setversion, http_host

This commit is contained in:
Zsolt Ero
2024-06-24 17:56:05 +02:00
parent 11a9879f18
commit 37afbbb902
8 changed files with 106 additions and 40 deletions

View File

@@ -0,0 +1,17 @@
from setuptools import find_packages, setup
requirements = [
'click',
'requests',
'pycurl',
'python-dotenv',
'questionary',
]
setup(
python_requires='>=3.10',
install_requires=requirements,
packages=find_packages(),
)

View File

@@ -0,0 +1,62 @@
#!/usr/bin/env python3
import subprocess
import click
import questionary
from setversion_lib import RCLONE_BIN, RCLONE_CONF
@click.group()
def cli():
"""
Sets deployed reference versions
"""
@cli.command()
@click.argument('area', required=True)
def interactive(area):
versions = get_available_versions(area)[::-1]
choices = [questionary.Choice(title=r, value=i) for i, r in enumerate(versions)]
answer = questionary.select(f'Select version for: {area}', choices=choices).ask()
selected = versions[answer]
set_version(area, selected)
def get_available_versions(area):
p = subprocess.run(
[
RCLONE_BIN,
'cat',
f'remote:ofm-{area}/dirs.txt',
],
env=dict(RCLONE_CONFIG=RCLONE_CONF),
check=True,
capture_output=True,
text=True,
)
versions = [l.strip() for l in p.stdout.strip().splitlines()]
versions.sort()
return versions
def set_version(area, version):
subprocess.run(
[
RCLONE_BIN,
'rcat',
f'remote:ofm-assets/versions/deployed_{area}.txt',
],
env=dict(RCLONE_CONFIG=RCLONE_CONF),
check=True,
input=version.encode(),
)
if __name__ == '__main__':
cli()

View File

@@ -0,0 +1,16 @@
from pathlib import Path
if Path('/data/ofm/config').exists():
OFM_CONFIG_DIR = Path('/data/ofm/config')
else:
OFM_CONFIG_DIR = Path(__file__).parent.parent.parent.parent / 'config'
assert OFM_CONFIG_DIR.exists()
RCLONE_CONF = OFM_CONFIG_DIR / 'rclone.conf'
if Path('/opt/homebrew/bin/rclone').exists():
RCLONE_BIN = '/opt/homebrew/bin/rclone'
else:
RCLONE_BIN = 'rclone'