a3e985fc81e20c7b7c001a379384a2336ee246d3
Hanno Böck add update script

Hanno Böck authored 4 years ago

1) #!/usr/bin/python3
2) 
3) import os
4) import pathlib
5) import sys
6) import urllib.request
7) import io
8) import tarfile
9) 
10) 
11) DBURL = "https://freewvsdb.schokokeks.org/"
Hanno Böck use black codingstyle

Hanno Böck authored 2 years 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) 
14) target = False
15) for dbpath in dbpaths:
16)     if not os.path.isdir(dbpath):
17)         try:
18)             os.makedirs(dbpath)
19)         except PermissionError:
20)             continue
21)     if os.access(dbpath, os.W_OK):
22)         target = dbpath
23)         break
24) 
25) if not target:
26)     sys.exit("Can't write to " + " or ".join(dbpaths))
27) 
28) old = 0
29) if os.path.isfile(target + "timestamp"):
Hanno Böck fix new pylint warnings

Hanno Böck authored 3 years ago

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

Hanno Böck authored 4 years ago

31)         old = int(f.read())
32) 
33) new = int(urllib.request.urlopen(DBURL + "freewvsdb.timestamp").read())
34) 
35) if new == old:
36)     # nothing to do
37)     sys.exit()
38) 
39) tarball = urllib.request.urlopen(DBURL + str(new) + ".tar.xz").read()
40) 
41) tf = tarfile.open(fileobj=io.BytesIO(tarball))
42) tf.extractall(path=target)
Hanno Böck fix new pylint warnings

Hanno Böck authored 3 years ago

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