This commit is contained in:
Zsolt Ero
2024-01-10 21:14:23 +01:00
parent 1b7dde229a
commit 8f6e45dc61
4 changed files with 39 additions and 6 deletions

View File

@@ -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_assets import download_fonts, download_natural_earth
from http_host_lib.download_assets import download_fonts, download_natural_earth, download_sprites
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
@@ -95,6 +95,7 @@ def download_assets(assets_dir: Path):
download_fonts(assets_dir)
download_natural_earth(assets_dir)
download_sprites(assets_dir)
@cli.command()

View File

@@ -2,7 +2,9 @@ import shutil
import subprocess
from pathlib import Path
from http_host_lib.utils import download_if_size_differs
import requests
from http_host_lib.utils import download_file_aria2, download_if_size_differs
def download_fonts(assets_dir: Path):
@@ -18,7 +20,7 @@ def download_fonts(assets_dir: Path):
for font in ['ofm']:
url = f'https://assets.openfreemap.com/fonts/{font}.tar.gz'
local_file = fonts_dir / f'{font}.tgz'
local_file = fonts_dir / f'{font}.tar.gz'
if not download_if_size_differs(url, local_file):
continue
@@ -43,6 +45,36 @@ def download_fonts(assets_dir: Path):
shutil.rmtree(fonts_temp, ignore_errors=True)
def download_sprites(assets_dir: Path):
"""
Download and extract sprites if their file size differ.
"""
sprites_dir = assets_dir / 'sprites'
sprites_dir.mkdir(exist_ok=True, parents=True)
r = requests.get('https://assets.openfreemap.com/index.txt', timeout=30)
r.raise_for_status()
sprites_remote = [l for l in r.text.splitlines() if l.startswith('sprites/')]
for sprite in sprites_remote:
sprite_name = sprite.split('/')[1].replace('.tar.gz', '')
if (sprites_dir / sprite_name).is_dir():
continue
url = f'https://assets.openfreemap.com/sprites/{sprite_name}.tar.gz'
local_file = sprites_dir / 'temp.tar.gz'
download_file_aria2(url, local_file)
subprocess.run(
['tar', '-xzf', local_file, '-C', sprites_dir],
check=True,
)
local_file.unlink()
def download_natural_earth(assets_dir: Path):
ne_dir = assets_dir / 'natural_earth'

View File

@@ -38,10 +38,10 @@ server {
add_header Cache-Control public;
}
location /ne/ {
location /ne2_shaded/ {
# trailing slash
alias /data/ofm/http_host/assets/natural_earth/tiles/; # trailing slash
alias /data/ofm/http_host/assets/natural_earth/tiles/natural_earth_2_shaded_relief.raster/; # trailing slash
try_files $uri =404;
expires 1d; # target 10y

View File

@@ -39,7 +39,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}')
print(f' downloading {url} into {local_file}')
local_file.unlink(missing_ok=True)
subprocess.run(