From 96c62f556bf9b207d4c5fbf9a3fbaf76dec9436a Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sat, 17 Jun 2023 12:45:00 +0100 Subject: [PATCH] langmover: rewrite whole directory when using --extract --extract now takes a path argument, a new copy of the source folder is made there. Rebuilding the whole folder gets rid of annoying things like mis-capitalized files. --- scripts/langmover/langmover.py | 25 ++++++++++++++++++------- scripts/langmover/login.json | 4 +++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/langmover/langmover.py b/scripts/langmover/langmover.py index b0fa92d..6ef5867 100644 --- a/scripts/langmover/langmover.py +++ b/scripts/langmover/langmover.py @@ -74,7 +74,7 @@ def parseKey(langTree, currentSection: str, fieldName: str, key: str, extract=Fa return (langTree, folder, value) -def generate(templ: Path, source: Path, output: Path, extract: bool, tree): +def generate(templ: Path, source: Path, output: Path, extract: str, tree): with open(templ, "r") as f: template = json.load(f) @@ -92,21 +92,32 @@ def generate(templ: Path, source: Path, output: Path, extract: bool, tree): continue - modifiedTree = {} folder = "" out[section] = {} for key in template[section]: - (modifiedTree, folder, val) = parseKey(tree[lang], section, key, template[section][key], extract) + (tree[lang], folder, val) = parseKey(tree[lang], section, key, template[section][key], extract) if val != "": out[section][key] = val - if extract and val != "": - with open(source / folder / lang, "w") as f: - json.dump(modifiedTree[folder], f, indent=4, ensure_ascii=False) + # if extract and val != "": + # with open(source / folder / lang, "w") as f: + # json.dump(modifiedTree[folder], f, indent=4, ensure_ascii=False) with open(output / Path(lang), "w") as f: json.dump(out, f, indent=4, ensure_ascii=False) + if extract and extract != "": + ex = Path(extract) + if not ex.exists(): + ex.mkdir() + + for lang in tree: + for folder in tree[lang]: + if not (ex / folder).exists(): + (ex / folder).mkdir() + with open(ex / folder / lang, "w") as f: + json.dump(tree[lang][folder], f, indent=4, ensure_ascii=False) + parser = argparse.ArgumentParser() @@ -114,7 +125,7 @@ parser = argparse.ArgumentParser() parser.add_argument("--source", help="source \"lang/\" folder.") parser.add_argument("--template", help="template file. see template.json for an example of how it works.") parser.add_argument("--output", help="output directory for new files.") -parser.add_argument("--extract", help="remove strings from original file as they are copied.", action="store_true") +parser.add_argument("--extract", help="put copies of original files with strings removed in this directory") args = parser.parse_args() diff --git a/scripts/langmover/login.json b/scripts/langmover/login.json index 568e8a9..433fbf8 100644 --- a/scripts/langmover/login.json +++ b/scripts/langmover/login.json @@ -22,7 +22,9 @@ "contactDiscord": "common", "theme": "common", "refresh": "common", - "required": "common" + "required": "common", + "login": "admin", + "logout": "admin" }, "notifications": { "errorLoginBlank": "admin",