mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-22 14:32:15 +00:00
work
This commit is contained in:
@@ -7,7 +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.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.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
|
||||||
from http_host_lib.nginx import write_nginx_config
|
from http_host_lib.nginx import write_nginx_config
|
||||||
@@ -95,6 +95,7 @@ def download_assets(assets_dir: Path):
|
|||||||
|
|
||||||
download_fonts(assets_dir)
|
download_fonts(assets_dir)
|
||||||
download_natural_earth(assets_dir)
|
download_natural_earth(assets_dir)
|
||||||
|
download_sprites(assets_dir)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
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):
|
def download_fonts(assets_dir: Path):
|
||||||
@@ -18,7 +20,7 @@ def download_fonts(assets_dir: Path):
|
|||||||
|
|
||||||
for font in ['ofm']:
|
for font in ['ofm']:
|
||||||
url = f'https://assets.openfreemap.com/fonts/{font}.tar.gz'
|
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):
|
if not download_if_size_differs(url, local_file):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -43,6 +45,36 @@ def download_fonts(assets_dir: Path):
|
|||||||
shutil.rmtree(fonts_temp, ignore_errors=True)
|
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):
|
def download_natural_earth(assets_dir: Path):
|
||||||
ne_dir = assets_dir / 'natural_earth'
|
ne_dir = assets_dir / 'natural_earth'
|
||||||
|
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ server {
|
|||||||
add_header Cache-Control public;
|
add_header Cache-Control public;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /ne/ {
|
location /ne2_shaded/ {
|
||||||
# trailing slash
|
# 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;
|
try_files $uri =404;
|
||||||
|
|
||||||
expires 1d; # target 10y
|
expires 1d; # target 10y
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def get_remote_file_size(url: str) -> int | None:
|
|||||||
|
|
||||||
|
|
||||||
def download_file_aria2(url: str, local_file: Path):
|
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)
|
local_file.unlink(missing_ok=True)
|
||||||
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
|
|||||||
Reference in New Issue
Block a user