コード例 #1
0
ファイル: play.py プロジェクト: DakaraProject/dakara-player
def play(args):
    """Execute the player

    Args:
        args (argparse.Namespace): arguments from command line.
    """
    create_logger()

    # load the config, display help to create config if it fails
    try:
        config = load_config(
            get_config_file(CONFIG_FILE),
            args.debug,
            mandatory_keys=["player", "server"],
        )

    except ConfigNotFoundError as error:
        raise ConfigNotFoundError(
            "{}, please run 'dakara-play create-config'".format(
                error)) from error

    set_loglevel(config)
    dakara = DakaraPlayer(config)

    # load the feeder, consider that the config is incomplete if it fails
    try:
        dakara.load()

    except DakaraError:
        logger.warning("Config may be incomplete, please check '{}'".format(
            get_config_file(CONFIG_FILE)))
        raise

    # run the player
    dakara.run()
コード例 #2
0
    def test_wrap(self, mocked_install, mocked_wrap_stderr):
        """Test to call the method and request to wrap stderr."""
        # call the method
        create_logger(wrap=True)

        # assert the call
        mocked_install.assert_called_with(fmt="my format", level="my level")
        mocked_wrap_stderr.assert_called_with()
コード例 #3
0
    def test_normal(self, mocked_install, mocked_wrap_stderr):
        """Test to call the method normally."""
        # call the method
        create_logger()

        # assert the call
        mocked_install.assert_called_with(fmt="my format", level="my level")
        mocked_wrap_stderr.assert_not_called()
コード例 #4
0
ファイル: play.py プロジェクト: DakaraProject/dakara-player
def create_resources(args):
    """Create resource files

    Args:
        args (argparse.Namespace): arguments from command line.
    """
    create_logger(custom_log_format="%(message)s", custom_log_level="INFO")
    create_resource_files(args.force)
    logger.info("You can now customize those files")
コード例 #5
0
ファイル: play.py プロジェクト: DakaraProject/dakara-player
def create_config(args):
    """Create the config file

    Args:
        args (argparse.Namespace): arguments from command line.
    """
    create_logger(custom_log_format="%(message)s", custom_log_level="INFO")
    create_config_file("dakara_player.resources", CONFIG_FILE, args.force)
    logger.info("Please edit this file")
コード例 #6
0
    def test_custom(self, mocked_install, mocked_wrap_stderr):
        """Test to call the method with custom format and level."""
        # call the method
        create_logger(custom_log_format="my custom format",
                      custom_log_level="my custom level")

        # assert the call
        mocked_install.assert_called_with(fmt="my custom format",
                                          level="my custom level")
        mocked_wrap_stderr.assert_not_called()
コード例 #7
0
def feed(args):
    """Execute the feed action

    Args:
        args (argparse.Namespace): arguments from command line.
    """
    create_logger(wrap=True)

    # load the config, display help to create config if it fails
    try:
        config = load_config(
            get_config_file(CONFIG_FILE),
            args.debug,
            mandatory_keys=["kara_folder", "server"],
        )

    except ConfigNotFoundError as error:
        raise ConfigNotFoundError(
            "{}, please run 'dakara-feed create-config'".format(
                error)) from error

    set_loglevel(config)
    feeder = DakaraFeeder(config,
                          force_update=args.force,
                          progress=args.progress)

    # load the feeder, consider that the config is incomplete if it fails
    try:
        feeder.load()

    except DakaraError:
        logger.warning("Config may be incomplete, please check '{}'".format(
            get_config_file(CONFIG_FILE)))
        raise

    # do the actual feeding
    feeder.feed()