try/catch importing modules for help

This commit is contained in:
əlemi 2022-04-23 22:06:09 +02:00
parent 086e59a0ce
commit 261d18f854
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -25,11 +25,14 @@ def main():
for path in sorted(addon_path.rglob('*.py')): for path in sorted(addon_path.rglob('*.py')):
py_path = str(path).replace('/', '.').replace('.py', '') py_path = str(path).replace('/', '.').replace('.py', '')
m = import_module(py_path) try:
for obj_name in vars(m).keys(): m = import_module(py_path)
obj = getattr(m, obj_name) for obj_name in vars(m).keys():
if obj != Addon and inspect.isclass(obj) and issubclass(obj, Addon): obj = getattr(m, obj_name)
addons.add(obj) if obj != Addon and inspect.isclass(obj) and issubclass(obj, Addon):
addons.add(obj)
except Exception as e:
logging.debug("Error importing module %s : %s", py_path, str(e))
help_text = '\n\naddons (enabled via config file):' help_text = '\n\naddons (enabled via config file):'
@ -49,7 +52,7 @@ def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='python -m treepuncher', prog='python -m treepuncher',
description='Treepuncher | Block Game automation framework', description='Treepuncher | Block Game automation framework',
epilog=help_text, epilog=help_text, # TODO maybe build this afterwards?
formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawDescriptionHelpFormatter,
) )
@ -59,6 +62,8 @@ def main():
parser.add_argument('--debug', dest='_debug', action='store_const', const=True, default=False, help="enable debug logs") parser.add_argument('--debug', dest='_debug', action='store_const', const=True, default=False, help="enable debug logs")
parser.add_argument('--no-packet-filter', dest='use_packet_whitelist', action='store_const', const=False, default=True, help="disable packet whitelist, will decrease performance") parser.add_argument('--no-packet-filter', dest='use_packet_whitelist', action='store_const', const=False, default=True, help="disable packet whitelist, will decrease performance")
parser.add_argument('--offline', dest='offline', action='store_const', const=True, default=False, help="run client in offline mode")
parser.add_argument('--code', dest='code', default='', help='login code for oauth2 flow') parser.add_argument('--code', dest='code', default='', help='login code for oauth2 flow')
parser.add_argument('--mojang', dest='mojang', action='store_const', const=True, default=False, help="use legacy Mojang authenticator") parser.add_argument('--mojang', dest='mojang', action='store_const', const=True, default=False, help="use legacy Mojang authenticator")
@ -81,6 +86,7 @@ def main():
client = Treepuncher( client = Treepuncher(
args.name, args.name,
args.server, args.server,
online_mode=not args.offline,
legacy=args.mojang, legacy=args.mojang,
use_packet_whitelist=args.use_packet_whitelist, use_packet_whitelist=args.use_packet_whitelist,
) )