mirror of
https://github.com/MetaCubeX/subconverter.git
synced 2025-09-26 23:09:20 +08:00
Update rules updater script
This commit is contained in:
parent
1f57413025
commit
40ba3fd970
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user