git.schokokeks.org
Repositories
Help
Report an Issue
freewvs.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
c5c6bee
Branches
Tags
master
v0.1.1
v0.1.2
v0.1.3
v0.1.4
v0.1.5
freewvs.git
update-freewvsdb
Codingstyle improvements suggested by ruff preview mode + remove old python compatibility code
Hanno Böck
commited
c5c6bee
at 2026-10-19 21:34:20
update-freewvsdb
Blame
History
Raw
#!/usr/bin/python3 import argparse import io import os import pathlib import sys import tarfile import urllib.request DBURL = "https://freewvsdb.schokokeks.org/" dbpaths = ["/var/lib/freewvs/", str(pathlib.Path.home()) + "/.cache/freewvs/"] ap = argparse.ArgumentParser() ap.add_argument("-f", "--force", action="store_true", help="Force update") args = ap.parse_args() target = False for dbpath in dbpaths: if not os.path.isdir(dbpath): try: os.makedirs(dbpath) except PermissionError: continue if os.access(dbpath, os.W_OK): target = dbpath break if not target: sys.exit("Can't write to " + " or ".join(dbpaths)) old = 0 if os.path.isfile(target + "timestamp"): old = int(pathlib.Path(target + "timestamp").read_text(encoding="ascii")) new = int(urllib.request.urlopen(DBURL + "freewvsdb.timestamp").read()) if new == old and not args.force: # nothing to do sys.exit() tarball = urllib.request.urlopen(DBURL + str(new) + ".tar.xz").read() tf = tarfile.open(fileobj=io.BytesIO(tarball)) tf.extractall(path=target, filter="data") pathlib.Path(target + "timestamp").write_text(str(new), encoding="ascii")