mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
IFCPatch can now be used as a library or as a CLI
This commit is contained in:
+43
-40
@@ -5,53 +5,56 @@ import ifcopenshell
|
||||
import logging
|
||||
import argparse
|
||||
|
||||
def execute(args):
|
||||
logging.basicConfig(filename=args.log, filemode='a', level=logging.DEBUG)
|
||||
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)
|
||||
ifc_file = ifcopenshell.open(args['input'])
|
||||
print('# Loading patch recipe ...')
|
||||
patcher = getattr(__import__(f'recipes.{args.recipe}'), args.recipe).Patcher(
|
||||
args.input, ifc_file, logger, args.arguments)
|
||||
patcher = getattr(__import__('recipes.{}'.format(args['recipe'])), args['recipe']).Patcher(
|
||||
args['input'], ifc_file, logger, args['arguments'])
|
||||
print('# Patching ...')
|
||||
patcher.patch()
|
||||
if is_library is not None:
|
||||
return ifc_file
|
||||
print('# Writing patched file ...')
|
||||
if not args.output:
|
||||
args.output = args.input
|
||||
if not args['output']:
|
||||
args['output'] = args['input']
|
||||
ifc_file.write(args.output)
|
||||
|
||||
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 = parser.parse_args()
|
||||
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)
|
||||
execute(args)
|
||||
|
||||
print('# All tasks are complete :-)')
|
||||
print('# All tasks are complete :-)')
|
||||
|
||||
Reference in New Issue
Block a user