Commit 28ede21f authored by Pietro Albini's avatar Pietro Albini

Merge branch 'init-command' into develop

parents 7f9c0a5a 49eac26c
Pipeline #81 passed with stage
in 0 seconds
......@@ -12,6 +12,9 @@
"command": ["{{base}}/env/bin/pip", "install", "{{artifact}}"]
}
],
"after_install": [
["{{base}}/env/bin/uitwww", "init", "{{base}}/data"]
],
"run": [
"{{base}}/env/bin/uitwww", "run", "-g", "{{gunicorn_config_file}}",
"{{base}}/data"
......
......@@ -37,6 +37,7 @@ def cli():
@click.option("-w", "--workers", help="Number of workers to start", default=3)
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def run(data, gunicorn_config, port, public, workers, debug):
"""Run the application"""
# Create the application instance
src_directory = os.path.dirname(os.path.abspath(__file__))
......@@ -70,3 +71,12 @@ def run(data, gunicorn_config, port, public, workers, debug):
server.run()
except SystemExit:
pass
@cli.command("init")
@click.argument("data")
def init(data):
"""Initialize the data directory"""
print("Initializing data directory:", data)
data_path = os.path.expanduser(os.path.abspath(data))
uitwww.init_data_directory(data_path)
......@@ -23,8 +23,15 @@ BASE = "https://api.launchpad.net/devel"
def fetch_paginated(initial):
"""Fetch paginated data"""
next_url = initial
while True:
data = requests.get(next_url).json()
retry_count = 0
while retry_count < 5:
resp = requests.get(next_url)
if resp.status_code == 200:
retry_count = 0
data = resp.json()
else:
retry_count += 1
continue
for entry in data["entries"]:
yield entry
......@@ -33,6 +40,9 @@ def fetch_paginated(initial):
break
next_url = data["next_collection_link"]
if retry_count:
raise RuntimeError("Failed to contact launchpad!")
def get_cdimage_mirrors(distro, country):
"""Get a list of cdimage mirrors"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment