Esempio n. 1
0
    def tearDown(self):
        super(DestinationTest, self).tearDown()
        self.lib._connection().close()

        # Reset config if it was changed in test cases
        config.clear()
        config.read(user=False, defaults=True)
Esempio n. 2
0
 def setUp(self):
     config.clear()
     config.read(user=False)
     self.importfeeds = ImportFeedsPlugin()
     self.lib = Library(':memory:')
     self.feeds_dir = tempfile.mkdtemp()
     config['importfeeds']['dir'] = self.feeds_dir
Esempio n. 3
0
    def tearDown(self):
        super(DestinationTest, self).tearDown()
        self.lib._connection().close()

        # Reset config if it was changed in test cases
        config.clear()
        config.read(user=False, defaults=True)
Esempio n. 4
0
 def setUp(self):
     config.clear()
     config.read(user=False)
     self.importfeeds = ImportFeedsPlugin()
     self.lib = Library(':memory:')
     self.feeds_dir = tempfile.mkdtemp()
     config['importfeeds']['dir'] = self.feeds_dir
Esempio n. 5
0
    def test_beetsdir_config_does_not_load_default_user_config(self):
        os.environ["BEETSDIR"] = self.beetsdir

        with open(self.user_config_path, "w") as file:
            file.write("anoption: value")

        config.read()
        self.assertFalse(config["anoption"].exists())
Esempio n. 6
0
    def test_default_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        config.read()
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.beetsdir, 'library.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.beetsdir, 'state.pickle'))
Esempio n. 7
0
    def test_beetsdir_config_does_not_load_default_user_config(self):
        os.environ['BEETSDIR'] = self.beetsdir

        with open(self.user_config_path, 'w') as file:
            file.write('anoption: value')

        config.read()
        self.assertFalse(config['anoption'].exists())
Esempio n. 8
0
    def test_beetsdir_config_does_not_load_default_user_config(self):
        os.environ['BEETSDIR'] = self.beetsdir

        with open(self.user_config_path, 'w') as file:
            file.write('anoption: value')

        config.read()
        self.assertFalse(config['anoption'].exists())
Esempio n. 9
0
    def test_default_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        config.read()
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.beetsdir, 'library.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.beetsdir, 'state.pickle'))
Esempio n. 10
0
    def test_beetsdir_config(self):
        os.environ['BEETSDIR'] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('anoption: overwrite')

        config.read()
        self.assertEqual(config['anoption'].get(), 'overwrite')
Esempio n. 11
0
    def test_beetsdir_config(self):
        os.environ['BEETSDIR'] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('anoption: overwrite')

        config.read()
        self.assertEqual(config['anoption'].get(), 'overwrite')
Esempio n. 12
0
    def test_beetsdir_config(self):
        os.environ["BEETSDIR"] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, "config.yaml")
        with open(env_config_path, "w") as file:
            file.write("anoption: overwrite")

        config.read()
        self.assertEqual(config["anoption"].get(), "overwrite")
Esempio n. 13
0
    def test_default_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)

        config.read()
        self.assert_equal_path(
            util.bytestring_path(config['library'].as_filename()),
            os.path.join(self.beetsdir, b'library.db'))
        self.assert_equal_path(
            util.bytestring_path(config['statefile'].as_filename()),
            os.path.join(self.beetsdir, b'state.pickle'))
Esempio n. 14
0
    def test_default_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)

        config.read()
        self.assert_equal_path(
            util.bytestring_path(config['library'].as_filename()),
            os.path.join(self.beetsdir, b'library.db'))
        self.assert_equal_path(
            util.bytestring_path(config['statefile'].as_filename()),
            os.path.join(self.beetsdir, b'state.pickle'))
Esempio n. 15
0
    def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
        os.environ["BEETSDIR"] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, "config.yaml")
        with open(env_config_path, "w") as file:
            file.write("library: beets.db\n")
            file.write("statefile: state")

        config.read()
        self.assertEqual(config["library"].as_filename(), os.path.join(self.beetsdir, "beets.db"))
        self.assertEqual(config["statefile"].as_filename(), os.path.join(self.beetsdir, "state"))
