2018-04-29 01:26:53 +00:00
|
|
|
import sys
|
|
|
|
import traceback
|
|
|
|
from argparse import ArgumentParser
|
2018-05-02 00:37:51 +00:00
|
|
|
from lib.utils import save_stderr, restore_stderr
|
|
|
|
from lib import extensions
|
2018-04-29 01:26:53 +00:00
|
|
|
|
|
|
|
|
2018-04-29 02:14:23 +00:00
|
|
|
parser = ArgumentParser()
|
|
|
|
parser.add_argument("--extension")
|
|
|
|
my_args, remaining_args = parser.parse_known_args()
|
2018-04-29 01:26:53 +00:00
|
|
|
|
2018-04-29 02:14:23 +00:00
|
|
|
extension_name = my_args.extension
|
2018-07-29 00:40:14 +00:00
|
|
|
|
|
|
|
# example: foo_bar_baz -> FooBarBaz
|
|
|
|
extension_class_name = extension_name.title().replace("_", "")
|
|
|
|
|
|
|
|
extension_class = getattr(extensions, extension_class_name)
|
2018-04-29 01:26:53 +00:00
|
|
|
extension = extension_class()
|
|
|
|
|
|
|
|
exception = None
|
|
|
|
|
|
|
|
save_stderr()
|
|
|
|
try:
|
2018-04-29 02:14:23 +00:00
|
|
|
extension.affect(args=remaining_args)
|
2018-04-29 01:26:53 +00:00
|
|
|
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)
|