'''
plantuml files are generated through a logger
'''
import logging
import logging.handlers
import atexit
import __main__ as main
try:
MAIN_FILE_NAME = main.__file__
if MAIN_FILE_NAME.endswith('.py'):
MAIN_FILE_NAME = MAIN_FILE_NAME[:-3] + '.autouml'
except:
MAIN_FILE_NAME = 'autouml'
LOGGER = logging.getLogger('autouml')
HANDLER1 = logging.handlers.RotatingFileHandler(
'%s.log' % MAIN_FILE_NAME,
backupCount=1
)
HANDLER2 = logging.FileHandler('%s.log' % MAIN_FILE_NAME)
LOG_FORMAT = UMLFormatter('%(message)s')
HANDLER1.setFormatter(LOG_FORMAT)
HANDLER2.setFormatter(LOG_FORMAT)
HANDLER1.doRollover()
LOGGER.addHandler(HANDLER1)
# LOGGER.addHandler(HANDLER2)
LOGGER.setLevel(logging.INFO)
[docs]def startuml(theme=''):
LOGGER.debug("Log generated by autouml")
LOGGER.info('''@startuml
%s''' % theme)
[docs]def closeuml():
'''
Closes plantuml diagram syntax and tries to generate the image.
Intended to be called on program exit
'''
LOGGER.info("@enduml")
try:
import plantuml
LOGGER.debug("Generating image at %s.png" % MAIN_FILE_NAME)
plantuml.PlantUML().processes_file(
'%s.log' % MAIN_FILE_NAME,
outfile='%s.png' % MAIN_FILE_NAME
)
except Exception, captured_except:
LOGGER.debug('Unable to generate image file')
LOGGER.debug(captured_except)
atexit.register(closeuml)