MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / execute

Function execute

src/ifcpatch/ifcpatch/__init__.py:68–127  ·  view source on GitHub ↗

Execute a patch recipe The details of how the patch recipe is executed depends on the definition of the recipe, as well as the arguments passed to the recipe. See the documentation for each patch recipe separately to understand more. :param args: A dictionary of arguments, correspo

(args: ArgumentsDict)

Source from the content-addressed store, hash-verified

66
67
68def execute(args: ArgumentsDict) -> Union[ifcopenshell.file, str, None]:
69 """Execute a patch recipe
70
71 The details of how the patch recipe is executed depends on the definition of
72 the recipe, as well as the arguments passed to the recipe. See the
73 documentation for each patch recipe separately to understand more.
74
75 :param args: A dictionary of arguments, corresponding to the parameters
76 listed subsequent to this in this docstring.
77 :type args: ArgumentsDict
78 :param file: An IFC model to apply the patch recipe to.
79 Required for most recipes except the ones that require `input`.
80 :type file: ifcopenshell.file, optional
81 :param input: A filepath to the incoming IFC file.
82 Required/supported only for some recipes, see specific recipes descriptions,
83 in other cases will be ignored.
84 :type input: str, optional
85 :param recipe: The name of the recipe. This is the same as the filename of
86 the recipe. E.g. "ExtractElements".
87 :type recipe: str
88 :param log: A filepath to a logfile.
89 :type log: str,optional
90 :param arguments: A list of zero or more positional arguments, depending on
91 the patch recipe. Some patch recipes will require you to specify
92 arguments, some won't.
93 :type arguments: list
94 :return: The result of the patch. This is typically a patched model, either
95 as an object or as a string.
96
97 Example:
98
99 .. code:: python
100
101 output = ifcpatch.execute({
102 "input": "input.ifc",
103 "file": ifcopenshell.open("input.ifc"),
104 "recipe": "ExtractElements",
105 "arguments": [".IfcWall"],
106 })
107 ifcpatch.write(output, "output.ifc")
108 """
109 if "log" in args:
110 logging.basicConfig(filename=args["log"], filemode="a", level=logging.DEBUG)
111 logger = ensure_logger()
112 if recipe_dir := os.environ.get("IFCPATCH_RECIPE_DIR"):
113 spec = importlib.util.spec_from_file_location(args["recipe"], os.path.join(recipe_dir, args["recipe"] + ".py"))
114 recipe = importlib.util.module_from_spec(spec)
115 sys.modules[args["recipe"]] = recipe
116 spec.loader.exec_module(recipe)
117 else:
118 recipe = importlib.import_module(f"ifcpatch.recipes.{args['recipe']}")
119
120 arguments = args.get("arguments", None) or []
121 if recipe.Patcher.__init__.__doc__ is not None:
122 patcher = recipe.Patcher(args.get("file"), logger, *arguments)
123 else:
124 patcher = recipe.Patcher(args.get("file"), logger, arguments)
125 patcher.patch()

Callers

nothing calls this directly

Calls 5

patchMethod · 0.95
ensure_loggerFunction · 0.85
getMethod · 0.45
joinMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected