Skip to content

Commit 5b642cb

Browse files
Add sync_aur script for AUR and GitHub PKGBUILD synchronization
1 parent 4289c74 commit 5b642cb

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tools/sync_aur.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import hashlib
2+
import logging
3+
import shutil
4+
import sys
5+
import os
6+
7+
logging.basicConfig(
8+
level = logging.DEBUG,
9+
format = "[%(asctime)s] [%(levelname)s] %(message)s",
10+
datefmt = "%Y-%m-%d %H:%M:%S"
11+
)
12+
13+
def get_sha512(file_path: str) -> str:
14+
hasher = hashlib.sha512()
15+
16+
with open(file = file_path, mode = "rb") as file:
17+
while chunk := file.read(8192):
18+
hasher.update(chunk)
19+
20+
return hasher.hexdigest()
21+
22+
def file_exists(file_path: str) -> bool:
23+
return os.path.exists(file_path)
24+
25+
def match_aur(github_file: str, aur_file: str, verbose: str) -> None:
26+
if not file_exists(github_file) or not file_exists(aur_file):
27+
logging.error(f"{github_file} or {aur_file} is not exists.")
28+
sys.exit(1)
29+
30+
github_sha512: str = get_sha512(github_file)
31+
aur_sha512: str = get_sha512(aur_file)
32+
33+
if github_sha512 != aur_sha512:
34+
logging.warning(f"{github_file} & {aur_file} is not matches. Sync now.")
35+
shutil.copy2(aur_file, github_file)
36+
37+
logging.info("Successfully sync AUR PKGBUILD to GitHub PKGBUILD.")
38+
39+
if verbose == "--verbose":
40+
logging.info(f"GitHub File SHA512: {github_sha512}")
41+
logging.info(f"AUR File SHA512: {aur_sha512}")
42+
43+
sys.exit(0)
44+
45+
logging.info("SHA512 Matches. Don't need sync")
46+
logging.info(f"GitHub File SHA512: {github_sha512}")
47+
logging.info(f"AUR File SHA512: {aur_sha512}")
48+
sys.exit(0)
49+
50+
match_aur(github_file = sys.argv[1], aur_file = sys.argv[2], verbose = sys.argv[3])

0 commit comments

Comments
 (0)