Skip to content

Selectively append changes to exported config files #10118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions tools/export/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,17 @@ def gen_file(self, template_file, data, target_file, **kwargs):
self.generated_files += [target_path]

def gen_file_nonoverwrite(self, template_file, data, target_file, **kwargs):
"""Generates a project file from a template using jinja"""
"""Generates or selectively appends a project file from a template"""
target_text = self._gen_file_inner(template_file, data, target_file, **kwargs)
target_path = self.gen_file_dest(target_file)
if exists(target_path):
with open(target_path) as fdin:
old_text = fdin.read()
if target_text not in old_text:
old_lines_set = set(fdin.read().splitlines())
target_set = set(target_text.splitlines())
to_append = target_set - old_lines_set
if len(to_append) > 0:
with open(target_path, "a") as fdout:
fdout.write(target_text)
fdout.write("\n".join(to_append))
else:
logging.debug("Generating: %s", target_path)
open(target_path, "w").write(target_text)
Expand Down