git.schokokeks.org
Repositories
Help
Report an Issue
freewvs.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
978fc5c
Branches
Tags
master
v0.1.1
v0.1.2
v0.1.3
v0.1.4
freewvs.git
update-freewvsdb
Use explicit filter for tarfile extraction if available
Hanno Böck
commited
978fc5c
at 2023-05-26 09:37:08
update-freewvsdb
Blame
History
Raw
#!/usr/bin/python3 import os import pathlib import sys import urllib.request import io import tarfile DBURL = "https://freewvsdb.schokokeks.org/" dbpaths = ["/var/lib/freewvs/", str(pathlib.Path.home()) + "/.cache/freewvs/"] 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"): with open(target + "timestamp", encoding="ascii") as f: old = int(f.read()) new = int(urllib.request.urlopen(DBURL + "freewvsdb.timestamp").read()) if new == old: # nothing to do sys.exit() tarball = urllib.request.urlopen(DBURL + str(new) + ".tar.xz").read() tf = tarfile.open(fileobj=io.BytesIO(tarball)) if sys.version_info < (3, 11, 4): tf.extractall(path=target) else: tf.extractall(path=target, filter="data") with open(target + "timestamp", "w", encoding="ascii") as f: f.write(str(new))