Example #1
0
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)
Example #2
0
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)
Example #3
0
    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)
Example #4
0
 def get_device_id(self) -> str:
     """
     Get the configured ``device_id``.
     """
     return Config.get('device_id')
Example #5
0
 def get_dashboard(self, name: str) -> str:
     """
     Get a dashboard configuration by name.
     """
     return Config.get_dashboard(name)
Example #6
0
 def dashboards(self) -> dict:
     """
     Get the configured dashboards.
     """
     return Config.get_dashboards()
Example #7
0
 def get_procedures(self) -> dict:
     """
     Get the configured procedures.
     """
     return json.loads(
         json.dumps(Config.get_procedures(), cls=Message.Encoder))
Example #8
0
 def get_backends(self) -> dict:
     """
     Get the configured backends.
     """
     return Config.get_backends()
Example #9
0
 def get_plugins(self) -> dict:
     """
     Get the configured plugins.
     """
     return Config.get_plugins()
Example #10
0
 def get(self) -> dict:
     """
     Get the current configuration.
     """
     return Config.get()
Example #11
0
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)
Example #12
0
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
Example #13
0
def db_file():
    yield Config.get('main.db')['engine'][len('sqlite:///'):]