Skip to content

Commit 08d17df

Browse files
committed
refactor tile_gen in Python
1 parent 41f49b0 commit 08d17df

File tree

17 files changed

+352
-273
lines changed

17 files changed

+352
-273
lines changed

init-server.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ def debug(hostname, user, port):
134134
# sudo_cmd(c, f'{VENV_BIN}/python -u /data/ofm/http_host/bin/host_manager.py nginx-sync')
135135

136136
# put(c, SCRIPTS_DIR / 'tile_gen' / 'upload_manager.py', f'{TILE_GEN_BIN}')
137-
put_dir(c, SCRIPTS_DIR / 'loadbalancer', '/data/ofm/loadbalancer')
138-
put_dir(
139-
c,
140-
SCRIPTS_DIR / 'loadbalancer' / 'loadbalancer_lib',
141-
'/data/ofm/loadbalancer/loadbalancer_lib',
142-
)
137+
# put_dir(c, SCRIPTS_DIR / 'loadbalancer', '/data/ofm/loadbalancer')
138+
# put_dir(
139+
# c,
140+
# SCRIPTS_DIR / 'loadbalancer' / 'loadbalancer_lib',
141+
# '/data/ofm/loadbalancer/loadbalancer_lib',
142+
# )
143+
144+
prepare_tile_gen(c)
143145

144146

145147
if __name__ == '__main__':

scripts/debug_proxy/src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export default {
3131
url.pathname = '/styles/bright'
3232
}
3333

34-
// no failure, just warning
35-
if (request.method !== 'GET') {
36-
const warningMessage = `Non-GET request ${request.method} ${url.pathname} ${userIP}`
37-
console.error(warningMessage)
38-
await sendTelegramMessage(warningMessage, env.TELEGRAM_TOKEN, env.TELEGRAM_CHAT_ID)
39-
}
34+
// // no failure, just warning
35+
// if (request.method !== 'GET') {
36+
// const warningMessage = `Non-GET request ${request.method} ${url.pathname} ${userIP}`
37+
// console.error(warningMessage)
38+
// await sendTelegramMessage(warningMessage, env.TELEGRAM_TOKEN, env.TELEGRAM_CHAT_ID)
39+
// }
4040

4141
if (!url.pathname.startsWith('/styles')) {
4242
const errorMessage = 'Bad path'

scripts/tile_gen/extract_btrfs.sh

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

scripts/tile_gen/planetiler_monaco.sh

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

scripts/tile_gen/planetiler_planet.sh

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

scripts/tile_gen/scripts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
These are self contained Python scripts, they can be run outside of this project's environment.
2+

scripts/tile_gen/tile_gen.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import subprocess
5+
from pathlib import Path
6+
7+
import click
8+
from tile_gen_lib.config import config
9+
from tile_gen_lib.extract import make_btrfs
10+
from tile_gen_lib.planetiler import run_planetiler
11+
from tile_gen_lib.upload import make_indexes, upload_rclone
12+
13+
14+
@click.group()
15+
def cli():
16+
"""
17+
Generates tiles and uploads to CloudFlare
18+
"""
19+
20+
21+
@cli.command()
22+
@click.argument('area', required=True)
23+
def make_tiles(area):
24+
"""
25+
Generate tiles for a given area
26+
"""
27+
28+
# run_planetiler(area)
29+
make_btrfs(Path('/data/ofm/tile_gen/runs/monaco/20240826_230406_pt'))
30+
31+
32+
@cli.command()
33+
def upload_runs():
34+
"""
35+
Upload all runs present in system
36+
"""
37+
38+
print('running upload_runs')
39+
40+
for area in config.areas:
41+
if not (config.runs_dir / area).exists():
42+
continue
43+
44+
p = subprocess.run(
45+
[
46+
'rclone',
47+
'lsjson',
48+
'--dirs-only',
49+
'--fast-list',
50+
f'remote:ofm-{area}',
51+
],
52+
text=True,
53+
capture_output=True,
54+
check=True,
55+
env=dict(RCLONE_CONFIG='/data/ofm/config/rclone.conf'),
56+
)
57+
rclone_json = json.loads(p.stdout)
58+
runs_remote = {p['Path'] for p in rclone_json}
59+
runs_local = {p.name for p in (config.runs_dir / area).iterdir()}
60+
61+
runs_to_upload = runs_local - runs_remote
62+
for run in runs_to_upload:
63+
print(f'uploading {area} {run}')
64+
upload_rclone(area, run)
65+
66+
make_indexes()
67+
68+
69+
@cli.command()
70+
def index():
71+
"""
72+
Run index on Cloudflare buckets
73+
"""
74+
75+
make_indexes()
76+
77+
78+
if __name__ == '__main__':
79+
cli()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pathlib import Path
2+
3+
4+
class Configuration:
5+
tile_gen_dir = Path('/data/ofm/tile_gen')
6+
7+
tile_gen_bin = tile_gen_dir / 'bin'
8+
tile_gen_scripts_dir = tile_gen_bin / 'scripts'
9+
10+
planetiler_bin = tile_gen_dir / 'planetiler'
11+
planetiler_path = planetiler_bin / 'planetiler.jar'
12+
13+
runs_dir = tile_gen_dir / 'runs'
14+
15+
areas = ['planet', 'monaco']
16+
17+
18+
config = Configuration()

0 commit comments

Comments
 (0)