Esempio n. 1
0
def run_forever(args, config):
    # ensure requiresments, raise SystemExit if failed
    os.chdir(os.path.join(os.path.dirname(__file__), '../..'))
    ensure_dirs()

    # In an ideal world, users are capable to do anything in rcfile,
    # including monkeypatch, so we should load rcfile as early as possible
    fuoexec_load_rcfile(config)

    # Extract config items from args and setup config object,
    # since then, no more `args` object, only `config`.
    setup_config(args, config)

    setup_logger(config)

    # create app instance with config
    #
    # nothing should happen except all objects are created
    app = create_app(config)

    # do fuoexec initialization before app inits
    fuoexec_init(app)

    # initialize app with config
    #
    # all objects can do initialization here. some objects may emit signal,
    # some objects may connect with others signals.
    init_app(app)

    app.initialized.emit(app)

    run_app(app)
Esempio n. 2
0
def run_once(args, config):
    # ignore all warnings since it will pollute the output
    warnings.filterwarnings("ignore")

    fuoexec_load_rcfile(config)
    setup_config(args, config)
    app = create_app(config)
    fuoexec_init(app)
    init_app(app)
    app.initialized.emit(app)

    future = oncemain(app, args)
    if future is not None:
        run_app_once(app, future)
Esempio n. 3
0
def before_start_app(args):
    """
    Prepare things that app depends on and initialize things which don't depend on app.
    """
    config = create_config()

    # Load rcfile.
    #
    # In an ideal world, users are capable to do anything in rcfile,
    # including monkeypatch, so we should load rcfile as early as possible
    fuoexec_load_rcfile(config)

    # Initialize config.
    #
    # Extract config items from args and setup config object.
    # Arg has higher priority than config. If a parameter was set both in
    # args and config, the arg can override the value.
    setup_config(args, config)

    # Precheck.
    #
    # When precheck failed, show error hint and exit.
    precheck(args, config)

    # Prepare.
    #
    # Ensure requirements, raise SystemExit if failed.
    ensure_dirs()
    setup_logger(config)
    # Ignore all warnings since it will pollute the output.
    if AppMode.cli in AppMode(config.MODE):
        warnings.filterwarnings("ignore")

    # Run.
    #
    if AppMode.gui in AppMode(config.MODE):
        try:
            # HELP: QtWebEngineWidgets must be imported before a
            #   QCoreApplication instance is created.
            # TODO: add a command line option to control this import.
            import PyQt5.QtWebEngineWidgets  # type: ignore # noqa
        except ImportError:
            logger.info('import QtWebEngineWidgets failed')
        from feeluown.utils.compat import DefaultQEventLoopPolicy
        asyncio.set_event_loop_policy(DefaultQEventLoopPolicy())
    return args, config
Esempio n. 4
0
def main():
    parser = setup_argparse()
    args = parser.parse_args()
    config = create_config()

    # make media assets available
    os.chdir(os.path.join(os.path.dirname(__file__), '..'))
    ensure_dirs()
    fuoexec_load_rcfile(config)

    res = init(args, config)

    if res == 1:
        # load some config before start run_cli
        run_cli(args, config)
    elif res == 2:
        run_once(args, config)
    else:
        run_forever(args, config)