master
Hanno Böck add update script

Hanno Böck authored 4 years ago

1) #!/usr/bin/python3
2) 
Hanno Böck add -f/--force parameter to...

Hanno Böck authored 2 weeks ago

3) import argparse
Hanno Böck sort imports

Hanno Böck authored 3 months ago

4) import io
Hanno Böck add update script

Hanno Böck authored 4 years ago

5) import os
6) import pathlib
7) import sys
8) import tarfile
Hanno Böck sort imports

Hanno Böck authored 3 months ago

9) import urllib.request
Hanno Böck add update script

Hanno Böck authored 4 years ago

10) 
11) DBURL = "https://freewvsdb.schokokeks.org/"
Hanno Böck use black codingstyle

Hanno Böck authored 1 year ago

12) dbpaths = ["/var/lib/freewvs/", str(pathlib.Path.home()) + "/.cache/freewvs/"]
Hanno Böck add update script

Hanno Böck authored 4 years ago

13) 
Hanno Böck add -f/--force parameter to...

Hanno Böck authored 2 weeks ago

14) ap = argparse.ArgumentParser()
15) ap.add_argument("-f", "--force", action="store_true", help="Force update")
16) args = ap.parse_args()
17) 
Hanno Böck add update script

Hanno Böck authored 4 years ago

18) target = False
19) for dbpath in dbpaths:
20)     if not os.path.isdir(dbpath):
21)         try:
22)             os.makedirs(dbpath)
23)         except PermissionError:
24)             continue
25)     if os.access(dbpath, os.W_OK):
26)         target = dbpath
27)         break
28) 
29) if not target:
30)     sys.exit("Can't write to " + " or ".join(dbpaths))
31) 
32) old = 0
33) if os.path.isfile(target + "timestamp"):
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

34)     with open(target + "timestamp", encoding="ascii") as f:
Hanno Böck add update script

Hanno Böck authored 4 years ago

35)         old = int(f.read())
36) 
37) new = int(urllib.request.urlopen(DBURL + "freewvsdb.timestamp").read())
38) 
Hanno Böck add -f/--force parameter to...

Hanno Böck authored 2 weeks ago

39) if new == old and not args.force:
Hanno Böck add update script

Hanno Böck authored 4 years ago

40)     # nothing to do
41)     sys.exit()
42) 
43) tarball = urllib.request.urlopen(DBURL + str(new) + ".tar.xz").read()
44) 
45) tf = tarfile.open(fileobj=io.BytesIO(tarball))
Hanno Böck Use explicit filter for tar...

Hanno Böck authored 10 months ago

46) if sys.version_info < (3, 11, 4):
47)     tf.extractall(path=target)
48) else:
49)     tf.extractall(path=target, filter="data")
Hanno Böck fix new pylint warnings

Hanno Böck authored 2 years ago

50) with open(target + "timestamp", "w", encoding="ascii") as f: