Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
Nuovo sito
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gruppo Web
Nuovo sito
Commits
9b97b19a
Commit
9b97b19a
authored
Oct 25, 2016
by
Pietro Albini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch to using a generic data directory for caching
parent
50efd1cf
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
34 deletions
+38
-34
CONTRIBUTING.md
CONTRIBUTING.md
+3
-8
uitwww/__init__.py
uitwww/__init__.py
+29
-7
uitwww/__main__.py
uitwww/__main__.py
+6
-19
No files found.
CONTRIBUTING.md
View file @
9b97b19a
...
...
@@ -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
...
...
uitwww/__init__.py
View file @
9b97b19a
# 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
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
)
uitwww/__main__.py
View file @
9b97b19a
# 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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment