Beispiel #1
0
def main(argv=list(sys.argv)):
    logging_config = deepcopy(DEFAULT_LOGGING_CONFIG)
    try:
        if "--test" in argv or "--pdb" in argv:
            logging_config['handlers']['console']['level'] = 'DEBUG'

        use_pdb = "--pdb" in argv
        if use_pdb:
            argv.remove("--pdb")

        platform_ = "test" if "--test" in argv else "mac"
        platform.init(platform_, use_pdb)

        if "--test" in argv:
            from editxt.test.runner import TestApplication
            app = TestApplication(argv)
        else:
            logging.config.dictConfig(logging_config)
            from editxt.application import Application
            argv = [a for a in argv if not a.startswith("-psn")] # OS X < 10.9 hack
            argv = argv[1:] # drop program name
            doc = __doc__.replace('Profile directory.',
                'Profile directory [default: {}].'
                .format(Application.default_profile()))
            opts = docopt.docopt(doc, argv, version=editxt.__version__)
            app = Application(opts.get('--profile'))

        with app.logger() as errlog:
            from editxt.platform.main import run
            run(app, argv, errlog.unexpected_error, use_pdb)
    except Exception as err:
        exc_info = sys.exc_info()
        if not logging.root.handlers:
            logging.config.dictConfig(logging_config)
        log.error('unhandled error', exc_info=exc_info)
        sys.exit(1)
Beispiel #2
0
from collections import defaultdict, OrderedDict
from contextlib import contextmanager
from itertools import chain, count
from os.path import abspath, basename, dirname, exists, isdir, isfile, join, splitext
from subprocess import check_output, CalledProcessError

import docopt

THIS_PATH = abspath(dirname(__file__))
HLJS2JSON = join(THIS_PATH, "../resources/hljs2json/hljs2json.js")
AUTO_COMMENT = "# Syntax definition automatically generated by hljs2xt.py\n"
IGNORE_ITEM_KEYS = {"begin", "relevance"}

sys.path.append(join(dirname(THIS_PATH)))
import editxt.platform as platform
platform.init("test", False)
from editxt.command.wraplines import wraplines


def main(args=None):
    opts = docopt.docopt(__doc__, args)
    hljs_file = opts["<hljs-file>"]
    xt_file = opts["<editxt-file>"]
    overwrite = opts["--overwrite"]
    ignore = {i for i in (opts["--ignore"] or "").split(",") if i}
    verbose = opts["--verbose"]
    if isdir(hljs_file):
        for name in os.listdir(hljs_file):
            if name.endswith(".js"):
                hljs_path = join(hljs_file, name)
                if name in ignore: