Commit e1f86183 authored by shadMod's avatar shadMod 💬

added debug param in create_app() to start up without run Downloads().store_cache_file()

Fixes: https://code.ubuntu-it.org/ubuntu-it-web/www/-/issues/15
parent cc762496
Pipeline #293 passed with stage
in 0 seconds
......@@ -29,7 +29,7 @@ from . import redirects
from . import utils
def create_app(data_path):
def create_app(data_path, debug=False):
"""Create a new instance of the application"""
# Normalize the data path
data_path = os.path.expanduser(os.path.abspath(data_path))
......@@ -41,11 +41,11 @@ def create_app(data_path):
)
# Prepare the data directory
init_data_directory(data_path)
init_data_directory(data_path, debug)
# Load the secret key
with open(os.path.join(data_path, "secret_key")) as f:
app.secret_key = f.read().strip()
with open(os.path.join(data_path, "secret_key")) as fn:
app.secret_key = fn.read().strip()
# Initialize the database
app.db = db.Database(os.path.join(data_path, "database.db"))
......@@ -79,14 +79,14 @@ def create_app(data_path):
return app
def init_data_directory(data_path):
def init_data_directory(data_path, debug=False):
"""Initialize the data directory"""
src_directory = os.path.dirname(os.path.abspath(__file__))
# Create all the directories
dirs = ["", "cache"]
for dir in dirs:
os.makedirs(os.path.join(data_path, dir), exist_ok=True)
for name in dirs:
os.makedirs(os.path.join(data_path, name), exist_ok=True)
# Initialize the cache
static_dirs = {"static": "+assets"}
......@@ -105,6 +105,7 @@ def init_data_directory(data_path):
f.write("%s\n" % utils.random_key(64))
os.chmod(secret_key_path, 0o400)
if debug is False:
# Initialize the download files
download_inst = download.Downloads(data_path)
download_inst.store_cache_file()
......@@ -40,7 +40,7 @@ def cli():
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def run(data, gunicorn_config, port, public, workers, debug):
"""Run the application"""
app = uitwww.create_app(data)
app = uitwww.create_app(data, debug)
app.wsgi_app = ReverseProxied(app.wsgi_app)
host = "127.0.0.1"
......@@ -76,11 +76,12 @@ def run(data, gunicorn_config, port, public, workers, debug):
@cli.command("init")
@click.argument("data")
def init(data):
@click.option("-d", "--debug", help="Enable debug mode", is_flag=True)
def init(data, debug):
"""Initialize the data directory"""
print("Initializing data directory:", data)
data_path = os.path.expanduser(os.path.abspath(data))
uitwww.init_data_directory(data_path)
uitwww.init_data_directory(data_path, debug)
@cli.command("build_scss")
......
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