mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
config refactor, renames
This commit is contained in:
@@ -70,7 +70,7 @@ def download_tileset(area: str, version: str, list_versions: bool, runs_dir: Pat
|
|||||||
selected_version = version
|
selected_version = version
|
||||||
|
|
||||||
if not runs_dir:
|
if not runs_dir:
|
||||||
runs_dir = config.default_runs_dir
|
runs_dir = config.runs_dir
|
||||||
|
|
||||||
if not runs_dir.parent.exists():
|
if not runs_dir.parent.exists():
|
||||||
sys.exit("runs dir's parent doesn't exist")
|
sys.exit("runs dir's parent doesn't exist")
|
||||||
@@ -92,7 +92,7 @@ def download_assets(assets_dir: Path):
|
|||||||
print('running download_assets')
|
print('running download_assets')
|
||||||
|
|
||||||
if not assets_dir:
|
if not assets_dir:
|
||||||
assets_dir = config.default_assets_dir
|
assets_dir = config.assets_dir
|
||||||
|
|
||||||
if not assets_dir.parent.exists():
|
if not assets_dir.parent.exists():
|
||||||
sys.exit("asset dir's parent doesn't exist")
|
sys.exit("asset dir's parent doesn't exist")
|
||||||
@@ -116,7 +116,7 @@ def mount():
|
|||||||
assert_linux()
|
assert_linux()
|
||||||
assert_sudo()
|
assert_sudo()
|
||||||
|
|
||||||
if not config.default_runs_dir.exists():
|
if not config.runs_dir.exists():
|
||||||
sys.exit(' download_tileset needs to be run first')
|
sys.exit(' download_tileset needs to be run first')
|
||||||
|
|
||||||
clean_up_mounts(config.mnt_dir)
|
clean_up_mounts(config.mnt_dir)
|
||||||
|
|||||||
@@ -5,19 +5,20 @@ from pathlib import Path
|
|||||||
class Configuration:
|
class Configuration:
|
||||||
http_host_dir = Path('/data/ofm/http_host')
|
http_host_dir = Path('/data/ofm/http_host')
|
||||||
|
|
||||||
nginx_dir = Path(__file__).parent / 'nginx'
|
http_host_bin = http_host_dir / 'bin'
|
||||||
|
http_host_scripts_dir = http_host_bin / 'scripts'
|
||||||
|
|
||||||
default_runs_dir = http_host_dir / 'runs'
|
runs_dir = http_host_dir / 'runs'
|
||||||
default_assets_dir = http_host_dir / 'assets'
|
assets_dir = http_host_dir / 'assets'
|
||||||
|
|
||||||
mnt_dir = Path('/mnt/ofm')
|
mnt_dir = Path('/mnt/ofm')
|
||||||
ofm_config_dir = Path('/data/ofm/config')
|
ofm_config_dir = Path('/data/ofm/config')
|
||||||
http_host_bin = http_host_dir / 'bin'
|
|
||||||
|
|
||||||
certs_dir = Path('/data/nginx/certs')
|
certs_dir = Path('/data/nginx/certs')
|
||||||
|
nginx_confs = Path(__file__).parent / 'nginx_confs'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open('/data/ofm/config/http_host.json') as fp:
|
with open(ofm_config_dir / 'http_host.json') as fp:
|
||||||
host_config = json.load(fp)
|
host_config = json.load(fp)
|
||||||
except Exception:
|
except Exception:
|
||||||
host_config = {}
|
host_config = {}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ def create_fstab():
|
|||||||
fstab_new = []
|
fstab_new = []
|
||||||
|
|
||||||
for area in ['planet', 'monaco']:
|
for area in ['planet', 'monaco']:
|
||||||
area_dir = (config.default_runs_dir / area).resolve()
|
area_dir = (config.runs_dir / area).resolve()
|
||||||
if not area_dir.exists():
|
if not area_dir.exists():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from http_host_lib.config import config
|
from http_host_lib.config import config
|
||||||
|
from http_host_lib.utils import python_venv_executable
|
||||||
|
|
||||||
|
|
||||||
def write_nginx_config():
|
def write_nginx_config():
|
||||||
@@ -29,7 +30,7 @@ def write_nginx_config():
|
|||||||
subprocess.run(['bash', config.http_host_bin / 'ledns_reader.sh'], check=True)
|
subprocess.run(['bash', config.http_host_bin / 'ledns_reader.sh'], check=True)
|
||||||
|
|
||||||
curl_text_mix += create_nginx_conf(
|
curl_text_mix += create_nginx_conf(
|
||||||
template_path=config.nginx_dir / 'ledns.conf',
|
template_path=config.nginx_confs / 'ledns.conf',
|
||||||
local='ofm_ledns',
|
local='ofm_ledns',
|
||||||
domain=domain_ledns,
|
domain=domain_ledns,
|
||||||
)
|
)
|
||||||
@@ -44,7 +45,7 @@ def write_nginx_config():
|
|||||||
shutil.copyfile(Path('/etc/nginx/ssl/dummy.key'), le_key)
|
shutil.copyfile(Path('/etc/nginx/ssl/dummy.key'), le_key)
|
||||||
|
|
||||||
curl_text_mix += create_nginx_conf(
|
curl_text_mix += create_nginx_conf(
|
||||||
template_path=config.nginx_dir / 'le.conf',
|
template_path=config.nginx_confs / 'le.conf',
|
||||||
local='ofm_le',
|
local='ofm_le',
|
||||||
domain=domain_le,
|
domain=domain_le,
|
||||||
)
|
)
|
||||||
@@ -130,7 +131,7 @@ def create_location_blocks(*, local, domain):
|
|||||||
|
|
||||||
location_str += create_latest_locations(local=local, domain=domain)
|
location_str += create_latest_locations(local=local, domain=domain)
|
||||||
|
|
||||||
with open(config.nginx_dir / 'location_static.conf') as fp:
|
with open(config.nginx_confs / 'location_static.conf') as fp:
|
||||||
location_str += '\n' + fp.read()
|
location_str += '\n' + fp.read()
|
||||||
|
|
||||||
return location_str, curl_text
|
return location_str, curl_text
|
||||||
@@ -139,7 +140,7 @@ def create_location_blocks(*, local, domain):
|
|||||||
def create_version_location(
|
def create_version_location(
|
||||||
*, area: str, version: str, subdir: Path, local: str, domain: str
|
*, area: str, version: str, subdir: Path, local: str, domain: str
|
||||||
) -> str:
|
) -> str:
|
||||||
run_dir = config.default_runs_dir / area / version
|
run_dir = config.runs_dir / area / version
|
||||||
if not run_dir.is_dir():
|
if not run_dir.is_dir():
|
||||||
print(f" {run_dir} doesn't exists, skipping")
|
print(f" {run_dir} doesn't exists, skipping")
|
||||||
return ''
|
return ''
|
||||||
@@ -155,8 +156,8 @@ def create_version_location(
|
|||||||
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
sys.executable,
|
python_venv_executable(),
|
||||||
Path(__file__).parent.parent / 'metadata_to_tilejson.py',
|
config.http_host_scripts_dir / 'metadata_to_tilejson.py',
|
||||||
'--minify',
|
'--minify',
|
||||||
metadata_path,
|
metadata_path,
|
||||||
tilejson_path,
|
tilejson_path,
|
||||||
@@ -203,7 +204,7 @@ def create_latest_locations(*, local: str, domain: str) -> str:
|
|||||||
version = fp.read().strip()
|
version = fp.read().strip()
|
||||||
print(f' setting latest version for {area}: {version}')
|
print(f' setting latest version for {area}: {version}')
|
||||||
|
|
||||||
run_dir = config.default_runs_dir / area / version
|
run_dir = config.runs_dir / area / version
|
||||||
tilejson_path = run_dir / f'tilejson-{local}.json'
|
tilejson_path = run_dir / f'tilejson-{local}.json'
|
||||||
assert tilejson_path.is_file()
|
assert tilejson_path.is_file()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -57,3 +56,14 @@ def download_file_aria2(url: str, local_file: Path):
|
|||||||
],
|
],
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def python_venv_executable() -> Path:
|
||||||
|
venv_path = os.environ.get('VIRTUAL_ENV')
|
||||||
|
|
||||||
|
if venv_path:
|
||||||
|
return Path(venv_path) / 'bin' / 'python'
|
||||||
|
elif sys.prefix != sys.base_prefix:
|
||||||
|
return Path(sys.prefix) / 'bin' / 'python'
|
||||||
|
else:
|
||||||
|
return Path(sys.executable)
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ class Configuration:
|
|||||||
|
|
||||||
runs_dir = tile_gen_dir / 'runs'
|
runs_dir = tile_gen_dir / 'runs'
|
||||||
|
|
||||||
rclone_config = Path('/data/ofm/config/rclone.conf')
|
ofm_config_dir = Path('/data/ofm/config')
|
||||||
|
rclone_config = ofm_config_dir / 'rclone.conf'
|
||||||
|
|
||||||
areas = ['planet', 'monaco']
|
areas = ['planet', 'monaco']
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ def prepare_http_host(c):
|
|||||||
|
|
||||||
|
|
||||||
def run_http_host_sync(c):
|
def run_http_host_sync(c):
|
||||||
|
print('Running host_manager.py sync --force')
|
||||||
sudo_cmd(c, f'{VENV_BIN}/python -u {HTTP_HOST_BIN}/host_manager.py sync --force')
|
sudo_cmd(c, f'{VENV_BIN}/python -u {HTTP_HOST_BIN}/host_manager.py sync --force')
|
||||||
|
|
||||||
|
|
||||||
@@ -146,8 +147,8 @@ def upload_http_host_files(c):
|
|||||||
|
|
||||||
put_dir(
|
put_dir(
|
||||||
c,
|
c,
|
||||||
SCRIPTS_DIR / 'http_host' / 'http_host_lib' / 'nginx',
|
SCRIPTS_DIR / 'http_host' / 'http_host_lib' / 'nginx_confs',
|
||||||
f'{HTTP_HOST_BIN}/http_host_lib/nginx',
|
f'{HTTP_HOST_BIN}/http_host_lib/nginx_confs',
|
||||||
)
|
)
|
||||||
|
|
||||||
c.sudo('chown -R ofm:ofm /data/ofm/http_host')
|
c.sudo('chown -R ofm:ofm /data/ofm/http_host')
|
||||||
|
|||||||
Reference in New Issue
Block a user