mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 20:32:25 +00:00
fix ifcpatch recipe import path (#1296)
This commit is contained in:
+24
-45
@@ -5,61 +5,40 @@ import ifcopenshell
|
|||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
def execute(args, is_library=None):
|
def execute(args, is_library=None):
|
||||||
logging.basicConfig(filename=args['log'], filemode='a', level=logging.DEBUG)
|
logging.basicConfig(filename=args["log"], filemode="a", level=logging.DEBUG)
|
||||||
logger = logging.getLogger('IFCPatch')
|
logger = logging.getLogger("IFCPatch")
|
||||||
print('# Loading IFC file ...')
|
print("# Loading IFC file ...")
|
||||||
ifc_file = ifcopenshell.open(args['input'])
|
ifc_file = ifcopenshell.open(args["input"])
|
||||||
print('# Loading patch recipe ...')
|
print("# Loading patch recipe ...")
|
||||||
patcher = getattr(__import__('recipes.{}'.format(args['recipe'])), args['recipe']).Patcher(
|
recipes = getattr(__import__("ifcpatch.recipes.{}".format(args["recipe"])), "recipes")
|
||||||
args['input'], ifc_file, logger, args['arguments'])
|
recipe = getattr(recipes, args["recipe"])
|
||||||
print('# Patching ...')
|
patcher = recipe.Patcher(args["input"], ifc_file, logger, args["arguments"])
|
||||||
|
print("# Patching ...")
|
||||||
patcher.patch()
|
patcher.patch()
|
||||||
ifc_file = patcher.file
|
ifc_file = patcher.file
|
||||||
if is_library is True:
|
if is_library is True:
|
||||||
return ifc_file
|
return ifc_file
|
||||||
print('# Writing patched file ...')
|
print("# Writing patched file ...")
|
||||||
if not args['output']:
|
if not args["output"]:
|
||||||
args['output'] = args['input']
|
args["output"] = args["input"]
|
||||||
if isinstance(ifc_file, str):
|
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)
|
text_file.write(ifc_file)
|
||||||
else:
|
else:
|
||||||
ifc_file.write(args['output'])
|
ifc_file.write(args["output"])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = argparse.ArgumentParser(
|
if __name__ == "__main__":
|
||||||
description='Patches IFC files to fix badly formatted data')
|
parser = argparse.ArgumentParser(description="Patches IFC files to fix badly formatted data")
|
||||||
parser.add_argument(
|
parser.add_argument("-i", "--input", type=str, required=True, help="The IFC file to patch")
|
||||||
'-i',
|
parser.add_argument("-o", "--output", type=str, help="The output file to save the patched IFC")
|
||||||
'--input',
|
parser.add_argument("-r", "--recipe", type=str, required=True, help="Name of the recipe to use when patching")
|
||||||
type=str,
|
parser.add_argument("-l", "--log", type=str, help="Specify a log file", default="ifcpatch.log")
|
||||||
required=True,
|
parser.add_argument("-a", "--arguments", nargs="+", help="Specify custom arguments to the patch recipe")
|
||||||
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())
|
args = vars(parser.parse_args())
|
||||||
|
|
||||||
execute(args)
|
execute(args)
|
||||||
|
|
||||||
print('# All tasks are complete :-)')
|
print("# All tasks are complete :-)")
|
||||||
|
|||||||
Reference in New Issue
Block a user