This commit is contained in:
Zsolt Ero
2024-08-29 15:53:38 +02:00
parent fc240a0edf
commit 64475f2d18
5 changed files with 59 additions and 51 deletions

View File

@@ -1,30 +1,60 @@
import shutil
import subprocess
from pathlib import Path
import sys
import click
import requests
from http_host_lib.config import config
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_area_version(area: str, version: str):
print('running download_btrfs')
if area not in config.areas:
sys.exit(f' please specify area: {config.areas}')
versions = get_versions_for_area(area)
if version == 'latest':
selected_version = versions[-1]
else:
if version not in versions:
available_versions_str = '\n'.join(versions)
sys.exit(
f'Requested version is not available.\nAvailable versions for {area}:\n{available_versions_str}'
)
selected_version = version
return download_and_extract_btrfs(area, selected_version)
def get_versions_for_area(area: str) -> list:
r = requests.get('https://btrfs.openfreemap.com/dirs.txt', timeout=30)
r.raise_for_status()
versions = [v.split('/')[2] for v in r.text.splitlines() if v.startswith(f'areas/{area}/')]
return sorted(versions)
def download_and_extract_btrfs(area: str, version: str) -> bool:
"""
returns True if downloaded something
returns True if download successful, False if skipped
"""
click.echo(f'downloading {area} {version}')
print(f'downloading {area} {version}')
version_dir = runs_dir / area / version
version_dir = config.runs_dir / area / version
btrfs_file = version_dir / 'tiles.btrfs'
if btrfs_file.exists():
print(' file exists, skipping download')
return False
temp_dir = runs_dir / '_tmp'
temp_dir = config.runs_dir / '_tmp'
shutil.rmtree(temp_dir, ignore_errors=True)
temp_dir.mkdir(parents=True)
url = f'https://{area}.openfreemap.com/{version}/tiles.btrfs.gz'
url = f'https://btrfs.openfreemap.com/areas/{area}/{version}/tiles.btrfs.gz'
# check disk space
disk_free = shutil.disk_usage(temp_dir).free

View File

@@ -3,6 +3,8 @@ from pathlib import Path
class Configuration:
areas = ['planet', 'monaco']
http_host_dir = Path('/data/ofm/http_host')
http_host_bin = http_host_dir / 'bin'