sync, check disk space

This commit is contained in:
Zsolt Ero
2024-02-22 23:47:56 +01:00
parent 4aa4465654
commit b11342f929
4 changed files with 23 additions and 6 deletions

View File

@@ -110,9 +110,7 @@ def add_http_host_cron(c):
def run_http_host_sync(c): def run_http_host_sync(c):
sudo_cmd( sudo_cmd(c, '/data/ofm/venv/bin/python -u /data/ofm/http_host/bin/host_manager.py sync')
c, '/data/ofm/venv/bin/python -u /data/ofm/http_host/bin/host_manager.py sync', user='ofm'
)
def upload_https_host_files(c): def upload_https_host_files(c):
@@ -218,6 +216,7 @@ def tile_gen(hostname, user, port):
def debug(hostname, user, port): def debug(hostname, user, port):
c = get_connection(hostname, user, port) c = get_connection(hostname, user, port)
upload_https_host_files(c)
run_http_host_sync(c) run_http_host_sync(c)

View File

@@ -179,6 +179,9 @@ def sync(ctx):
print('running sync') print('running sync')
print(datetime.datetime.now(tz=datetime.timezone.utc)) print(datetime.datetime.now(tz=datetime.timezone.utc))
assert_linux()
assert_sudo()
download_done = False download_done = False
download_done += ctx.invoke(download_tileset, area='monaco') download_done += ctx.invoke(download_tileset, area='monaco')
download_done += ctx.invoke(download_tileset, area='planet') download_done += ctx.invoke(download_tileset, area='planet')

View File

@@ -21,7 +21,9 @@ def download_fonts(assets_dir: Path):
return return
ofm_dir = fonts_dir / 'ofm' ofm_dir = fonts_dir / 'ofm'
shutil.rmtree(ofm_dir, ignore_errors=True) ofm_dir_bak = fonts_dir / 'ofm.bak'
shutil.rmtree(ofm_dir_bak, ignore_errors=True)
ofm_dir.rename(ofm_dir_bak)
subprocess.run( subprocess.run(
['tar', '-xzf', local_file, '-C', fonts_dir], ['tar', '-xzf', local_file, '-C', fonts_dir],
@@ -43,7 +45,9 @@ def download_styles(assets_dir: Path):
return return
ofm_dir = styles_dir / 'ofm' ofm_dir = styles_dir / 'ofm'
shutil.rmtree(ofm_dir, ignore_errors=True) ofm_dir_bak = styles_dir / 'ofm.bak'
shutil.rmtree(ofm_dir_bak, ignore_errors=True)
ofm_dir.rename(ofm_dir_bak)
subprocess.run( subprocess.run(
['tar', '-xzf', local_file, '-C', styles_dir], ['tar', '-xzf', local_file, '-C', styles_dir],

View File

@@ -5,7 +5,7 @@ from pathlib import Path
import click import click
from http_host_lib.utils import download_file_aria2 from http_host_lib.utils import download_file_aria2, get_remote_file_size
def download_and_extract_tileset(area: str, version: str, runs_dir: Path) -> bool: def download_and_extract_tileset(area: str, version: str, runs_dir: Path) -> bool:
@@ -26,6 +26,17 @@ def download_and_extract_tileset(area: str, version: str, runs_dir: Path) -> boo
temp_dir.mkdir(parents=True) temp_dir.mkdir(parents=True)
url = f'https://{area}.openfreemap.com/{version}/tiles.btrfs.gz' url = f'https://{area}.openfreemap.com/{version}/tiles.btrfs.gz'
# check disk space
disk_free = shutil.disk_usage(temp_dir).free
file_size = get_remote_file_size(url)
if not file_size:
raise ValueError('Cannot get remote file size')
needed_space = file_size * 3
if disk_free < needed_space:
raise ValueError(f'Not enough disk space. Needed: {needed_space}, free space: {disk_free}')
target_file = temp_dir / 'tiles.btrfs.gz' target_file = temp_dir / 'tiles.btrfs.gz'
download_file_aria2(url, target_file) download_file_aria2(url, target_file)