Add method to merge dict objects to yaml files
PROD-36050
Change-Id: I7e3cfb005a575bc5ffa078746f6623870307d005
diff --git a/reclass_tools/walk_models.py b/reclass_tools/walk_models.py
index 533a120..86cc2ef 100644
--- a/reclass_tools/walk_models.py
+++ b/reclass_tools/walk_models.py
@@ -245,3 +245,32 @@
)
)
# return found_keys
+
+
+def merge_dict_to_reclass(paths, dict_obj,
+ verbose=False):
+ """
+ Add bunch of values to the specific reclass models
+ :param paths: list, paths to reclass files to edit
+ :param dict: obj be added to the reclass model
+ :return: None
+ """
+ for path in paths:
+ for fyml in walkfiles(path, verbose=verbose):
+ if not fyml.fname.endswith('.yml'): continue
+ try:
+ model = helpers.yaml_read(fyml.fname)
+ except yaml.scanner.ScannerError as e:
+ print(e, file=sys.stderr)
+ continue
+ if model is None: continue
+ # ----------------------------
+ merged_model = helpers.merge_nested_objects(model, dict_obj)
+ # ----------------------------
+ with open(fyml.fname, 'w') as f:
+ f.write(
+ yaml.dump(
+ merged_model, default_flow_style=False,
+ width=255
+ )
+ )
\ No newline at end of file