diff options
Diffstat (limited to 'inkstitch.py')
| -rw-r--r-- | inkstitch.py | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/inkstitch.py b/inkstitch.py index b466a508..1a7b1468 100644 --- a/inkstitch.py +++ b/inkstitch.py @@ -1,12 +1,24 @@ import os import sys +import logging import traceback +from cStringIO import StringIO from argparse import ArgumentParser from lib import extensions from lib.utils import save_stderr, restore_stderr +logger = logging.getLogger('shapely.geos') +logger.setLevel(logging.DEBUG) +shapely_errors = StringIO() +ch = logging.StreamHandler(shapely_errors) +ch.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s') +ch.setFormatter(formatter) +logger.addHandler(ch) + + parser = ArgumentParser() parser.add_argument("--extension") my_args, remaining_args = parser.parse_known_args() @@ -31,20 +43,25 @@ extension_class_name = extension_name.title().replace("_", "") extension_class = getattr(extensions, extension_class_name) extension = extension_class() -exception = None - -save_stderr() -try: +if hasattr(sys, 'gettrace') and sys.gettrace(): extension.affect(args=remaining_args) -except (SystemExit, KeyboardInterrupt): - raise -except Exception: - exception = traceback.format_exc() -finally: - restore_stderr() - -if exception: - print >> sys.stderr, exception - sys.exit(1) else: - sys.exit(0) + save_stderr() + exception = None + try: + extension.affect(args=remaining_args) + except (SystemExit, KeyboardInterrupt): + raise + except Exception: + exception = traceback.format_exc() + finally: + restore_stderr() + + if shapely_errors.tell(): + print >> sys.stderr, shapely_errors.getvalue() + + if exception: + print >> sys.stderr, exception + sys.exit(1) + else: + sys.exit(0) |
