Burathar
4 years ago
11 changed files with 96 additions and 47 deletions
@ -1,23 +1,48 @@
@@ -1,23 +1,48 @@
|
||||
from os import environ |
||||
from os import path, mkdir |
||||
import logging |
||||
from logging.handlers import RotatingFileHandler |
||||
from pathlib import Path |
||||
import confuse |
||||
|
||||
from flask import Flask |
||||
from flask_bootstrap import Bootstrap |
||||
|
||||
app = Flask(__name__) |
||||
Bootstrap(app) |
||||
|
||||
|
||||
def read_config(): |
||||
conf = confuse.Configuration('biscd', __name__) |
||||
try: |
||||
conf['config'].get() |
||||
except confuse.NotFoundError: |
||||
raise ValueError("Failed to open any configfile containing a 'config' object. " \ |
||||
conf['logging'].get() |
||||
except confuse.NotFoundError as not_found: |
||||
raise ValueError("Failed to open any configfile containing a 'logging' object. " \ |
||||
"Please make sure the module directory contains a config_default.yaml, " \ |
||||
f"or /etc/{__name__}/config.yaml exists") |
||||
f"or /etc/{__name__}/config.yaml exists") from not_found |
||||
return conf |
||||
|
||||
return conf['config'] |
||||
def setup_logging(): |
||||
# pylint: disable=no-member |
||||
if config['logging']['log_to_sdout'].get(bool): |
||||
stream_handler = logging.StreamHandler() |
||||
stream_handler.setLevel(logging.INFO) |
||||
app.logger.addHandler(stream_handler) |
||||
else: |
||||
logfile = Path(config['logging']['logfile'].as_filename()) |
||||
if not logfile.parent.exists(): |
||||
logfile.parent.mkdir(mode=0o770, parents=True) |
||||
file_handler = RotatingFileHandler(str(logfile), maxBytes=10240, backupCount=10) |
||||
file_handler.setFormatter(logging.Formatter( |
||||
'%(asctime)s %(levelname)s: %(message)s ' |
||||
'[in %(pathname)s:%(lineno)d]')) |
||||
file_handler.setLevel(logging.INFO) |
||||
app.logger.addHandler(file_handler) |
||||
|
||||
app.logger.setLevel(logging.INFO) |
||||
app.logger.info('Biscd startup') |
||||
|
||||
app = Flask(__name__) |
||||
config = read_config() |
||||
bootstrap = Bootstrap(app) |
||||
|
||||
setup_logging() |
||||
|
||||
from biscd import routes, errors |
||||
from biscd import routes, errors, models |
||||
|
@ -1,13 +1,12 @@
@@ -1,13 +1,12 @@
|
||||
confiag: |
||||
flask_development_server: |
||||
# Options: production, development |
||||
flask_env: development |
||||
# Options: 127.0.0.1 , 0.0.0.0 |
||||
server_host: 0.0.0.0 |
||||
port: 5000 |
||||
flask_development_server: |
||||
# Options: production, development |
||||
flask_env: development |
||||
# Options: 127.0.0.1 , 0.0.0.0 |
||||
server_host: 0.0.0.0 |
||||
port: 5000 |
||||
|
||||
logging: |
||||
infofile: info.log |
||||
errorfile: error.log |
||||
logging: |
||||
log_to_sdout: true |
||||
logfile: info.log |
||||
|
||||
message: Hoi |
||||
message: Hoi |
@ -1,8 +1,9 @@
@@ -1,8 +1,9 @@
|
||||
from flask import render_template, abort |
||||
from biscd import app, config, utils |
||||
from flask import render_template |
||||
from biscd import app |
||||
from biscd.models.project import Project |
||||
|
||||
@app.route('/', methods=['GET']) |
||||
@app.route('/index', methods=['GET']) |
||||
def index(): |
||||
return render_template('index.html', message=config['message'].get()) |
||||
|
||||
project_names = Project.list() |
||||
return render_template('index.html', projects=project_names) |
||||
|
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
from datetime import datetime |
||||
|
||||
from flask import request |
||||
|
||||
def get_timestamp(): |
||||
return datetime.now().astimezone().isoformat(timespec='milliseconds') |
||||
|
||||
def get_remote_addr(): |
||||
#print(f"HTTP_X_REAL_IP: {request.environ.get('HTTP_X_REAL_IP')}") |
||||
#print(f"HTTP_X_FORWARDED_FOR: {request.environ.get('HTTP_X_FORWARDED_FOR')}") |
||||
return request.environ.get('HTTP_X_FORWARDED_FOR', request.remote_addr) |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
flask_development_server: |
||||
# Options: production, development |
||||
flask_env: production |
||||
# Options: 127.0.0.1 , 0.0.0.0 |
||||
server_host: 127.0.0.1 |
||||
port: 5000 |
||||
|
||||
logging: |
||||
log_to_sdout: true |
||||
logfile: info.log |
||||
|
||||
message: Hoi |
@ -1,13 +0,0 @@
@@ -1,13 +0,0 @@
|
||||
config: |
||||
flask_development_server: |
||||
# Options: production, development |
||||
flask_env: production |
||||
# Options: 127.0.0.1 , 0.0.0.0 |
||||
server_host: 127.0.0.1 |
||||
port: 5000 |
||||
|
||||
logging: |
||||
infofile: info.log |
||||
errorfile: error.log |
||||
|
||||
message: Hoi |
Loading…
Reference in new issue