Commit 9b97b19a authored by Pietro Albini's avatar Pietro Albini

Switch to using a generic data directory for caching

parent 50efd1cf
......@@ -136,17 +136,12 @@ Per eseguire il sito in locale, è possibile eseguire questo comando (una volta
dentro il virtualenv o con il sito installato globalmente):
```
uitwww run -d -p 8000
uitwww run -d -p 8000 data/
```
Esso avvierà un'istanza in debug-mode (*da non eseguire in produzione!!!*), che
ascolta su [localhost:8000][localhost]. Se si vuole attivare anche la cache
statica, bisogna aggiungere come argomento il path della directory che la dovrà
contenere:
```
uitwww run -d -p 8000 path/to/cache
```
ascolta su [localhost:8000][localhost], usando `data/` come directory in cui
salvare i file necessari al suo funzionamento.
## Generazione di una build
......
# Source code of the Ubuntu-it website
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
# Copyright (C) 2015-2016 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
......@@ -14,21 +14,43 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import flask
from uitwww import pages
from . import pages
from . import cache
def create_app(cache_path=None):
def create_app(data_path):
"""Create a new instance of the application"""
app = flask.Flask(__name__, static_url_path="/+assets")
app.config["DATA_PATH"] = data_path
# Apply the static cache thing
if cache_path is not None:
app.config["CACHE_PATH"] = cache_path
cache.install_cache(app)
app.config["CACHE_PATH"] = os.path.join(data_path, "cache")
cache.install_cache(app)
app.register_blueprint(pages.prepare_blueprint(app))
pages.prepare_navbar(app)
return app
def init_data_directory(data_path):
"""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)
# Initialize the cache
static_dirs = {"static": "+assets"}
for src, dest in static_dirs.items():
dest = os.path.join(data_path, "cache", dest)
# Create the correct symlink
if os.path.exists(dest):
os.remove(dest)
os.symlink(os.path.join(src_directory, src), dest)
# Source code of the Ubuntu-it website
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
# Copyright (C) 2015-2016 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
......@@ -29,34 +29,21 @@ def cli():
@cli.command("run")
@click.argument("cache", required=False, default=None)
@click.argument("data")
@click.option("-g", "--gunicorn-config", default=None, help="Path to a"
"gunicorn config file")
@click.option("-p", "--port", default=8000, help="Bind that port")
@click.option("--public", help="Make available to the public", is_flag=True)
@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(cache, gunicorn_config, port, public, workers, debug):
def run(data, gunicorn_config, port, public, workers, debug):
# Create the application instance
app = uitwww.create_app(cache)
app.wsgi_app = utils.ReverseProxied(app.wsgi_app)
src_directory = os.path.dirname(os.path.abspath(__file__))
# Link static assets to the cache directory, if it's enabled
static_dirs = {"static": "+assets"}
if cache is not None:
if not os.path.exists(cache):
os.makedirs(cache)
for src, dest in static_dirs.items():
dest = os.path.join(cache, dest)
# The destinationa already exists
if os.path.exists(dest):
continue
os.symlink(os.path.join(src_directory, src), dest)
uitwww.init_data_directory(data)
app = uitwww.create_app(data)
app.wsgi_app = utils.ReverseProxied(app.wsgi_app)
host = "127.0.0.1"
if public:
......
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