Skip to content

Commit 19562ff

Browse files
author
Artturi Ramanen
committed
Selectively append changes to exported config files
In case of a non-overwriting change to an exported config file the previous logic appended a new block of text to the previous file every time the to-be-written block of text was not exactly matched. This parses the old config file and the to-be-written changes into sets, which can then be compared. If all of the incoming lines are found in the old config file set, no changes are made. If some incoming lines are not found in the old config file, only these are appended.
1 parent cde7d0b commit 19562ff

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tools/export/exporters.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,17 @@ def gen_file(self, template_file, data, target_file, **kwargs):
206206
self.generated_files += [target_path]
207207

208208
def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
209-
"""Generates a project file from a template using jinja"""
209+
"""Generates or selectively appends a project file from a template"""
210210
target_text = self._gen_file_inner(template_file, data, target_file, **kwargs)
211211
target_path = self.gen_file_dest(target_file)
212212
if exists(target_path):
213213
with open(target_path) as fdin:
214-
old_text = fdin.read()
215-
if target_text not in old_text:
214+
old_lines_set = set(fdin.read().splitlines())
215+
target_set = set(target_text.splitlines())
216+
to_append = target_set - old_lines_set
217+
if len(to_append) > 0:
216218
with open(target_path, "a") as fdout:
217-
fdout.write(target_text)
219+
fdout.write("\n".join(to_append))
218220
else:
219221
logging.debug("Generating: %s", target_path)
220222
open(target_path, "w").write(target_text)

0 commit comments

Comments
 (0)