From 01b1f4642f711b0d4dec9b835c1c4bd1c63bef79 Mon Sep 17 00:00:00 2001 From: Long <931924+htlcnn@users.noreply.github.com> Date: Fri, 5 Feb 2021 14:19:10 +0700 Subject: [PATCH] fix ifcpatch recipe import path (#1296) --- src/ifcpatch/__init__.py | 69 ++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/src/ifcpatch/__init__.py b/src/ifcpatch/__init__.py index 00b88b97af..a3a74249aa 100644 --- a/src/ifcpatch/__init__.py +++ b/src/ifcpatch/__init__.py @@ -5,61 +5,40 @@ import ifcopenshell import logging import argparse + def execute(args, is_library=None): - logging.basicConfig(filename=args['log'], filemode='a', level=logging.DEBUG) - logger = logging.getLogger('IFCPatch') - print('# Loading IFC file ...') - ifc_file = ifcopenshell.open(args['input']) - print('# Loading patch recipe ...') - patcher = getattr(__import__('recipes.{}'.format(args['recipe'])), args['recipe']).Patcher( - args['input'], ifc_file, logger, args['arguments']) - print('# Patching ...') + logging.basicConfig(filename=args["log"], filemode="a", level=logging.DEBUG) + logger = logging.getLogger("IFCPatch") + print("# Loading IFC file ...") + ifc_file = ifcopenshell.open(args["input"]) + print("# Loading patch recipe ...") + recipes = getattr(__import__("ifcpatch.recipes.{}".format(args["recipe"])), "recipes") + recipe = getattr(recipes, args["recipe"]) + patcher = recipe.Patcher(args["input"], ifc_file, logger, args["arguments"]) + print("# Patching ...") patcher.patch() ifc_file = patcher.file if is_library is True: return ifc_file - print('# Writing patched file ...') - if not args['output']: - args['output'] = args['input'] + print("# Writing patched file ...") + if not args["output"]: + args["output"] = args["input"] if isinstance(ifc_file, str): - with open(args['output'], 'w') as text_file: + with open(args["output"], "w") as text_file: text_file.write(ifc_file) else: - ifc_file.write(args['output']) + ifc_file.write(args["output"]) -if __name__ == '__main__': - parser = argparse.ArgumentParser( - description='Patches IFC files to fix badly formatted data') - parser.add_argument( - '-i', - '--input', - type=str, - required=True, - help='The IFC file to patch') - parser.add_argument( - '-o', - '--output', - type=str, - help='The output file to save the patched IFC') - parser.add_argument( - '-r', - '--recipe', - type=str, - required=True, - help='Name of the recipe to use when patching') - parser.add_argument( - '-l', - '--log', - type=str, - help='Specify a log file', - default='ifcpatch.log') - parser.add_argument( - '-a', - '--arguments', - nargs='+', - help='Specify custom arguments to the patch recipe') + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Patches IFC files to fix badly formatted data") + parser.add_argument("-i", "--input", type=str, required=True, help="The IFC file to patch") + parser.add_argument("-o", "--output", type=str, help="The output file to save the patched IFC") + parser.add_argument("-r", "--recipe", type=str, required=True, help="Name of the recipe to use when patching") + parser.add_argument("-l", "--log", type=str, help="Specify a log file", default="ifcpatch.log") + parser.add_argument("-a", "--arguments", nargs="+", help="Specify custom arguments to the patch recipe") args = vars(parser.parse_args()) execute(args) - print('# All tasks are complete :-)') + print("# All tasks are complete :-)")