From 44359c8ca9bbf37f480e44de62bcdb794590de2b Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Mon, 8 Jan 2024 18:44:05 +0100 Subject: [PATCH] download_natural_earth --- .gitignore | 1 + init-server.py | 3 +-- scripts/http_host/host_manager.py | 3 ++- .../{download_fonts.py => download_assets.py} | 27 +++++++++++++++++-- scripts/http_host/http_host_lib/utils.py | 1 + 5 files changed, 30 insertions(+), 5 deletions(-) rename scripts/http_host/http_host_lib/{download_fonts.py => download_assets.py} (64%) diff --git a/.gitignore b/.gitignore index e67beac..227472f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ rclone.conf node_modules tmp temp +_temp /.idea venv diff --git a/init-server.py b/init-server.py index cd6df69..0d09274 100755 --- a/init-server.py +++ b/init-server.py @@ -135,8 +135,7 @@ def install_benchmark(c): def debug_tmp(c): - install_benchmark(c) - # upload_https_host_files(c) + upload_https_host_files(c) # put(c, SCRIPTS_DIR / 'http_host' / 'cron.d' / 'ofm_http_host', '/etc/cron.d/') diff --git a/scripts/http_host/host_manager.py b/scripts/http_host/host_manager.py index 55dc836..830b3bb 100755 --- a/scripts/http_host/host_manager.py +++ b/scripts/http_host/host_manager.py @@ -7,7 +7,7 @@ from pathlib import Path import click import requests from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR -from http_host_lib.download_fonts import download_fonts +from http_host_lib.download_assets import download_fonts, download_natural_earth 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.nginx import write_nginx_config @@ -94,6 +94,7 @@ def download_assets(assets_dir: Path): sys.exit("asset dir's parent doesn't exist") download_fonts(assets_dir) + download_natural_earth(assets_dir) @cli.command() diff --git a/scripts/http_host/http_host_lib/download_fonts.py b/scripts/http_host/http_host_lib/download_assets.py similarity index 64% rename from scripts/http_host/http_host_lib/download_fonts.py rename to scripts/http_host/http_host_lib/download_assets.py index 5de908a..293e1d6 100644 --- a/scripts/http_host/http_host_lib/download_fonts.py +++ b/scripts/http_host/http_host_lib/download_assets.py @@ -16,8 +16,8 @@ def download_fonts(assets_dir: Path): fonts_temp = assets_dir / 'fonts_temp' - for font in ['ml', 'omt', 'pm']: - url = f'https://assets.openfreemap.com/fonts/{font}.tgz' + for font in ['ofm']: + url = f'https://assets.openfreemap.com/fonts/{font}.tar.gz' local_file = fonts_dir / f'{font}.tgz' if not download_if_size_differs(url, local_file): continue @@ -41,3 +41,26 @@ def download_fonts(assets_dir: Path): shutil.rmtree(target_dir_renamed, ignore_errors=True) shutil.rmtree(fonts_temp, ignore_errors=True) + + +def download_natural_earth(assets_dir: Path): + ne_dir = assets_dir / 'natural_earth' + + if (ne_dir / 'tiles' / 'natural_earth_2_shaded_relief.raster' / '0' / '0' / '0.png').exists(): + return + + ne_dir.mkdir(exist_ok=True, parents=True) + + subprocess.run( + [ + 'git', + 'clone', + '--depth=1', + '-b', + 'gh-pages', + 'https://github.com/lukasmartinelli/naturalearthtiles.git', + ne_dir, + ] + ) + + shutil.rmtree(ne_dir / '.git') diff --git a/scripts/http_host/http_host_lib/utils.py b/scripts/http_host/http_host_lib/utils.py index bd006fd..02b7f02 100644 --- a/scripts/http_host/http_host_lib/utils.py +++ b/scripts/http_host/http_host_lib/utils.py @@ -40,6 +40,7 @@ def get_remote_file_size(url: str) -> int | None: def download_file_aria2(url: str, local_file: Path): print(f' downloading: {url} into {local_file}') + local_file.unlink(missing_ok=True) subprocess.run( [