Skip to content

Commit bb73111

Browse files
committed
upload by python
1 parent 54ec000 commit bb73111

File tree

3 files changed

+83
-38
lines changed

3 files changed

+83
-38
lines changed

init-server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44
from fabric import Config, Connection
55

6-
from ssh_lib import SCRIPTS_DIR, VENV_BIN, dotenv_val
6+
from ssh_lib import SCRIPTS_DIR, TILE_GEN_BIN, VENV_BIN, dotenv_val
77
from ssh_lib.planetiler import planetiler
88
from ssh_lib.tasks import (
99
prepare_http_host,
@@ -120,7 +120,7 @@ def debug(hostname, user, port):
120120
# upload_http_host_files(c)
121121
# sudo_cmd(c, f'{VENV_BIN}/python -u /data/ofm/http_host/bin/host_manager.py nginx-sync')
122122

123-
planetiler(c)
123+
put(c, SCRIPTS_DIR / 'tile_gen' / 'upload_manager.py', f'{TILE_GEN_BIN}')
124124

125125

126126
if __name__ == '__main__':

scripts/tile_gen/cloudflare_upload.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

scripts/tile_gen/upload_manager.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
import json
3+
import pathlib
4+
import subprocess
5+
6+
import click
7+
8+
9+
AREAS = ['planet', 'monaco']
10+
11+
RUNS_DIR = pathlib.Path('/data/ofm/tile_gen/runs')
12+
13+
14+
def upload_rclone(area, run):
15+
subprocess.run(
16+
[
17+
'rclone',
18+
'sync',
19+
'--transfers=8',
20+
'--multi-thread-streams=8',
21+
'--fast-list',
22+
'-v',
23+
'--stats-file-name-length',
24+
'0',
25+
'--stats-one-line',
26+
'--log-file',
27+
RUNS_DIR / area / run / 'logs' / 'rclone.log',
28+
'--exclude',
29+
'logs/**',
30+
RUNS_DIR / area / run,
31+
f'remote:ofm-{area}/{run}',
32+
],
33+
env=dict(RCLONE_CONFIG='/data/ofm/config/rclone.conf'),
34+
check=True,
35+
)
36+
37+
38+
@click.group()
39+
def cli():
40+
"""
41+
Uploads runs to Cloudflare
42+
"""
43+
44+
45+
@cli.command()
46+
def upload_runs():
47+
"""
48+
Upload all runs present in system
49+
"""
50+
51+
print('running upload_runs')
52+
53+
for area in AREAS:
54+
if not (RUNS_DIR / area).exists():
55+
continue
56+
57+
p = subprocess.run(
58+
[
59+
'rclone',
60+
'lsjson',
61+
'--dirs-only',
62+
'--fast-list',
63+
f'remote:ofm-{area}',
64+
],
65+
text=True,
66+
capture_output=True,
67+
check=True,
68+
env=dict(RCLONE_CONFIG='/data/ofm/config/rclone.conf'),
69+
)
70+
rclone_json = json.loads(p.stdout)
71+
runs_remote = {p['Path'] for p in rclone_json}
72+
runs_local = {p.name for p in (RUNS_DIR / area).iterdir()}
73+
74+
runs_to_upload = runs_local - runs_remote
75+
for run in runs_to_upload:
76+
print(f'uploading {area} {run}')
77+
upload_rclone(area, run)
78+
79+
80+
if __name__ == '__main__':
81+
cli()

0 commit comments

Comments
 (0)