コード例 #1
0
ファイル: generator.py プロジェクト: hat-open/hat-core
def main(host: str,
         port: int,
         count: int,
         text: str,
         queue_size: int,
         msg_delay: float,
         end_delay: float):
    """Syslog test message generator"""
    aio.init_asyncio()

    logging.config.dictConfig({
        'version': 1,
        'formatters': {
            'default': {}},
        'handlers': {
            'syslog': {
                'class': 'hat.syslog.handler.SysLogHandler',
                'host': host,
                'port': port,
                'comm_type': 'TCP',
                'level': 'DEBUG',
                'formatter': 'default',
                'queue_size': queue_size}},
        'root': {
            'level': 'INFO',
            'handlers': ['syslog']},
        'disable_existing_loggers': False})

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(count, text, msg_delay, end_delay))
コード例 #2
0
ファイル: qt.py プロジェクト: hat-open/hat-core
def _run_async_thread(app, executor, async_main, args, kwargs):
    aio.init_asyncio()
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    try:
        qt_executor = functools.partial(loop.run_in_executor, executor)
        loop.run_until_complete(async_main(qt_executor, *args, **kwargs))
    finally:
        executor.submit(app.exit)
コード例 #3
0
ファイル: main.py プロジェクト: hat-open/hat-core
def main(conf: typing.Optional[Path], ui_path: Path):
    """Orchestrator"""
    aio.init_asyncio()

    if not conf:
        for suffix in ('.yaml', '.yml', '.json'):
            conf = (user_conf_dir / 'orchestrator').with_suffix(suffix)
            if conf.exists():
                break
    conf = json.decode_file(conf)
    json_schema_repo.validate('hat://orchestrator.yaml#', conf)

    logging.config.dictConfig(conf['log'])

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(conf, ui_path))
コード例 #4
0
def main(conf: typing.Optional[Path], ui_path: Path):
    """Main entry point"""
    aio.init_asyncio()

    conf, conf_path = None, conf
    if not conf_path:
        for suffix in ('.yaml', '.yml', '.json'):
            conf_path = (user_conf_dir / 'manager').with_suffix(suffix)
            if conf_path.exists():
                break
    if conf_path.exists():
        conf = json.decode_file(conf_path)
    else:
        conf = common.default_conf
    common.json_schema_repo.validate('hat://manager/main.yaml#', conf)

    logging.config.dictConfig(conf['log'])

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(conf, conf_path, ui_path))
コード例 #5
0
ファイル: main.py プロジェクト: hat-open/hat-core
def main(conf: typing.Optional[Path]):
    """Gateway"""
    aio.init_asyncio()

    if not conf:
        for suffix in ('.yaml', '.yml', '.json'):
            conf = (user_conf_dir / 'gateway').with_suffix(suffix)
            if conf.exists():
                break
    conf = json.decode_file(conf)
    common.json_schema_repo.validate('hat://gateway/main.yaml#', conf)

    for device_conf in conf['devices']:
        module = importlib.import_module(device_conf['module'])
        if module.json_schema_repo and module.json_schema_id:
            module.json_schema_repo.validate(module.json_schema_id,
                                             device_conf)

    logging.config.dictConfig(conf['log'])

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(conf))
コード例 #6
0
def main(conf: typing.Optional[Path]):
    """Event Server"""
    aio.init_asyncio()

    if not conf:
        for suffix in ('.yaml', '.yml', '.json'):
            conf = (user_conf_dir / 'event').with_suffix(suffix)
            if conf.exists():
                break
    conf = json.decode_file(conf)
    common.json_schema_repo.validate('hat://event/main.yaml#', conf)

    sub_confs = ([conf['backend_engine']['backend']] +
                 conf['module_engine']['modules'])
    for sub_conf in sub_confs:
        module = importlib.import_module(sub_conf['module'])
        if module.json_schema_repo and module.json_schema_id:
            module.json_schema_repo.validate(module.json_schema_id, sub_conf)

    logging.config.dictConfig(conf['log'])

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(conf))
コード例 #7
0
ファイル: main.py プロジェクト: hat-open/hat-core
def main(conf: typing.Optional[Path],
         ui_path: Path):
    """GUI Server"""
    aio.init_asyncio()

    if not conf:
        for suffix in ('.yaml', '.yml', '.json'):
            conf = (user_conf_dir / 'gui').with_suffix(suffix)
            if conf.exists():
                break
    conf = json.decode_file(conf)
    hat.gui.common.json_schema_repo.validate('hat://gui/main.yaml#', conf)

    for adapter_conf in conf['adapters']:
        module = importlib.import_module(adapter_conf['module'])
        if module.json_schema_repo and module.json_schema_id:
            module.json_schema_repo.validate(module.json_schema_id,
                                             adapter_conf)

    logging.config.dictConfig(conf['log'])

    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main(conf, ui_path))
コード例 #8
0
ファイル: main.py プロジェクト: hat-open/hat-core
def main(conf: typing.Optional[Path], log: typing.Optional[str],
         syslog_addr: typing.Optional[str], syslog_pem: typing.Optional[Path],
         ui_addr: typing.Optional[str], ui_pem: typing.Optional[Path],
         ui_path: Path, db_path: typing.Optional[Path],
         db_low_size: typing.Optional[int], db_high_size: typing.Optional[int],
         db_enable_archive: bool, db_disable_journal: bool):
    """Syslog Server"""
    aio.init_asyncio()

    if not conf:
        for suffix in ('.yaml', '.yml', '.json'):
            conf = (user_conf_dir / 'syslog').with_suffix(suffix)
            if conf.exists():
                break
        else:
            conf = None
    if conf:
        conf = json.decode_file(conf)
        common.json_schema_repo.validate('hat://syslog.yaml#', conf)

    if log:
        log_conf = _get_console_log_conf(log)
    elif conf:
        log_conf = conf['log']
    else:
        log_conf = {'version': 1}

    if not syslog_addr:
        syslog_addr = conf['syslog_addr'] if conf else default_syslog_addr

    if not syslog_pem and conf and 'syslog_pem' in conf:
        syslog_pem = Path(conf['syslog_pem'])

    if not ui_addr:
        ui_addr = conf['ui_addr'] if conf else default_ui_addr

    if not ui_pem and conf and 'ui_pem' in conf:
        ui_pem = Path(conf['ui_pem'])

    if not db_path:
        db_path = Path(conf['db_path']) if conf else default_db_path

    if db_low_size is None:
        db_low_size = conf['db_low_size'] if conf else default_db_low_size

    if db_high_size is None:
        db_high_size = conf['db_high_size'] if conf else default_db_high_size

    if not db_enable_archive and conf:
        db_enable_archive = conf['db_enable_archive']

    if not db_disable_journal and conf:
        db_disable_journal = conf['db_disable_journal']

    logging.config.dictConfig(log_conf)
    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(
            async_main(syslog_addr=syslog_addr,
                       syslog_pem=syslog_pem,
                       ui_addr=ui_addr,
                       ui_pem=ui_pem,
                       ui_path=ui_path,
                       db_path=db_path,
                       db_low_size=db_low_size,
                       db_high_size=db_high_size,
                       db_enable_archive=db_enable_archive,
                       db_disable_journal=db_disable_journal))
コード例 #9
0
def pytest_configure(config):
    aio.init_asyncio()
コード例 #10
0
def main():
    aio.init_asyncio()
    with contextlib.suppress(asyncio.CancelledError):
        aio.run_asyncio(async_main())