diff --git a/modules/http_host/http_host_lib/btrfs.py b/modules/http_host/http_host_lib/btrfs.py index 4f6e6bf..ca59282 100644 --- a/modules/http_host/http_host_lib/btrfs.py +++ b/modules/http_host/http_host_lib/btrfs.py @@ -10,12 +10,18 @@ from http_host_lib.utils import download_file_aria2, get_remote_file_size def download_area_version(area: str, version: str) -> bool: """ Downloads and uncompresses tiles.btrfs files from the btrfs bucket + + "latest" version means the latest in the remote bucket + "deployed" version means to read the currently deployed version string from the config dir """ if area not in config.areas: - sys.exit(f' please specify area: {config.areas}') + sys.exit(f' Please specify area: {config.areas}') versions = get_versions_for_area(area) + if not versions: + print(f' No version found for {area}') + return False # latest version if version == 'latest': @@ -32,9 +38,10 @@ def download_area_version(area: str, version: str) -> bool: 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}' + print( + f' Requested version is not available.\nAvailable versions for {area}:\n{available_versions_str}' ) + return False selected_version = version return download_and_extract_btrfs(area, selected_version) diff --git a/modules/http_host/http_host_lib/config.py b/modules/http_host/http_host_lib/config.py index bca1e0a..4e4fabc 100644 --- a/modules/http_host/http_host_lib/config.py +++ b/modules/http_host/http_host_lib/config.py @@ -19,11 +19,16 @@ class Configuration: certs_dir = Path('/data/nginx/certs') nginx_confs = Path(__file__).parent / 'nginx_confs' - ofm_config_dir = Path('/data/ofm/config') - deployed_versions_dir = ofm_config_dir / 'deployed_versions' + if Path('/data/ofm').exists(): + ofm_config_dir = Path('/data/ofm/config') + else: + repo_root = Path(__file__).parent.parent.parent.parent + ofm_config_dir = repo_root / 'config' ofm_config = json.loads((ofm_config_dir / 'config.json').read_text()) + deployed_versions_dir = ofm_config_dir / 'deployed_versions' + rclone_config = ofm_config_dir / 'rclone.conf' rclone_bin = subprocess.run(['which', 'rclone'], capture_output=True, text=True).stdout.strip() diff --git a/modules/tile_gen/tile_gen_lib/shared.py b/modules/tile_gen/tile_gen_lib/shared.py index 69426f6..1bcac21 100644 --- a/modules/tile_gen/tile_gen_lib/shared.py +++ b/modules/tile_gen/tile_gen_lib/shared.py @@ -7,10 +7,23 @@ import requests def get_versions_for_area(area: str) -> list: - r = requests.get('https://btrfs.openfreemap.com/dirs.txt', timeout=30) + """ + Download the files.txt and check for the runs with the "done" file present + """ + r = requests.get('https://btrfs.openfreemap.com/files.txt', timeout=30) r.raise_for_status() - versions = [v.split('/')[2] for v in r.text.splitlines() if v.startswith(f'areas/{area}/')] + versions = [] + + files = r.text.splitlines() + for f in files: + if not f.startswith(f'areas/{area}/'): + continue + if not f.endswith('/done'): + continue + version_str = f.split('/')[2] + versions.append(version_str) + return sorted(versions)