Hanno Böck commited on 2019-12-23 18:02:53
Zeige 1 geänderte Dateien mit 44 Einfügungen und 0 Löschungen.
| ... | ... |
@@ -0,0 +1,44 @@ |
| 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/" |
|
| 12 |
+dbpaths = ['/var/lib/freewvs/', str(pathlib.Path.home()) + "/.cache/freewvs/"] |
|
| 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"): |
|
| 30 |
+ with open(target + "timestamp", "r") as f: |
|
| 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) |
|
| 43 |
+with open(target + "timestamp", "w") as f: |
|
| 44 |
+ f.write(str(new)) |
|
| 0 | 45 |