def initialize_logger(): logger = logging.getLogger('werkzeug') try: log_conf = Config.get('logging') if 'level' in log_conf: logger.setLevel(log_conf['level']) except Exception as e: logger.warning('Could not read logging level') logger.exception(e)
def app(): logging.info('Starting Platypush test service') Config.init(config_file) app = Daemon(config_file=config_file, redis_queue='platypush-tests/bus') Thread(target=lambda: app.run()).start() logging.info( 'Sleeping {} seconds while waiting for the daemon to start up'.format( app_start_timeout)) time.sleep(app_start_timeout) yield app logging.info('Stopping Platypush test service') app.stop_app() clear_loggers() db_file = (Config.get('main.db') or {}).get('engine', '')[len('sqlite:///'):] if db_file and os.path.isfile(db_file): logging.info('Removing temporary db file {}'.format(db_file)) os.unlink(db_file)
def _get_camera(self, camera_plugin: Optional[str] = None, **config) -> CameraPlugin: camera_plugin = camera_plugin or self.camera_plugin if not config: config = Config.get(camera_plugin) or {} config['stream_raw_frames'] = True cls = get_plugin_class_by_name(camera_plugin) assert cls and issubclass( cls, CameraPlugin), '{} is not a valid camera plugin'.format( camera_plugin) return cls(**config)
def get_device_id(self) -> str: """ Get the configured ``device_id``. """ return Config.get('device_id')
def get_dashboard(self, name: str) -> str: """ Get a dashboard configuration by name. """ return Config.get_dashboard(name)
def dashboards(self) -> dict: """ Get the configured dashboards. """ return Config.get_dashboards()
def get_procedures(self) -> dict: """ Get the configured procedures. """ return json.loads( json.dumps(Config.get_procedures(), cls=Message.Encoder))
def get_backends(self) -> dict: """ Get the configured backends. """ return Config.get_backends()
def get_plugins(self) -> dict: """ Get the configured plugins. """ return Config.get_plugins()
def get(self) -> dict: """ Get the current configuration. """ return Config.get()
def get_camera(device_id=None): device_id = get_device_id(device_id) camera_conf = Config.get('camera') or {} camera_conf['device_id'] = device_id return CameraPlugin(**camera_conf)
def base_url(): backends = Config.get_backends() assert 'http' in backends, 'Missing HTTP server configuration' url = 'http://localhost:{port}'.format(port=backends['http']['port']) set_base_url(url) yield url
def db_file(): yield Config.get('main.db')['engine'][len('sqlite:///'):]