Skip to content

Commit 47cc315

Browse files
committed
IfcPatch can now support patches that write to arbitrary files or have no output.
1 parent bac683e commit 47cc315

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/ifcpatch/ifcpatch/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
# You should have received a copy of the GNU Lesser General Public License
1919
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
2020

21+
import os
2122
import ifcopenshell
2223
import logging
23-
import os
2424
import typing
2525
import inspect
2626
import collections
@@ -95,9 +95,14 @@ def write(output, filepath):
9595
:return: None
9696
:rtype: None
9797
"""
98-
if isinstance(output, str):
99-
with open(filepath, "w") as text_file:
100-
text_file.write(output)
98+
if output is None:
99+
return
100+
elif isinstance(output, str):
101+
if os.path.exists(output):
102+
os.rename(output, filepath)
103+
else:
104+
with open(filepath, "w") as text_file:
105+
text_file.write(output)
101106
else:
102107
output.write(filepath)
103108

0 commit comments

Comments
 (0)