def process_msg(self, msg, hw_addr_recieved, device_id_recieved): ''' - checks recieved key - sends respose to device when and if needed (in handler) - writes decision to log ''' try: if (self._is_busy): log.logger().info(self._info + ' REFUSED a request from ({0}, {1}) ; it is busy'.format(hw_addr_recieved, device_id_recieved)) return self._is_busy = True log.logger().debug(self._info + ': procesing msg from ({0}, {1})'.format(hw_addr_recieved, device_id_recieved)) key = lprotocols.in_lvl3_32ints.unpack(msg)[0] decision_str = 'deny' hw_addr_sending = hw_addr_recieved device_id_sending = None if (device_id_recieved == self.__parameters['devices']['out']['reader']): direction = '_out' device_id_sending = self.__parameters['devices']['out']['lock'] elif (device_id_recieved == self.__parameters['devices']['in']['reader']): direction = '_in' device_id_sending = self.__parameters['devices']['in']['lock'] else: raise Exception('unknown device_id') #TODO: make logger thread: connect it on creation, save log through it db.initialize() #connect this thread to db helper_name, handler_args = self._AccessPoint__check_access(key, self.__parameters['id']) # key sending is a kostyil - create new, but bounded thread: decision_str = self.script_helpers[helper_name](key, hw_addr_sending, device_id_sending, handler_args) self._is_busy = False except Exception as exc: log.logger().error(self._info + ': error while processing msg from ({0}, {1}): '\ .format(hw_addr_recieved, device_id_recieved) + '\n\t' + traceback.format_exc())
from shared import log, config, database from server.synchronizer import Synchronizer from shared.network import * import shared.man_db_msg_pb2 as proto default_log_conf_path = os.path.dirname(os.path.abspath(__file__)) + '/../config/server_logging.conf' default_conf_path = os.path.dirname(os.path.abspath(__file__)) + '/../config/server_config.yml' log.initialize(default_log_conf_path) config.initialize(default_conf_path) db_connection_string = 'mysql://' + config.config()['database']['user'] + ':' + config.config()['database']['password'] + '@' + config.config()['database']['host'] + '/' + config.config()['database']['db'] db_debug_mode = config.config()['database']['debug'] database.initialize(db_connection_string, db_debug_mode) def log_handler(msg): try: log.logger().info('Got log, synchronizing...') with database.manager().transaction(): database.manager().load_log(msg.db) log.logger().info('Log successfully synchronized.') except Exception as exc: log.logger().error(repr(exc)) class Server(): def __init__(self):