mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-22 06:22:16 +00:00
deploy_tileset_version
This commit is contained in:
@@ -1,81 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import datetime
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import click
|
|
||||||
import requests
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
|
||||||
def cli():
|
|
||||||
"""
|
|
||||||
Deploys the version of tiles specified by https://assets.openfreemap.com/versions/deployed_tiles_planet.txt
|
|
||||||
|
|
||||||
1. Checking if the given version is present on the disk and mounted
|
|
||||||
2. Writing to a version file
|
|
||||||
3. Calling nginx_sync to update the /planet location block
|
|
||||||
"""
|
|
||||||
|
|
||||||
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
|
||||||
|
|
||||||
if not Path('/etc/fstab').exists():
|
|
||||||
sys.exit('Needs to be run on Linux')
|
|
||||||
|
|
||||||
if os.geteuid() != 0:
|
|
||||||
sys.exit('Needs sudo')
|
|
||||||
|
|
||||||
if not Path('/mnt/ofm').exists():
|
|
||||||
sys.exit('mounter.py needs to be run first')
|
|
||||||
|
|
||||||
need_nginx_sync = False
|
|
||||||
|
|
||||||
for area in ['planet', 'monaco']:
|
|
||||||
r = requests.get(f'https://assets.openfreemap.com/versions/deployed_tiles_{area}.txt')
|
|
||||||
r.raise_for_status()
|
|
||||||
version_str = r.text.strip()
|
|
||||||
print(f'remote version for {area}: {version_str}')
|
|
||||||
|
|
||||||
local_version_file = Path(f'/data/ofm/config/deployed_tiles_{area}.txt')
|
|
||||||
|
|
||||||
if not local_version_file.exists():
|
|
||||||
local_version_start = None
|
|
||||||
else:
|
|
||||||
with open(local_version_file) as fp:
|
|
||||||
local_version_start = fp.read()
|
|
||||||
|
|
||||||
if not version_str:
|
|
||||||
print(' remote version not specified')
|
|
||||||
if local_version_start is not None:
|
|
||||||
local_version_file.unlink()
|
|
||||||
need_nginx_sync = True
|
|
||||||
continue
|
|
||||||
|
|
||||||
mnt_file = Path(f'/mnt/ofm/{area}-{version_str}/metadata.json')
|
|
||||||
if not mnt_file.exists():
|
|
||||||
print(' local version does not exist')
|
|
||||||
if local_version_start is not None:
|
|
||||||
local_version_file.unlink()
|
|
||||||
need_nginx_sync = True
|
|
||||||
continue
|
|
||||||
|
|
||||||
if version_str != local_version_start:
|
|
||||||
with open(local_version_file, 'w') as fp:
|
|
||||||
fp.write(version_str)
|
|
||||||
need_nginx_sync = True
|
|
||||||
|
|
||||||
if need_nginx_sync:
|
|
||||||
print('running nginx_sync.py')
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
[sys.executable, Path(__file__).parent / 'nginx_sync' / 'nginx_sync.py'],
|
|
||||||
check=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
print('\n\n\n')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
cli()
|
|
||||||
@@ -7,6 +7,7 @@ from pathlib import Path
|
|||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR
|
from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR
|
||||||
|
from http_host_lib.deploy_tileset import deploy_tileset
|
||||||
from http_host_lib.download_fonts import download_fonts
|
from http_host_lib.download_fonts import download_fonts
|
||||||
from http_host_lib.download_tileset import download_and_extract_tileset
|
from http_host_lib.download_tileset import download_and_extract_tileset
|
||||||
from http_host_lib.mount import clean_up_mounts, create_fstab
|
from http_host_lib.mount import clean_up_mounts, create_fstab
|
||||||
@@ -110,23 +111,44 @@ def mount():
|
|||||||
clean_up_mounts(MNT_DIR)
|
clean_up_mounts(MNT_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def deploy_tileset_version():
|
||||||
|
"""
|
||||||
|
Deploys the tileset version specified by
|
||||||
|
https://assets.openfreemap.com/versions/deployed_planet.txt
|
||||||
|
|
||||||
|
1. Check if the given version is present on the disk and is mounted
|
||||||
|
2. Write to a version file
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert_linux()
|
||||||
|
assert_sudo()
|
||||||
|
|
||||||
|
if not MNT_DIR.exists():
|
||||||
|
sys.exit('mount needs to be run first')
|
||||||
|
|
||||||
|
return deploy_tileset()
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def sync(ctx):
|
def sync(ctx):
|
||||||
"""
|
"""
|
||||||
Runs the sync task, normally called by cron every minute
|
Runs the sync task, normally called by cron every minute
|
||||||
|
On a new server this also takes care of everything, no need to run anything manually.
|
||||||
"""
|
"""
|
||||||
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
print(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||||
|
|
||||||
downloaded = False
|
downloaded = False
|
||||||
downloaded += ctx.invoke(download_tileset, area='monaco')
|
downloaded += ctx.invoke(download_tileset, area='monaco')
|
||||||
# d2 = ctx.invoke(download_tileset, area='planet')
|
# d2 = ctx.invoke(download_tileset, area='planet')
|
||||||
|
|
||||||
if downloaded:
|
if downloaded:
|
||||||
ctx.invoke(mount)
|
ctx.invoke(mount)
|
||||||
|
|
||||||
ctx.invoke(download_assets)
|
ctx.invoke(download_assets)
|
||||||
|
|
||||||
|
ctx.invoke(deploy_tileset_version)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# TODO
|
# TODO
|
||||||
|
|||||||
43
scripts/http_host/http_host_lib/deploy_tileset.py
Normal file
43
scripts/http_host/http_host_lib/deploy_tileset.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def deploy_tileset():
|
||||||
|
need_nginx_sync = False
|
||||||
|
|
||||||
|
for area in ['planet', 'monaco']:
|
||||||
|
r = requests.get(f'https://assets.openfreemap.com/versions/deployed_tiles_{area}.txt')
|
||||||
|
r.raise_for_status()
|
||||||
|
remote_version = r.text.strip()
|
||||||
|
print(f' remote version for {area}: {remote_version}')
|
||||||
|
|
||||||
|
local_version_file = Path(f'/data/ofm/config/deployed_tiles_{area}.txt')
|
||||||
|
|
||||||
|
if not local_version_file.exists():
|
||||||
|
local_version_start = None
|
||||||
|
else:
|
||||||
|
with open(local_version_file) as fp:
|
||||||
|
local_version_start = fp.read()
|
||||||
|
|
||||||
|
if not remote_version:
|
||||||
|
print(' remote version not specified')
|
||||||
|
if local_version_start is not None:
|
||||||
|
local_version_file.unlink()
|
||||||
|
need_nginx_sync = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
mnt_file = Path(f'/mnt/ofm/{area}-{remote_version}/metadata.json')
|
||||||
|
if not mnt_file.exists():
|
||||||
|
print(' local version does not exist')
|
||||||
|
if local_version_start is not None:
|
||||||
|
local_version_file.unlink()
|
||||||
|
need_nginx_sync = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
if remote_version != local_version_start:
|
||||||
|
with open(local_version_file, 'w') as fp:
|
||||||
|
fp.write(remote_version)
|
||||||
|
need_nginx_sync = True
|
||||||
|
|
||||||
|
return need_nginx_sync
|
||||||
Reference in New Issue
Block a user