Esempio n. 16
0
    def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        config.read()
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.beetsdir, 'beets.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.beetsdir, 'state'))
Esempio n. 17
0
    def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        config.read()
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.beetsdir, 'beets.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.beetsdir, 'state'))
Esempio n. 18
0
    def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)

        env_config_path = os.path.join(self.beetsdir, b'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        config.read()
        self.assert_equal_path(
            util.bytestring_path(config['library'].as_filename()),
            os.path.join(self.beetsdir, b'beets.db'))
        self.assert_equal_path(
            util.bytestring_path(config['statefile'].as_filename()),
            os.path.join(self.beetsdir, b'state'))
Esempio n. 19
0
    def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)

        env_config_path = os.path.join(self.beetsdir, b'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        config.read()
        self.assert_equal_path(
            util.bytestring_path(config['library'].as_filename()),
            os.path.join(self.beetsdir, b'beets.db'))
        self.assert_equal_path(
            util.bytestring_path(config['statefile'].as_filename()),
            os.path.join(self.beetsdir, b'state'))
Esempio n. 20
0
def _raw_main(args, load_config=True):
    """A helper function for `main` without top-level exception
    handling.
    """
    # Load global configuration files.
    if load_config:
        config.read()

    # Temporary: Migrate from 1.0-style configuration.
    from beets.ui import migrate
    if load_config:
        migrate.automigrate()

    # Get the default subcommands.
    from beets.ui.commands import default_commands

    # Add plugin paths.
    sys.path += get_plugin_paths()
    # Load requested plugins.
    plugins.load_plugins(config['plugins'].as_str_seq())
    plugins.send("pluginload")

    # Construct the root parser.
    commands = list(default_commands)
    commands += plugins.commands()
    commands.append(migrate.migrate_cmd)  # Temporary.
    parser = SubcommandsOptionParser(subcommands=commands)
    parser.add_option('-l',
                      '--library',
                      dest='library',
                      help='library database file to use')
    parser.add_option('-d',
                      '--directory',
                      dest='directory',
                      help="destination music directory")
    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='print debugging information')

    # Parse the command-line!
    options, subcommand, suboptions, subargs = parser.parse_args(args)
    config.set_args(options)

    # Open library file.
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            Template(config['art_filename'].get(unicode)),
            config['timeout'].as_number(),
            get_replacements(),
        )
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'.format(
                  util.displayable_path(config.config_dir()),
                  util.displayable_path(lib.path),
                  util.displayable_path(lib.directory),
              ))

    # Configure the MusicBrainz API.
    mb.configure()

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
    plugins.send('cli_exit', lib=lib)
Esempio n. 21
0
 def test_command_line_option_relative_to_working_dir(self):
     config.read()
     os.chdir(self.temp_dir)
     self.run_command('--library', 'foo.db', 'test', lib=None)
     self.assert_equal_path(config['library'].as_filename(),
                            os.path.join(os.getcwd(), 'foo.db'))
Esempio n. 22
0
def _raw_main(args, load_config=True):
    """A helper function for `main` without top-level exception
    handling.
    """
    # Load global configuration files.
    if load_config:
        config.read()

    # Temporary: Migrate from 1.0-style configuration.
    from beets.ui import migrate
    if load_config:
        migrate.automigrate()

    # Get the default subcommands.
    from beets.ui.commands import default_commands

    # Add plugin paths.
    sys.path += get_plugin_paths()
    # Load requested plugins.
    plugins.load_plugins(config['plugins'].as_str_seq())
    plugins.send("pluginload")

    # Construct the root parser.
    commands = list(default_commands)
    commands += plugins.commands()
    commands.append(migrate.migrate_cmd)  # Temporary.
    parser = SubcommandsOptionParser(subcommands=commands)
    parser.add_option('-l', '--library', dest='library',
                      help='library database file to use')
    parser.add_option('-d', '--directory', dest='directory',
                      help="destination music directory")
    parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
                      help='print debugging information')

    # Parse the command-line!
    options, subcommand, suboptions, subargs = parser.parse_args(args)
    config.set_args(options)

    # Open library file.
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            Template(config['art_filename'].get(unicode)),
            config['timeout'].as_number(),
            get_replacements(),
        )
    except sqlite3.OperationalError:
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)
        ))
    plugins.send("library_opened", lib=lib)

    # Configure the logger.
    if config['verbose'].get(bool):
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    log.debug(u'data directory: {0}\n'
              u'library database: {1}\n'
              u'library directory: {2}'.format(
        util.displayable_path(config.config_dir()),
        util.displayable_path(lib.path),
        util.displayable_path(lib.directory),
    ))

    # Invoke the subcommand.
    subcommand.func(lib, suboptions, subargs)
Esempio n. 23
0
    def test_default_config_paths_resolve_relative_to_beetsdir(self):
        os.environ["BEETSDIR"] = self.beetsdir

        config.read()
        self.assertEqual(config["library"].as_filename(), os.path.join(self.beetsdir, "library.db"))
        self.assertEqual(config["statefile"].as_filename(), os.path.join(self.beetsdir, "state.pickle"))