#664 Metadata syncs

pull/707/head
meisnate12 3 years ago
parent 8fe3cd635f
commit 20719de518

@ -1 +1 @@
1.15.1-develop57 1.15.1-develop58

@ -179,7 +179,7 @@ class ConfigFile:
if "trakt" in new_config: new_config["trakt"] = new_config.pop("trakt") if "trakt" in new_config: new_config["trakt"] = new_config.pop("trakt")
if "mal" in new_config: new_config["mal"] = new_config.pop("mal") if "mal" in new_config: new_config["mal"] = new_config.pop("mal")
if not self.read_only: if not self.read_only:
yaml.round_trip_dump(new_config, open(self.config_path, "w", encoding="utf-8"), indent=None, block_seq_indent=2) yaml.round_trip_dump(new_config, open(self.config_path, "w", encoding="utf-8"), block_seq_indent=2)
self.data = new_config self.data = new_config
except yaml.scanner.ScannerError as e: except yaml.scanner.ScannerError as e:
raise Failed(f"YAML Error: {util.tab_new_lines(e)}") raise Failed(f"YAML Error: {util.tab_new_lines(e)}")
@ -207,7 +207,7 @@ class ConfigFile:
if parent not in loaded_config or not loaded_config[parent]: loaded_config[parent] = {attribute: default} if parent not in loaded_config or not loaded_config[parent]: loaded_config[parent] = {attribute: default}
elif attribute not in loaded_config[parent]: loaded_config[parent][attribute] = default elif attribute not in loaded_config[parent]: loaded_config[parent][attribute] = default
else: endline = "" else: endline = ""
yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), indent=None, block_seq_indent=2) yaml.round_trip_dump(loaded_config, open(self.config_path, "w"), block_seq_indent=2)
if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else [] if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else []
elif data[attribute] is None: elif data[attribute] is None:
if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else [] if default_is_none and var_type in ["list", "int_list", "comma_list"]: return default if default else []

@ -764,20 +764,36 @@ def library_operations(config, library):
logger.info("") logger.info("")
logger.info(f"Metadata Backup Path: {library.metadata_backup['path']}") logger.info(f"Metadata Backup Path: {library.metadata_backup['path']}")
logger.info("") logger.info("")
try:
meta, _, _ = yaml.util.load_yaml_guess_indent(open(library.metadata_backup["path"]))
except yaml.scanner.ScannerError as e:
meta = {} meta = {}
util.print_multiline(f"YAML Error: {util.tab_new_lines(e)}", error=True)
filename, file_extension = os.path.splitext(library.metadata_backup["path"])
i = 1
while os.path.exists(f"{filename}{i}{file_extension}"):
i += 1
os.rename(library.metadata_backup["path"], f"{filename}{i}{file_extension}")
logger.error(f"Backup failed to load saving copy to {filename}{i}{file_extension}")
if "metadata" not in meta:
meta["metadata"] = {}
items = library.get_all(load=True) items = library.get_all(load=True)
titles = [i.title for i in items] titles = [i.title for i in items]
for i, item in enumerate(items, 1): for i, item in enumerate(items, 1):
util.print_return(f"Processing: {i}/{len(items)} {item.title}") util.print_return(f"Processing: {i}/{len(items)} {item.title}")
map_key, attrs = library.get_locked_attributes(item, titles) map_key, attrs = library.get_locked_attributes(item, titles)
if attrs or library.metadata_backup["add_blank_entries"]: if attrs or library.metadata_backup["add_blank_entries"]:
meta[map_key] = attrs def run_dict(save_dict, the_dict):
for kk, vv in the_dict.items():
if isinstance(vv, dict):
run_dict(save_dict[kk], vv)
else:
save_dict[kk] = vv
run_dict(meta["metadata"][map_key], attrs)
util.print_end() util.print_end()
with open(library.metadata_backup["path"], "w"):
pass
try: try:
yaml.round_trip_dump({"metadata": meta}, open(library.metadata_backup["path"], "w", encoding="utf-8")) yaml.round_trip_dump(meta, open(library.metadata_backup["path"], "w", encoding="utf-8"), block_seq_indent=2)
logger.info(f"{len(meta)} {library.type.capitalize()}{'s' if len(meta) > 1 else ''} Backed Up") logger.info(f"{len(meta['metadata'])} {library.type.capitalize()}{'s' if len(meta['metadata']) > 1 else ''} Backed Up")
except yaml.scanner.ScannerError as e: except yaml.scanner.ScannerError as e:
util.print_multiline(f"YAML Error: {util.tab_new_lines(e)}", error=True) util.print_multiline(f"YAML Error: {util.tab_new_lines(e)}", error=True)

Loading…
Cancel
Save