|
@@ -3,28 +3,82 @@
|
|
|
|
|
|
from svgpathtools import svg2paths, wsvg
|
|
|
import sys
|
|
|
+import logging
|
|
|
+import argparse
|
|
|
|
|
|
+##
|
|
|
+# Setup logging
|
|
|
+##
|
|
|
+FILE_MIN_LEVEL = logging.INFO
|
|
|
+STDOUT_MIN_LEVEL = logging.ERROR
|
|
|
+
|
|
|
+logging.addLevelName(logging.NOTSET, '?')
|
|
|
+logging.addLevelName(logging.DEBUG, 'D')
|
|
|
+logging.addLevelName(logging.INFO, 'I')
|
|
|
+logging.addLevelName(logging.WARNING, 'W')
|
|
|
+logging.addLevelName(logging.ERROR, 'E')
|
|
|
+logging.addLevelName(logging.CRITICAL, 'C')
|
|
|
+
|
|
|
+log = logging.getLogger('connectsvg')
|
|
|
+log.setLevel(min(FILE_MIN_LEVEL, STDOUT_MIN_LEVEL))
|
|
|
+
|
|
|
+fh = logging.FileHandler('connectSVG.log')
|
|
|
+fh.setLevel(FILE_MIN_LEVEL)
|
|
|
+log.addHandler(fh)
|
|
|
+
|
|
|
+fhFormat = logging.Formatter('%(levelname)s/%(asctime)s (%(module)s) : %(message)s', '%Y-%m-%d %H:%M:%S,%03d')
|
|
|
+fh.setFormatter(fhFormat)
|
|
|
+
|
|
|
+sh = logging.StreamHandler(sys.stdout)
|
|
|
+sh.setLevel(STDOUT_MIN_LEVEL)
|
|
|
+log.addHandler(sh)
|
|
|
+
|
|
|
+shFormat = logging.Formatter('%(levelname)s - %(message)s')
|
|
|
+sh.setFormatter(shFormat)
|
|
|
+
|
|
|
+
|
|
|
+##
|
|
|
+# Import program parts
|
|
|
+##
|
|
|
from Exceptions import *
|
|
|
from breakUncontinuous import breakUncontinuous
|
|
|
from connectPaths import connectPaths
|
|
|
from orderPaths import orderPaths
|
|
|
|
|
|
+##
|
|
|
+# Program
|
|
|
+##
|
|
|
+
|
|
|
+log.info("Starting connectSVG")
|
|
|
+
|
|
|
try :
|
|
|
+ log.info("Reading arguments")
|
|
|
if len(sys.argv) not in (2,3) :
|
|
|
raise InvalidArgumentException()
|
|
|
|
|
|
file = sys.argv[1]
|
|
|
oFile = sys.argv[2] if len(sys.argv) == 3 else sys.argv[1]
|
|
|
|
|
|
+ log.info("Reading svg")
|
|
|
paths, attributes = svg2paths(file)
|
|
|
|
|
|
+ log.info("Breaking uncontinuous paths")
|
|
|
paths, attributes = breakUncontinuous(paths, attributes)
|
|
|
+ log.info("Connecting paths")
|
|
|
paths, attributes = connectPaths(paths, attributes)
|
|
|
+ log.info("Ordering paths")
|
|
|
paths, attributes = orderPaths(paths, attributes)
|
|
|
|
|
|
- wsvg(paths, attributes=attributes, filename=oFile)
|
|
|
+ outfile = args.outfile if args.outfile else args.infile
|
|
|
+ log.info("Writing in %s", outfile)
|
|
|
+ wsvg(paths, attributes=attributes, filename=outfile)
|
|
|
|
|
|
except InvalidArgumentException :
|
|
|
- print('The command accepts exactly one argument with the file to read.')
|
|
|
+ log.critical("The command accepts one argument with the file to read and one optional with the file to write")
|
|
|
except FileNotFoundError :
|
|
|
- print('The given file is not found.')
|
|
|
+ log.critical('The given file to read is not found')
|
|
|
+except Exception as e :
|
|
|
+ log.critical("Un uncaught error has occured:", exc_info=e)
|
|
|
+ log.info("Terminating connectSVG without writing")
|
|
|
+else :
|
|
|
+ log.info("connectSVG has finished")
|