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: