From 45aab7d2d6aac975b39566a8a04d8ddc0c070191 Mon Sep 17 00:00:00 2001 From: Metro420yt <84623250+Metro420yt@users.noreply.github.com> Date: Fri, 23 Aug 2024 08:37:35 -0400 Subject: [PATCH 1/5] feat: continuous integration --- README.md | 2 +- lib/input.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f59a197..94cc494 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Updating only a single file? Use SyndiShanX's online tool instead: https://syndi - See section below for detailed info 3. Run the script - `cd ./ClassUpdate` - - `python ./replace.py` + - `python ./replace.py [config_profile] [-y]` ### Example Files marked with `↻` will be updated by the script if using the default config. diff --git a/lib/input.py b/lib/input.py index 2e64b94..19002f6 100644 --- a/lib/input.py +++ b/lib/input.py @@ -5,9 +5,17 @@ import configparser import glob import os.path +import sys from lib.format import ind, q +flags, args = [], [] +for s in sys.argv[1:]: + if s.startswith('-'): + flags.append(s) + else: + args.append(s) + __all__ = ["get_params"] @@ -29,11 +37,20 @@ def get_config(config_filename): raw_config.read(config_filename) profile = "DEFAULT" - if input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": + if (len(args) != 0): + profile = args[0] + + if "-y" not in flags and input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": profile = input("Config profile name:\t\t") profile = try_user(raw_config, profile) + config_user = raw_config[profile] + else: + try: + config_user = raw_config[profile] + except KeyError: + print(ValueError(f'unknown profile: "{profile}"')) + sys.exit() - config_user = raw_config[profile] config = { "dir": config_user["ThemeDirectory"], "ext": config_user["FileExtension"], @@ -57,6 +74,7 @@ def get_params(): ), recursive=True) print(f"\nFound {len(filenames)} {config['ext']} files in {config['dir']}.") - input("Press enter to continue or Ctrl+C to cancel.") + if '-y' not in flags: + input("Press enter to continue or Ctrl+C to cancel.") return config["uselocaldiff"], config['location'], filenames From 742cb52cf62ae893dcb5f3afc7252e45749e7b4d Mon Sep 17 00:00:00 2001 From: Metro420yt <84623250+Metro420yt@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:37:03 -0400 Subject: [PATCH 2/5] moved key check --- lib/input.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/input.py b/lib/input.py index 19002f6..7d034a3 100644 --- a/lib/input.py +++ b/lib/input.py @@ -43,14 +43,12 @@ def get_config(config_filename): if "-y" not in flags and input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": profile = input("Config profile name:\t\t") profile = try_user(raw_config, profile) - config_user = raw_config[profile] - else: - try: - config_user = raw_config[profile] - except KeyError: - print(ValueError(f'unknown profile: "{profile}"')) - sys.exit() + if profile not in raw_config: + print(ValueError(f'unknown profile: "{profile}"')) + sys.exit() + + config_user = raw_config[profile] config = { "dir": config_user["ThemeDirectory"], "ext": config_user["FileExtension"], From 4af36861562ffb5b8bea6b243446dd111cc6b791 Mon Sep 17 00:00:00 2001 From: Metro420yt <84623250+Metro420yt@users.noreply.github.com> Date: Mon, 28 Oct 2024 08:42:56 -0400 Subject: [PATCH 3/5] actually errors now --- lib/input.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/input.py b/lib/input.py index 7d034a3..9c0d651 100644 --- a/lib/input.py +++ b/lib/input.py @@ -37,7 +37,7 @@ def get_config(config_filename): raw_config.read(config_filename) profile = "DEFAULT" - if (len(args) != 0): + if len(args) != 0: profile = args[0] if "-y" not in flags and input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": @@ -45,8 +45,7 @@ def get_config(config_filename): profile = try_user(raw_config, profile) if profile not in raw_config: - print(ValueError(f'unknown profile: "{profile}"')) - sys.exit() + raise ValueError(f'unknown profile: "{profile}"') config_user = raw_config[profile] config = { From e5d31b0b77202e25a786cc757521dbb20d070eab Mon Sep 17 00:00:00 2001 From: Metro420yt <84623250+Metro420yt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:50:22 -0400 Subject: [PATCH 4/5] added CLI config overwrite arguments + added help flag + changed flags to be dict + error check for local diff + -y only skips continue prompt now --- lib/input.py | 53 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/input.py b/lib/input.py index 9c0d651..c3f3638 100644 --- a/lib/input.py +++ b/lib/input.py @@ -9,14 +9,24 @@ from lib.format import ind, q -flags, args = [], [] +flags, args = {}, [] for s in sys.argv[1:]: - if s.startswith('-'): - flags.append(s) + if s.startswith('-'): # format to {key:value} from -key=value + flag = s.split('=') + flags[flag[0][1:]] = flag[1] if len(flag) > 1 else None else: args.append(s) +if 'h' in flags or 'help' in flags: + print("""usage: [flags] +flags: + -y: skip confirmation dialog + -x=, -ext=: file extension to filter for + -diff=: diff source to use""") + sys.exit() + __all__ = ["get_params"] +__root__ = os.path.dirname(os.path.dirname(__file__)) def try_user(config, profile): @@ -32,22 +42,43 @@ def try_user(config, profile): def get_config(config_filename): """Get parameters from config file.""" raw_config = configparser.ConfigParser() + + config_filename = os.path.join(__root__, config_filename) if not os.path.exists(config_filename): raise FileNotFoundError("Config file not found.") raw_config.read(config_filename) profile = "DEFAULT" + is_path = False if len(args) != 0: - profile = args[0] + is_path = os.path.isdir(args[0]) - if "-y" not in flags and input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": + if not is_path: + profile = args[0] + elif input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n": profile = input("Config profile name:\t\t") profile = try_user(raw_config, profile) - if profile not in raw_config: - raise ValueError(f'unknown profile: "{profile}"') + if profile in raw_config: + config_user = raw_config[profile] + else: + raise ValueError(f'unknown profile/directory: "{profile}"') + + if is_path: + config_user["ThemeDirectory"] = os.path.abspath(args[0]) + else: + # backwards compat. + config_user["ThemeDirectory"] = os.path.abspath(__root__+'/../'+config_user["ThemeDirectory"]) + + if "ext" in flags: + config_user["FileExtension"] = flags["ext"] + elif "x" in flags: + config_user["FileExtension"] = flags["x"] + + if "diff" in flags: + config_user["DiffLocation"] = flags["diff"] + config_user["UseLocalDiff"] = "no" if flags["diff"].startswith("http") else "yes" - config_user = raw_config[profile] config = { "dir": config_user["ThemeDirectory"], "ext": config_user["FileExtension"], @@ -55,6 +86,8 @@ def get_config(config_filename): "location": config_user["DiffLocation"], } + if config["uselocaldiff"] and not os.path.exists(config["location"]): + raise FileNotFoundError("Diff file not found.") return config @@ -67,11 +100,11 @@ def get_params(): print(ind(f"Diff file location:\t{config['location']}")) filenames = glob.glob(os.path.join( - "..", config["dir"], "**", "*." + config["ext"] + config["dir"], "**", "*." + config["ext"] ), recursive=True) print(f"\nFound {len(filenames)} {config['ext']} files in {config['dir']}.") - if '-y' not in flags: + if 'y' not in flags: input("Press enter to continue or Ctrl+C to cancel.") return config["uselocaldiff"], config['location'], filenames From 4d21e388fac6f1c32c85caeefe1bad8cf1b742c4 Mon Sep 17 00:00:00 2001 From: Metro420yt <84623250+Metro420yt@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:58:24 -0400 Subject: [PATCH 5/5] usage update + msg for help menu --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94cc494..ca3a4ad 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ Updating only a single file? Use SyndiShanX's online tool instead: https://syndi - See section below for detailed info 3. Run the script - `cd ./ClassUpdate` - - `python ./replace.py [config_profile] [-y]` + - `python ./replace.py [config_profile|theme_dir]` +> use `-help` to see flags ### Example Files marked with `↻` will be updated by the script if using the default config.