-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.py
72 lines (55 loc) · 2.18 KB
/
upload.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import apsw
import os
import subprocess
import yaml
def backup(secrets_file="secrets.yaml"):
f = open(secrets_file)
secrets = yaml.load(f, Loader=yaml.SafeLoader)
f.close()
ldb_conn = apsw.Connection("db/lbrynomics.db")
ldb = ldb_conn.cursor()
ldb.execute("PRAGMA main.wal_checkpoint(FULL);")
ldb_conn.close()
os.system("zstd -19 db/lbrynomics.db -o ./lbrynomics.db.zst")
cmd = "sshpass -e scp -P {port} lbrynomics.db.zst {user}@{dest}"\
.format(user=secrets["user"],
dest=secrets["destination"], port=secrets["port"])
env = os.environ.copy()
env["SSHPASS"] = secrets["password"]
result = subprocess.run(cmd, env=env, shell=True)
os.system("rm lbrynomics.db.zst")
def upload(secrets_file="secrets.yaml", html_plot=False, include_pngs=True):
print("Uploading files: ", flush=True, end="")
#os.system("rm upload/*")
if html_plot:
os.system("mv plots/*.html upload")
os.system("mv plots/*.svg upload")
else:
if include_pngs:
os.system("mv plots/*.png upload")
os.system("mv json/*.json upload")
f = open(secrets_file)
secrets = yaml.load(f, Loader=yaml.SafeLoader)
f.close()
wildcard = "*"
if html_plot:
wildcard += ".html"
print(f"upload/{wildcard}", flush=True)
cmd = "sshpass -e scp -C -P {port} upload/{wildcard} {user}@{dest}"\
.format(user=secrets["user"], wildcard=wildcard,
dest=secrets["destination"], port=secrets["port"])
env = os.environ.copy()
env["SSHPASS"] = secrets["password"]
result = subprocess.run(cmd, env=env, shell=True)
if html_plot:
wildcard = "*.svg"
print(f"upload/{wildcard}", flush=True)
cmd = "sshpass -e scp -C -P {port} upload/{wildcard} {user}@{dest}"\
.format(user=secrets["user"], wildcard=wildcard,
dest=secrets["destination"], port=secrets["port"])
env = os.environ.copy()
env["SSHPASS"] = secrets["password"]
result = subprocess.run(cmd, env=env, shell=True)
os.system("rm upload/*.html")
os.system("rm upload/*.svg")
print("done.\n", flush=True)