diff --git a/saturn/__init__.py b/saturn/__init__.py new file mode 100644 index 0000000..b4137ff --- /dev/null +++ b/saturn/__init__.py @@ -0,0 +1,37 @@ +import argparse +import configparser +import logging +import locale + +from pathlib import Path + +from datetime import date +import caldav + +from .server import create_app +from .calendar import get_davclient + + +parser = argparse.ArgumentParser(description='Web-based CalDav client') +parser.add_argument('-c', '--config', type=Path, default='config.ini', + help='Configuration file path') + +args = parser.parse_args() + +config = configparser.ConfigParser() +config.read(args.config) + +locale.setlocale(locale.LC_ALL, config.get('locale', 'locale', fallback=None)) + +logging.basicConfig(level=config.get('logging', 'level', fallback='WARN')) +log = logging.getLogger('saturn') + +log.info('Starting saturn') + + +davclient = get_davclient(config['caldav']) +app = create_app( + bytes(config.get('server', 'secret_key'), 'utf-8'), + config.get('server', 'password'), + davclient, +) diff --git a/saturn/__main__.py b/saturn/__main__.py index fa1cc65..ea42a9f 100644 --- a/saturn/__main__.py +++ b/saturn/__main__.py @@ -1,47 +1,4 @@ -import argparse -import configparser -import logging -import locale -## dev imports -from pprint import pp -import sys - -from pathlib import Path - -from datetime import date -import caldav - -from .server import create_app -from .calendar import get_davclient - - -parser = argparse.ArgumentParser(description='Web-based CalDav client') -parser.add_argument('-c', '--config', type=Path, default='config.ini', - help='Configuration file path') - -args = parser.parse_args() - -config = configparser.ConfigParser() -config.read(args.config) - -locale.setlocale(locale.LC_ALL, config.get('locale', 'locale', fallback=None)) - -logging.basicConfig(level=config.get('logging', 'level', fallback='WARN')) -log = logging.getLogger('saturn') - -log.info('Starting saturn') - - -davclient = get_davclient(config['caldav']) -app = create_app( - bytes(config.get('server', 'secret_key'), 'utf-8'), - config.get('server', 'password'), - davclient, -) +from . import app if __name__ == '__main__': - app.run( - host=config.get('server', 'host', fallback=None), - port=config.get('server', 'port', fallback=None), - debug=config.get('server', 'debug', fallback=None), - ) + app.run()