From 40ba3fd9700f798f645f66ae798b7ee4bcec77f9 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:56:52 +0800 Subject: [PATCH] Update rules updater script --- scripts/rules_config.conf | 8 ++++---- scripts/update_rules.py | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/rules_config.conf b/scripts/rules_config.conf index 31b5fdda0..5efcdbe17 100644 --- a/scripts/rules_config.conf +++ b/scripts/rules_config.conf @@ -1,23 +1,23 @@ [ACL4SSR] name=ACL4SSR url=https://github.com/ACL4SSR/ACL4SSR -checkout=1dc5c92b0c8ceaaecbc66530c309961f53e52c8c +branch=master match=Clash/*.list|Clash/Ruleset/** [ACL4SSR_config] name=ACL4SSR url=https://github.com/ACL4SSR/ACL4SSR -checkout=1dc5c92b0c8ceaaecbc66530c309961f53e52c8c +branch=master match=Clash/config/** dest=base/config/ keep_tree=false [DivineEngine] url=https://github.com/DivineEngine/Profiles -checkout=f4d75f7d48a3f42129e030bef751d4d22bca02da +commit=f4d75f7d48a3f42129e030bef751d4d22bca02da match=Surge/Ruleset/** [NobyDa] url=https://github.com/NobyDa/Script -checkout=ae4c12f23de8078e02c373c9969b19af28257fcb +branch=master match=Surge/*.list diff --git a/scripts/update_rules.py b/scripts/update_rules.py index 7633c76ac..dbf27c26a 100644 --- a/scripts/update_rules.py +++ b/scripts/update_rules.py @@ -22,7 +22,7 @@ def open_repo(path: str): return None -def update_rules(repo_path, save_path, commit, matches, keep_tree): +def update_rules(repo_path: str, save_path: str, matches: list[str], keep_tree: bool): os.makedirs(save_path, exist_ok=True) for pattern in matches: files = glob.glob(os.path.join(repo_path, pattern), recursive=True) @@ -51,12 +51,13 @@ def main(): for section in config.sections(): repo = config.get(section, "name", fallback=section) url = config.get(section, "url") - commit = config.get(section, "checkout") + commit = config.get(section, "commit", fallback=None) + branch = config.get(section, "branch", fallback=None) matches = config.get(section, "match").split("|") save_path = config.get(section, "dest", fallback=f"base/rules/{repo}") keep_tree = config.getboolean(section, "keep_tree", fallback=True) - logging.info(f"reading files from url {url} with commit {commit} and matches {matches}, save to {save_path} keep_tree {keep_tree}") + logging.info(f"reading files from url {url}, matches {matches}, save to {save_path} keep_tree {keep_tree}") repo_path = os.path.join("./tmp/repo/", repo) @@ -67,8 +68,17 @@ def main(): else: logging.info(f"repo {repo_path} exists") - r.git.checkout(commit) - update_rules(repo_path, save_path, commit, matches, keep_tree) + if commit is not None: + logging.info(f"checking out to commit {commit}") + r.git.checkout(commit) + elif branch is not None: + logging.info(f"checking out to branch {branch}") + r.branches[branch].checkout() + else: + logging.info(f"checking out to default branch") + r.active_branch.checkout() + + update_rules(repo_path, save_path, matches, keep_tree) shutil.rmtree("./tmp", ignore_errors=True)