Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: continuous integration #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
- `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.
Expand Down
56 changes: 52 additions & 4 deletions lib/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@
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('-'): # 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: <dir|profile> [flags]
flags:
-y: skip confirmation dialog
-x=<value>, -ext=<value>: file extension to filter for
-diff=<dir|url>: diff source to use""")
sys.exit()

__all__ = ["get_params"]
__root__ = os.path.dirname(os.path.dirname(__file__))


def try_user(config, profile):
Expand All @@ -24,23 +42,52 @@ 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"
if input(f"Use {q(profile)} profile? [Y/n]\t").lower() == "n":
is_path = False
if len(args) != 0:
is_path = os.path.isdir(args[0])

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)

config_user = raw_config[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 = {
"dir": config_user["ThemeDirectory"],
"ext": config_user["FileExtension"],
"uselocaldiff": config_user.getboolean("UseLocalDiff"),
"location": config_user["DiffLocation"],
}

if config["uselocaldiff"] and not os.path.exists(config["location"]):
raise FileNotFoundError("Diff file not found.")
return config


Expand All @@ -53,10 +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']}.")
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