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

@@ -5,7 +5,7 @@ from pathlib import Path
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:
@@ -26,6 +26,17 @@ def download_and_extract_tileset(area: str, version: str, runs_dir: Path) -> boo
temp_dir.mkdir(parents=True)
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'
download_file_aria2(url, target_file)