1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-16 03:59:11 +01:00
doorlockd-mirror/doorlockd
Ralf Ramsauer 9828534eae Config: Move SYSCONFDIR and PREFIX to Config
Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
2019-06-15 22:42:01 +02:00

79 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Doorlockd -- Binary Kitchen's smart door opener
Copyright (c) Binary Kitchen e.V., 2018-2019
Author:
Ralf Ramsauer <ralf@binary-kitchen.de>
This work is licensed under the terms of the GNU GPL, version 2. See
the LICENSE file in the top-level directory.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
"""
import logging
import sys
from configparser import ConfigParser
from os.path import abspath, join
from pydoorlock.Authenticator import Authenticator
from pydoorlock.WebApp import webapp_run, emit_doorstate
from pydoorlock.Doorlock import DoorlockResponse, DoorHandler
from pydoorlock.Config import Config, root_prefix, sounds_prefix
__author__ = 'Ralf Ramsauer'
__copyright = 'Copyright (c) Ralf Ramsauer, 2018-2019'
__license__ = 'GPLv2'
__email__ = 'ralf@binary-kitchen.de'
__status__ = 'Development'
__maintainer__ = 'Ralf Ramsauer'
__version__ = '0.0'
log_level = logging.DEBUG
date_fmt = '%Y-%m-%d %H:%M:%S'
log_fmt = '%(asctime)-15s %(levelname)-8s %(message)s'
log = logging.getLogger()
cfg = Config('doorlockd')
class Logic:
def __init__(self, cfg, sounds_prefix, scripts_prefix, callback):
self.auth = Authenticator(cfg)
self.door_handler = DoorHandler(cfg, sounds_prefix, scripts_prefix)
self.door_handler.register_callback(callback)
def request(self, state, credentials):
err = self.auth.try_auth(credentials)
if err != DoorlockResponse.Success:
return err
return self.door_handler.request(state)
@property
def state(self):
return self.door_handler.state
if __name__ == '__main__':
logging.basicConfig(level=log_level, stream=sys.stdout,
format=log_fmt, datefmt=date_fmt)
log.info('Starting doorlockd')
scripts_prefix = join(root_prefix, 'scripts')
logic = Logic(cfg, sounds_prefix, scripts_prefix, emit_doorstate)
static_folder = abspath(join(root_prefix, 'static'))
template_folder = abspath(join(root_prefix, 'templates'))
webapp_run(cfg, logic, __status__, __version__, template_folder,
static_folder)
sys.exit(0)