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
from caldav import DAVClient
from vobject.base import ContentLine
import config
from shared import config
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
from models.database import OldTodo, Protocol, ProtocolType, TodoMail
from shared import db
import config
from shared import config
def lookup_todo_id(old_candidates, new_who, new_description):
......
......@@ -7,7 +7,7 @@ from uuid import uuid4
from shared import (
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 models.errors import DateNotMatchingException
from dateutil import tz
......@@ -17,7 +17,6 @@ import os
from sqlalchemy import event
from sqlalchemy.orm import relationship, backref
import config
from todostates import make_states
......
......@@ -6,7 +6,7 @@ from enum import Enum
from shared import escape_tex
from utils import footnote_hash
import config
from shared import config
INDENT_LETTER = "-"
......
......@@ -21,7 +21,6 @@ flake8==3.5.0
Flask==0.12.2
Flask-Migrate==2.1.1
Flask-Script==2.0.6
Flask-SocketIO==2.9.3
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
fuzzywuzzy==0.16.0
......@@ -60,6 +59,7 @@ regex==2018.2.8
requests==2.18.4
six==1.11.0
SQLAlchemy==1.2.3
SQLAlchemy-Utils==0.33.2
typing==3.6.4
tzlocal==1.5.1
urllib3==1.22
......
......@@ -21,9 +21,8 @@ from datetime import datetime, timedelta
import math
import mimetypes
import config
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,
security_manager, current_user, check_login, login_required,
class_filter, needs_date_test, todostate_name_filter,
......@@ -180,6 +179,19 @@ def merge_duplicate_todos():
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
def runserver():
app.run()
......
......@@ -7,7 +7,12 @@ from enum import Enum
from common import back
import config
try:
import configproxy
config, public_config = configproxy.import_config()
except ImportError as error:
print(error)
raise
db = SQLAlchemy()
......
......@@ -16,7 +16,7 @@ from models.errors import DateNotMatchingException
from server import celery, app
from shared import (
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 (
mail_manager, add_line_numbers,
set_etherpad_text, parse_datetime_from_string)
......@@ -25,8 +25,6 @@ from wiki import WikiClient, WikiException
from calendarpush import Client as CalendarClient, CalendarException
from legacy import lookup_todo_id
import config
texenv = app.create_jinja_environment()
texenv.block_start_string = r"\ENV{"
texenv.block_end_string = r"}"
......
......@@ -14,8 +14,9 @@ import ipaddress
from socket import getfqdn
from uuid import uuid4
import subprocess
import contextlib
import config
from shared import config
def random_string(length):
......@@ -64,6 +65,20 @@ class MailManager:
return smtplib.SMTP_SSL
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):
if (not self.active
or not self.hostname
......@@ -83,13 +98,20 @@ class MailManager:
part["Content-Disposition"] = (
'attachment; filename="{}"'.format(name))
msg.attach(part)
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)
server.sendmail(self.from_addr, to_addr.split(","), msg.as_string())
server.quit()
with self.session() as server:
server.sendmail(
self.from_addr,
to_addr.split(","),
msg.as_string())
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)
......@@ -128,7 +150,6 @@ def get_etherpad_text(pad):
def set_etherpad_text(pad, text, only_if_default=True):
print(pad)
if only_if_default:
current_text = get_etherpad_text(pad)
if (current_text != config.EMPTY_ETHERPAD
......@@ -137,7 +158,6 @@ def set_etherpad_text(pad, text, only_if_default=True):
file_like = BytesIO(text.encode("utf-8"))
files = {"file": file_like}
url = get_etherpad_import_url(pad)
print(url)
req = requests.post(url, files=files)
return req.status_code == 200
......
......@@ -11,7 +11,7 @@ from models.database import TodoState
from validators import CheckTodoDateByState
from shared import current_user
import config
from shared import config
def get_protocoltype_choices(protocoltypes, add_all=True):
......
......@@ -2,7 +2,7 @@ from flask import Markup, url_for
from shared import date_filter, datetime_filter, time_filter, current_user
from common.csrf import get_csrf_token
import config
from shared import config
class Table:
......
import requests
from json import JSONDecodeError
import config
from shared import config
HTTP_STATUS_OK = 200
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