mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +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 logging
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def execute(args):
|
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__(f'recipes.{args.recipe}'), args.recipe).Patcher(
|
patcher = getattr(__import__('recipes.{}'.format(args['recipe'])), args['recipe']).Patcher(
|
||||||
args.input, ifc_file, logger, args.arguments)
|
args['input'], ifc_file, logger, args['arguments'])
|
||||||
print('# Patching ...')
|
print('# Patching ...')
|
||||||
patcher.patch()
|
patcher.patch()
|
||||||
|
if is_library is not None:
|
||||||
|
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']
|
||||||
ifc_file.write(args.output)
|
ifc_file.write(args.output)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
if __name__ == '__main__':
|
||||||
description='Patches IFC files to fix badly formatted data')
|
parser = argparse.ArgumentParser(
|
||||||
parser.add_argument(
|
description='Patches IFC files to fix badly formatted data')
|
||||||
'-i',
|
parser.add_argument(
|
||||||
'--input',
|
'-i',
|
||||||
type=str,
|
'--input',
|
||||||
required=True,
|
type=str,
|
||||||
help='The IFC file to patch')
|
required=True,
|
||||||
parser.add_argument(
|
help='The IFC file to patch')
|
||||||
'-o',
|
parser.add_argument(
|
||||||
'--output',
|
'-o',
|
||||||
type=str,
|
'--output',
|
||||||
help='The output file to save the patched IFC')
|
type=str,
|
||||||
parser.add_argument(
|
help='The output file to save the patched IFC')
|
||||||
'-r',
|
parser.add_argument(
|
||||||
'--recipe',
|
'-r',
|
||||||
type=str,
|
'--recipe',
|
||||||
required=True,
|
type=str,
|
||||||
help='Name of the recipe to use when patching')
|
required=True,
|
||||||
parser.add_argument(
|
help='Name of the recipe to use when patching')
|
||||||
'-l',
|
parser.add_argument(
|
||||||
'--log',
|
'-l',
|
||||||
type=str,
|
'--log',
|
||||||
help='Specify a log file',
|
type=str,
|
||||||
default='ifcpatch.log')
|
help='Specify a log file',
|
||||||
parser.add_argument(
|
default='ifcpatch.log')
|
||||||
'-a',
|
parser.add_argument(
|
||||||
'--arguments',
|
'-a',
|
||||||
nargs='+',
|
'--arguments',
|
||||||
help='Specify custom arguments to the patch recipe')
|
nargs='+',
|
||||||
args = parser.parse_args()
|
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