mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
version checking using "done" files
This commit is contained in:
@@ -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:
|
def download_area_version(area: str, version: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Downloads and uncompresses tiles.btrfs files from the btrfs bucket
|
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:
|
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)
|
versions = get_versions_for_area(area)
|
||||||
|
if not versions:
|
||||||
|
print(f' No version found for {area}')
|
||||||
|
return False
|
||||||
|
|
||||||
# latest version
|
# latest version
|
||||||
if version == 'latest':
|
if version == 'latest':
|
||||||
@@ -32,9 +38,10 @@ def download_area_version(area: str, version: str) -> bool:
|
|||||||
else:
|
else:
|
||||||
if version not in versions:
|
if version not in versions:
|
||||||
available_versions_str = '\n'.join(versions)
|
available_versions_str = '\n'.join(versions)
|
||||||
sys.exit(
|
print(
|
||||||
f'Requested version is not available.\nAvailable versions for {area}:\n{available_versions_str}'
|
f' Requested version is not available.\nAvailable versions for {area}:\n{available_versions_str}'
|
||||||
)
|
)
|
||||||
|
return False
|
||||||
selected_version = version
|
selected_version = version
|
||||||
|
|
||||||
return download_and_extract_btrfs(area, selected_version)
|
return download_and_extract_btrfs(area, selected_version)
|
||||||
|
|||||||
@@ -19,11 +19,16 @@ class Configuration:
|
|||||||
certs_dir = Path('/data/nginx/certs')
|
certs_dir = Path('/data/nginx/certs')
|
||||||
nginx_confs = Path(__file__).parent / 'nginx_confs'
|
nginx_confs = Path(__file__).parent / 'nginx_confs'
|
||||||
|
|
||||||
ofm_config_dir = Path('/data/ofm/config')
|
if Path('/data/ofm').exists():
|
||||||
deployed_versions_dir = ofm_config_dir / 'deployed_versions'
|
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())
|
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_config = ofm_config_dir / 'rclone.conf'
|
||||||
rclone_bin = subprocess.run(['which', 'rclone'], capture_output=True, text=True).stdout.strip()
|
rclone_bin = subprocess.run(['which', 'rclone'], capture_output=True, text=True).stdout.strip()
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,23 @@ import requests
|
|||||||
|
|
||||||
|
|
||||||
def get_versions_for_area(area: str) -> list:
|
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()
|
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)
|
return sorted(versions)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user