Skip to content

Commit 4709470

Browse files
committed
download_assets
1 parent 7b735e3 commit 4709470

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

scripts/http_host/host_manager.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
import click
88
import requests
99
from http_host_lib import DEFAULT_ASSETS_DIR, DEFAULT_RUNS_DIR, MNT_DIR
10-
from http_host_lib.download_assets import download_fonts, download_natural_earth, download_sprites
10+
from http_host_lib.download_assets import (
11+
download_fonts,
12+
download_natural_earth,
13+
download_sprites,
14+
download_styles,
15+
)
1116
from http_host_lib.download_tileset import download_and_extract_tileset
1217
from http_host_lib.mount import clean_up_mounts, create_fstab
1318
from http_host_lib.nginx import write_nginx_config
1419
from http_host_lib.set_tileset_versions import set_tileset_versions
15-
from http_host_lib.utils import assert_linux, assert_single_process, assert_sudo
20+
from http_host_lib.utils import assert_linux, assert_sudo
1621

1722

1823
@click.group()
@@ -94,9 +99,11 @@ def download_assets(assets_dir: Path):
9499
sys.exit("asset dir's parent doesn't exist")
95100

96101
download_fonts(assets_dir)
97-
download_natural_earth(assets_dir)
102+
download_styles(assets_dir)
98103
download_sprites(assets_dir)
99104

105+
download_natural_earth(assets_dir)
106+
100107

101108
@cli.command()
102109
def mount():

scripts/http_host/http_host_lib/download_assets.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,50 @@
1010
def download_fonts(assets_dir: Path):
1111
"""
1212
Download and extract font assets if their file size differ.
13-
Making updates atomic, with extraction to a temp dest + rename
1413
"""
1514

1615
fonts_dir = assets_dir / 'fonts'
1716
fonts_dir.mkdir(exist_ok=True, parents=True)
1817

19-
fonts_temp = assets_dir / 'fonts_temp'
18+
url = 'https://assets.openfreemap.com/fonts/ofm.tar.gz'
19+
local_file = fonts_dir / 'ofm.tar.gz'
20+
if not download_if_size_differs(url, local_file):
21+
return
2022

21-
for font in ['ofm']:
22-
url = f'https://assets.openfreemap.com/fonts/{font}.tar.gz'
23-
local_file = fonts_dir / f'{font}.tar.gz'
24-
if not download_if_size_differs(url, local_file):
25-
continue
23+
ofm_dir = fonts_dir / 'ofm'
24+
shutil.rmtree(ofm_dir, ignore_errors=True)
2625

27-
shutil.rmtree(fonts_temp, ignore_errors=True)
28-
fonts_temp.mkdir()
26+
subprocess.run(
27+
['tar', '-xzf', local_file, '-C', fonts_dir],
28+
check=True,
29+
)
2930

30-
subprocess.run(
31-
['tar', '-xzf', local_file, '-C', fonts_temp],
32-
check=True,
33-
)
3431

35-
target_dir = fonts_dir / font
36-
target_dir_renamed = fonts_dir / f'{font}.bak'
37-
temp_dir = fonts_temp / font
32+
def download_styles(assets_dir: Path):
33+
"""
34+
Download and extract style assets if their file size differ.
35+
"""
36+
37+
styles_dir = assets_dir / 'styles'
38+
styles_dir.mkdir(exist_ok=True, parents=True)
3839

39-
if target_dir.exists():
40-
target_dir.rename(target_dir_renamed)
41-
temp_dir.rename(target_dir)
40+
url = 'https://assets.openfreemap.com/styles/ofm.tar.gz'
41+
local_file = styles_dir / 'ofm.tar.gz'
42+
if not download_if_size_differs(url, local_file):
43+
return
4244

43-
shutil.rmtree(target_dir_renamed, ignore_errors=True)
45+
ofm_dir = styles_dir / 'ofm'
46+
shutil.rmtree(ofm_dir, ignore_errors=True)
4447

45-
shutil.rmtree(fonts_temp, ignore_errors=True)
48+
subprocess.run(
49+
['tar', '-xzf', local_file, '-C', styles_dir],
50+
check=True,
51+
)
4652

4753

4854
def download_sprites(assets_dir: Path):
4955
"""
50-
Download and extract sprites if their file size differ.
56+
Download and extract sprites if the version is not available
5157
"""
5258

5359
sprites_dir = assets_dir / 'sprites'

0 commit comments

Comments
 (0)