-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(merge attributes): update replace_uri_in_template_string util func
Signed-off-by: David Wallace <[email protected]>
- Loading branch information
Showing
2 changed files
with
7 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
from rdmo.domain.models import Attribute | ||
|
||
def replace_uri_in_template_string(template: str, source_uri: str, target_uri: str) -> str: | ||
patterns = [f"'{source_uri}'", f'"{source_uri}"'] | ||
replacements = [f"'{target_uri}'", f'"{target_uri}"'] | ||
|
||
def replace_uri_in_template_string(template: str, source: Attribute, target: Attribute) -> str: | ||
new_lines = [] | ||
path_changed = source.path != target.path | ||
for line in template.splitlines(): | ||
new_line = line | ||
if source.uri in line: | ||
new_line = new_line.replace(source.uri, target.uri) | ||
if path_changed: | ||
if source.path in new_line: | ||
new_line = new_line.replace(source.path, target.path) | ||
new_lines.append(new_line) | ||
new_template = "\n".join(new_lines) | ||
new_template = template | ||
for pattern, replacement in zip(patterns, replacements): | ||
new_template = new_template.replace(pattern, replacement) | ||
return new_template |