summaryrefslogtreecommitdiff
path: root/inkstitch.py
blob: b466a50892587dd7a3f5876ef4441fbd388822b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import sys
import traceback
from argparse import ArgumentParser

from lib import extensions
from lib.utils import save_stderr, restore_stderr


parser = ArgumentParser()
parser.add_argument("--extension")
my_args, remaining_args = parser.parse_known_args()

if os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "DEBUG")):
    # How to debug Ink/Stitch:
    #
    # 1. Install LiClipse (liclipse.com) -- no need to install Eclipse first
    # 2. Start debug server as described here: http://www.pydev.org/manual_adv_remote_debugger.html
    #    * follow the "Note:" to enable the debug server menu item
    # 3. Create a file named "DEBUG" next to inkstitch.py in your git clone.
    # 4. Run any extension and PyDev will start debugging.

    import pydevd
    pydevd.settrace()

extension_name = my_args.extension

# example: foo_bar_baz -> FooBarBaz
extension_class_name = extension_name.title().replace("_", "")

extension_class = getattr(extensions, extension_class_name)
extension = extension_class()

exception = None

save_stderr()
try:
    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)