Skip to content

Commit

Permalink
Update rules updater script
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 committed Apr 6, 2024
1 parent 1f57413 commit 40ba3fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions scripts/rules_config.conf
Original file line number Diff line number Diff line change
@@ -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
20 changes: 15 additions & 5 deletions scripts/update_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 40ba3fd

Please sign in to comment.