Commit a0ca4d6d authored by Robin Sonnabend's avatar Robin Sonnabend

Parse, check and generate the configuration

The configuration is defined in configproxy.py. Add new keys there.
Use ./configproxy.py check to check the config validity.
    ./configproxy.py create to create an example config.
parent 4d789866
...@@ -5,7 +5,7 @@ import quopri ...@@ -5,7 +5,7 @@ import quopri
from caldav import DAVClient from caldav import DAVClient
from vobject.base import ContentLine from vobject.base import ContentLine
import config from shared import config
class CalendarException(Exception): class CalendarException(Exception):
......
Subproject commit 4c0c16f069bb39d593b53eae0c2b92b1f05eba90 Subproject commit 2a0f881728f1000f27fb00321bc37fb869007fa9
This diff is collapsed.
This diff is collapsed.
...@@ -4,7 +4,7 @@ from fuzzywuzzy import process ...@@ -4,7 +4,7 @@ from fuzzywuzzy import process
from models.database import OldTodo, Protocol, ProtocolType, TodoMail from models.database import OldTodo, Protocol, ProtocolType, TodoMail
from shared import db from shared import db
import config from shared import config
def lookup_todo_id(old_candidates, new_who, new_description): def lookup_todo_id(old_candidates, new_who, new_description):
......
...@@ -7,7 +7,7 @@ from uuid import uuid4 ...@@ -7,7 +7,7 @@ from uuid import uuid4
from shared import ( from shared import (
db, date_filter_short, escape_tex, DATE_KEY, START_TIME_KEY, END_TIME_KEY, db, date_filter_short, escape_tex, DATE_KEY, START_TIME_KEY, END_TIME_KEY,
current_user) current_user, config)
from utils import get_etherpad_url, split_terms, check_ip_in_networks from utils import get_etherpad_url, split_terms, check_ip_in_networks
from models.errors import DateNotMatchingException from models.errors import DateNotMatchingException
from dateutil import tz from dateutil import tz
...@@ -17,7 +17,6 @@ import os ...@@ -17,7 +17,6 @@ import os
from sqlalchemy import event from sqlalchemy import event
from sqlalchemy.orm import relationship, backref from sqlalchemy.orm import relationship, backref
import config
from todostates import make_states from todostates import make_states
......
...@@ -6,7 +6,7 @@ from enum import Enum ...@@ -6,7 +6,7 @@ from enum import Enum
from shared import escape_tex from shared import escape_tex
from utils import footnote_hash from utils import footnote_hash
import config from shared import config
INDENT_LETTER = "-" INDENT_LETTER = "-"
......
...@@ -21,7 +21,6 @@ flake8==3.5.0 ...@@ -21,7 +21,6 @@ flake8==3.5.0
Flask==0.12.2 Flask==0.12.2
Flask-Migrate==2.1.1 Flask-Migrate==2.1.1
Flask-Script==2.0.6 Flask-Script==2.0.6
Flask-SocketIO==2.9.3
Flask-SQLAlchemy==2.3.2 Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2 Flask-WTF==0.14.2
fuzzywuzzy==0.16.0 fuzzywuzzy==0.16.0
...@@ -60,6 +59,7 @@ regex==2018.2.8 ...@@ -60,6 +59,7 @@ regex==2018.2.8
requests==2.18.4 requests==2.18.4
six==1.11.0 six==1.11.0
SQLAlchemy==1.2.3 SQLAlchemy==1.2.3
SQLAlchemy-Utils==0.33.2
typing==3.6.4 typing==3.6.4
tzlocal==1.5.1 tzlocal==1.5.1
urllib3==1.22 urllib3==1.22
......
...@@ -21,9 +21,8 @@ from datetime import datetime, timedelta ...@@ -21,9 +21,8 @@ from datetime import datetime, timedelta
import math import math
import mimetypes import mimetypes
import config
from shared import ( from shared import (
db, date_filter, datetime_filter, date_filter_long, config, db, date_filter, datetime_filter, date_filter_long,
date_filter_short, time_filter, time_filter_short, user_manager, date_filter_short, time_filter, time_filter_short, user_manager,
security_manager, current_user, check_login, login_required, security_manager, current_user, check_login, login_required,
class_filter, needs_date_test, todostate_name_filter, class_filter, needs_date_test, todostate_name_filter,
...@@ -180,6 +179,19 @@ def merge_duplicate_todos(): ...@@ -180,6 +179,19 @@ def merge_duplicate_todos():
todo_by_id[todo_id] = todo todo_by_id[todo_id] = todo
@manager.command
def check_config():
# TODO: check how to set return codes
import configproxy
return configproxy.check_config()
@manager.command
def create_example_config(filename):
import configproxy
return configproxy.write_example_config(filename=filename)
@manager.command @manager.command
def runserver(): def runserver():
app.run() app.run()
......
...@@ -7,7 +7,12 @@ from enum import Enum ...@@ -7,7 +7,12 @@ from enum import Enum
from common import back from common import back
import config try:
import configproxy
config, public_config = configproxy.import_config()
except ImportError as error:
print(error)
raise
db = SQLAlchemy() db = SQLAlchemy()
......
...@@ -16,7 +16,7 @@ from models.errors import DateNotMatchingException ...@@ -16,7 +16,7 @@ from models.errors import DateNotMatchingException
from server import celery, app from server import celery, app
from shared import ( from shared import (
db, escape_tex, unhyphen, date_filter, datetime_filter, date_filter_long, db, escape_tex, unhyphen, date_filter, datetime_filter, date_filter_long,
date_filter_short, time_filter, class_filter, KNOWN_KEYS, WikiType) date_filter_short, time_filter, class_filter, KNOWN_KEYS, WikiType, config)
from utils import ( from utils import (
mail_manager, add_line_numbers, mail_manager, add_line_numbers,
set_etherpad_text, parse_datetime_from_string) set_etherpad_text, parse_datetime_from_string)
...@@ -25,8 +25,6 @@ from wiki import WikiClient, WikiException ...@@ -25,8 +25,6 @@ from wiki import WikiClient, WikiException
from calendarpush import Client as CalendarClient, CalendarException from calendarpush import Client as CalendarClient, CalendarException
from legacy import lookup_todo_id from legacy import lookup_todo_id
import config
texenv = app.create_jinja_environment() texenv = app.create_jinja_environment()
texenv.block_start_string = r"\ENV{" texenv.block_start_string = r"\ENV{"
texenv.block_end_string = r"}" texenv.block_end_string = r"}"
......
...@@ -14,8 +14,9 @@ import ipaddress ...@@ -14,8 +14,9 @@ import ipaddress
from socket import getfqdn from socket import getfqdn
from uuid import uuid4 from uuid import uuid4
import subprocess import subprocess
import contextlib
import config from shared import config
def random_string(length): def random_string(length):
...@@ -64,6 +65,20 @@ class MailManager: ...@@ -64,6 +65,20 @@ class MailManager:
return smtplib.SMTP_SSL return smtplib.SMTP_SSL
return smtplib.SMTP return smtplib.SMTP
def connect(self):
server = self._get_smtp()(self.hostname)
if self.use_starttls:
server.starttls()
if self.username not in [None, ""] and self.password not in [None, ""]:
server.login(self.username, self.password)
return server
@contextlib.contextmanager
def session(self):
server = self.connect()
yield server
server.quit()
def send(self, to_addr, subject, content, appendix=None, reply_to=None): def send(self, to_addr, subject, content, appendix=None, reply_to=None):
if (not self.active if (not self.active
or not self.hostname or not self.hostname
...@@ -83,13 +98,20 @@ class MailManager: ...@@ -83,13 +98,20 @@ class MailManager:
part["Content-Disposition"] = ( part["Content-Disposition"] = (
'attachment; filename="{}"'.format(name)) 'attachment; filename="{}"'.format(name))
msg.attach(part) msg.attach(part)
server = self._get_smtp()(self.hostname) with self.session() as server:
if self.use_starttls: server.sendmail(
server.starttls() self.from_addr,
if self.username not in [None, ""] and self.password not in [None, ""]: to_addr.split(","),
server.login(self.username, self.password) msg.as_string())
server.sendmail(self.from_addr, to_addr.split(","), msg.as_string())
server.quit() def check(self):
if not self.active:
return True
if not self.hostname or not self.from_addr:
return False
with self.session():
pass
return True
mail_manager = MailManager(config) mail_manager = MailManager(config)
...@@ -128,7 +150,6 @@ def get_etherpad_text(pad): ...@@ -128,7 +150,6 @@ def get_etherpad_text(pad):
def set_etherpad_text(pad, text, only_if_default=True): def set_etherpad_text(pad, text, only_if_default=True):
print(pad)
if only_if_default: if only_if_default:
current_text = get_etherpad_text(pad) current_text = get_etherpad_text(pad)
if (current_text != config.EMPTY_ETHERPAD if (current_text != config.EMPTY_ETHERPAD
...@@ -137,7 +158,6 @@ def set_etherpad_text(pad, text, only_if_default=True): ...@@ -137,7 +158,6 @@ def set_etherpad_text(pad, text, only_if_default=True):
file_like = BytesIO(text.encode("utf-8")) file_like = BytesIO(text.encode("utf-8"))
files = {"file": file_like} files = {"file": file_like}
url = get_etherpad_import_url(pad) url = get_etherpad_import_url(pad)
print(url)
req = requests.post(url, files=files) req = requests.post(url, files=files)
return req.status_code == 200 return req.status_code == 200
......
...@@ -11,7 +11,7 @@ from models.database import TodoState ...@@ -11,7 +11,7 @@ from models.database import TodoState
from validators import CheckTodoDateByState from validators import CheckTodoDateByState
from shared import current_user from shared import current_user
import config from shared import config
def get_protocoltype_choices(protocoltypes, add_all=True): def get_protocoltype_choices(protocoltypes, add_all=True):
......
...@@ -2,7 +2,7 @@ from flask import Markup, url_for ...@@ -2,7 +2,7 @@ from flask import Markup, url_for
from shared import date_filter, datetime_filter, time_filter, current_user from shared import date_filter, datetime_filter, time_filter, current_user
from common.csrf import get_csrf_token from common.csrf import get_csrf_token
import config from shared import config
class Table: class Table:
......
import requests import requests
from json import JSONDecodeError from json import JSONDecodeError
import config from shared import config
HTTP_STATUS_OK = 200 HTTP_STATUS_OK = 200
HTTP_STATUS_AUTHENTICATE = 401 HTTP_STATUS_AUTHENTICATE = 401
......
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