Add config file

This commit is contained in:
augustin64 2022-08-30 18:18:38 +02:00
parent 664266bafd
commit dc4f1f21d3
4 changed files with 26 additions and 6 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@
.vscode .vscode
# data # data
instance/partitioncloud.sqlite instance
partitioncloud/partitions partitioncloud/partitions
partitioncloud/search-partitions partitioncloud/search-partitions
partitioncloud/static/thumbnails partitioncloud/static/thumbnails

9
default_config.py Normal file
View File

@ -0,0 +1,9 @@
# Should be copied to ../instance folder to override some values
# WARNING: Be sure not to leave spaces around `=` because this
# Config file will be used both by Python and Bash
# Generate with `python -c 'import secrets; print(secrets.token_hex())'`
SECRET_KEY="dev"
# Port to run on
PORT="5000"

13
make.sh
View File

@ -16,7 +16,13 @@ init () {
} }
start () { start () {
flask run flask run --port=$PORT
}
production () {
FLASK_APP=partitioncloud /usr/bin/gunicorn \
wsgi:app \
--bind 0.0.0.0:$PORT
} }
@ -27,7 +33,10 @@ usage () {
} }
if [[ $1 && $(type "$1") = *"is a"*"function"* || $(type "$1") == *"est une fonction"* ]]; then if [[ $1 && $(type "$1") = *"is a"*"function"* || $(type "$1") == *"est une fonction"* ]]; then
$1 ${*:2} # Call the function # Import config
source "default_config.py"
[[ ! -x instance/config.py ]] && source "instance/config.py"
$1 ${*:2} # Call the function
else else
usage usage
echo $(type "$1") echo $(type "$1")

View File

@ -14,11 +14,13 @@ from .db import get_db
app = Flask(__name__) app = Flask(__name__)
app.config.from_mapping( app.config.from_mapping(
# a default secret that should be overridden by instance config
SECRET_KEY="dev",
# store the database in the instance folder
DATABASE=os.path.join(app.instance_path, f"{__name__}.sqlite"), DATABASE=os.path.join(app.instance_path, f"{__name__}.sqlite"),
) )
app.config.from_object('default_config')
if os.path.exists("instance/config.py"):
app.config.from_object('instance.config')
else:
print("[WARNING] Using default config")
app.register_blueprint(auth.bp) app.register_blueprint(auth.bp)
app.register_blueprint(albums.bp) app.register_blueprint(albums.bp)