From 47cc3158fdc358ded066a5f83d54eaeacdb09955 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 16 Jun 2023 13:22:33 +1000 Subject: [PATCH] IfcPatch can now support patches that write to arbitrary files or have no output. --- src/ifcpatch/ifcpatch/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ifcpatch/ifcpatch/__init__.py b/src/ifcpatch/ifcpatch/__init__.py index 3ad25ee8b3..549990e06a 100644 --- a/src/ifcpatch/ifcpatch/__init__.py +++ b/src/ifcpatch/ifcpatch/__init__.py @@ -18,9 +18,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcPatch. If not, see . +import os import ifcopenshell import logging -import os import typing import inspect import collections @@ -95,9 +95,14 @@ def write(output, filepath): :return: None :rtype: None """ - if isinstance(output, str): - with open(filepath, "w") as text_file: - text_file.write(output) + if output is None: + return + elif isinstance(output, str): + if os.path.exists(output): + os.rename(output, filepath) + else: + with open(filepath, "w") as text_file: + text_file.write(output) else: output.write(filepath)