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 @@ ...@@ -12,6 +12,9 @@
"command": ["{{base}}/env/bin/pip", "install", "{{artifact}}"] "command": ["{{base}}/env/bin/pip", "install", "{{artifact}}"]
} }
], ],
"after_install": [
["{{base}}/env/bin/uitwww", "init", "{{base}}/data"]
],
"run": [ "run": [
"{{base}}/env/bin/uitwww", "run", "-g", "{{gunicorn_config_file}}", "{{base}}/env/bin/uitwww", "run", "-g", "{{gunicorn_config_file}}",
"{{base}}/data" "{{base}}/data"
......
...@@ -37,6 +37,7 @@ def cli(): ...@@ -37,6 +37,7 @@ def cli():
@click.option("-w", "--workers", help="Number of workers to start", default=3) @click.option("-w", "--workers", help="Number of workers to start", default=3)
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True) @click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def run(data, gunicorn_config, port, public, workers, debug): def run(data, gunicorn_config, port, public, workers, debug):
"""Run the application"""
# Create the application instance # Create the application instance
src_directory = os.path.dirname(os.path.abspath(__file__)) src_directory = os.path.dirname(os.path.abspath(__file__))
...@@ -70,3 +71,12 @@ def run(data, gunicorn_config, port, public, workers, debug): ...@@ -70,3 +71,12 @@ def run(data, gunicorn_config, port, public, workers, debug):
server.run() server.run()
except SystemExit: except SystemExit:
pass 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" ...@@ -23,8 +23,15 @@ BASE = "https://api.launchpad.net/devel"
def fetch_paginated(initial): def fetch_paginated(initial):
"""Fetch paginated data""" """Fetch paginated data"""
next_url = initial next_url = initial
while True: retry_count = 0
data = requests.get(next_url).json() 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"]: for entry in data["entries"]:
yield entry yield entry
...@@ -33,6 +40,9 @@ def fetch_paginated(initial): ...@@ -33,6 +40,9 @@ def fetch_paginated(initial):
break break
next_url = data["next_collection_link"] next_url = data["next_collection_link"]
if retry_count:
raise RuntimeError("Failed to contact launchpad!")
def get_cdimage_mirrors(distro, country): def get_cdimage_mirrors(distro, country):
"""Get a list of cdimage mirrors""" """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