示例#1
0
文件: cli.py 项目: DanElbert/tilty
def run(
    keep_running: bool,
    config_file: str = 'config.ini',
):
    """
    main cli entrypoint

    Args:
        keep_running (bool): Whether or not to keep running. Default: False
        config_file (str): The configuration file location to load.
    """
    file = pathlib.Path(config_file)
    if not file.exists():
        raise ConfigurationFileNotFoundException()

    CONFIG.read(config_file)

    logging_level = 'INFO'
    try:
        logging_level = CONFIG['general'].get('logging_level', 'INFO')
    except KeyError:
        pass
    LOGGER.setLevel(logging.getLevelName(logging_level))

    device = tilt_device.TiltDevice()
    signal.signal(signal.SIGINT, partial(terminate_process, device))
    device.start()
    threading.Thread(
        target=scan_and_emit_thread,
        name='tilty_daemon',
        args=(device, CONFIG, keep_running)
    ).start()
    if keep_running:
        while True:
            pass
示例#2
0
文件: cli.py 项目: nalabelle/tilty
def run(
    keep_running: bool,
    config_file: str = 'config.ini',
):
    """
    main cli entrypoint

    Args:
        keep_running (bool): Whether or not to keep running. Default: False
        config_file (str): The configuration file location to load.
    """
    file = pathlib.Path(config_file)
    if not file.exists():
        raise ConfigurationFileNotFoundException()

    CONFIG.read(config_file)

    handler = logging.StreamHandler(sys.stdout)
    logging_level = 'INFO'
    try:
        logging_level = CONFIG['general'].get('logging_level', 'INFO')
        logfile = CONFIG['general'].get('logfile', None)
        if logfile:
            handler = logging.FileHandler(filename=logfile)
    except KeyError:
        pass
    LOGGER.setLevel(logging.getLevelName(logging_level))
    handler.setLevel(logging_level)
    LOGGER.addHandler(handler)

    keep_running_flag = threading.Event()
    if keep_running:
        keep_running_flag.set()

    device = tilt_device.TiltDevice()
    signal.signal(signal.SIGINT,
                  partial(terminate_process, device, keep_running_flag))
    device.start()
    main_thread = threading.Thread(target=scan_and_emit_thread,
                                   name='tilty_daemon',
                                   args=(device, CONFIG, keep_running_flag))
    main_thread.start()
    main_thread.join()