コード例 #1
0
ファイル: convert.py プロジェクト: psychoticmeow/beets
def convert_func(lib, opts, args):
    dest = opts.dest if opts.dest is not None else \
            config['convert']['dest'].get()

    if not dest:
        raise ui.UserError('no convert destination set')

    dest = util.bytestring_path(dest)
    threads = opts.threads if opts.threads is not None else \
            config['convert']['threads'].get(int)
    keep_new = opts.keep_new

    if not config['convert']['paths']:
        path_formats = ui.get_path_formats()
    else:
        path_formats = ui.get_path_formats(config['convert']['paths'])

    ui.commands.list_items(lib, ui.decargs(args), opts.album, None)

    if not ui.input_yn("Convert? (Y/n)"):
        return

    if opts.album:
        items = (i for a in lib.albums(ui.decargs(args)) for i in a.items())
    else:
        items = iter(lib.items(ui.decargs(args)))
    convert = [convert_item(lib, dest, keep_new, path_formats) for i in range(threads)]
    pipe = util.pipeline.Pipeline([items, convert])
    pipe.run_parallel()
コード例 #2
0
ファイル: test_ui.py プロジェクト: axujen/beets
    def test_custom_paths_prepend(self):
        default_formats = ui.get_path_formats()

        config['paths'] = {u'foo': u'bar'}
        pf = ui.get_path_formats()
        key, tmpl = pf[0]
        self.assertEqual(key, 'foo')
        self.assertEqual(tmpl.original, 'bar')
        self.assertEqual(pf[1:], default_formats)
コード例 #3
0
ファイル: test_ui.py プロジェクト: nanux/beets
    def test_custom_paths_prepend(self):
        default_formats = ui.get_path_formats()

        config["paths"] = {u"foo": u"bar"}
        pf = ui.get_path_formats()
        key, tmpl = pf[0]
        self.assertEqual(key, "foo")
        self.assertEqual(tmpl.original, "bar")
        self.assertEqual(pf[1:], default_formats)
コード例 #4
0
ファイル: test_ui.py プロジェクト: Tantali/beets
 def test_default_paths_preserved(self):
     default_formats = ui.get_path_formats()
     def func(lib, opts, args):
         self.assertEqual(lib.path_formats[1:],
                          default_formats)
     self._run_main([], """
         paths:
             x: y
     """, func)
コード例 #5
0
ファイル: convert.py プロジェクト: Handpaperrotp/beets
    def convert_func(self, lib, opts, args):
        if not opts.dest:
            opts.dest = self.config['dest'].get()
        if not opts.dest:
            raise ui.UserError('no convert destination set')
        opts.dest = util.bytestring_path(opts.dest)

        if not opts.threads:
            opts.threads = self.config['threads'].get(int)

        if self.config['paths']:
            path_formats = ui.get_path_formats(self.config['paths'])
        else:
            path_formats = ui.get_path_formats()

        if not opts.format:
            opts.format = self.config['format'].get(unicode).lower()

        pretend = opts.pretend if opts.pretend is not None else \
            self.config['pretend'].get(bool)

        if not pretend:
            ui.commands.list_items(lib, ui.decargs(args), opts.album)

            if not (opts.yes or ui.input_yn("Convert? (Y/n)")):
                return

        if opts.album:
            albums = lib.albums(ui.decargs(args))
            items = (i for a in albums for i in a.items())
            if self.config['copy_album_art']:
                for album in albums:
                    self.copy_album_art(album, opts.dest, path_formats,
                                        pretend)
        else:
            items = iter(lib.items(ui.decargs(args)))
        convert = [self.convert_item(opts.dest,
                                     opts.keep_new,
                                     path_formats,
                                     opts.format,
                                     pretend)
                   for _ in range(opts.threads)]
        pipe = util.pipeline.Pipeline([items, convert])
        pipe.run_parallel()
コード例 #6
0
    def convert_func(self, lib, opts, args):
        if not opts.dest:
            opts.dest = self.config['dest'].get()
        if not opts.dest:
            raise ui.UserError(u'no convert destination set')
        opts.dest = util.bytestring_path(opts.dest)

        if not opts.threads:
            opts.threads = self.config['threads'].get(int)

        if self.config['paths']:
            path_formats = ui.get_path_formats(self.config['paths'])
        else:
            path_formats = ui.get_path_formats()

        if not opts.format:
            opts.format = self.config['format'].get(unicode).lower()

        pretend = opts.pretend if opts.pretend is not None else \
            self.config['pretend'].get(bool)

        if not pretend:
            ui.commands.list_items(lib, ui.decargs(args), opts.album)

            if not (opts.yes or ui.input_yn(u"Convert? (Y/n)")):
                return

        if opts.album:
            albums = lib.albums(ui.decargs(args))
            items = (i for a in albums for i in a.items())
            if self.config['copy_album_art']:
                for album in albums:
                    self.copy_album_art(album, opts.dest, path_formats,
                                        pretend)
        else:
            items = iter(lib.items(ui.decargs(args)))
        convert = [
            self.convert_item(opts.dest, opts.keep_new, path_formats,
                              opts.format, pretend)
            for _ in range(opts.threads)
        ]
        pipe = util.pipeline.Pipeline([items, convert])
        pipe.run_parallel()
コード例 #7
0
    def test_default_paths_preserved(self):
        default_formats = ui.get_path_formats()

        self._reset_config()
        with self.write_config_file() as config:
            config.write('paths: {x: y}')
        self.run_command('test', lib=None)
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, 'x')
        self.assertEqual(template.original, 'y')
        self.assertEqual(self.test_cmd.lib.path_formats[1:], default_formats)
コード例 #8
0
ファイル: test_ui.py プロジェクト: dangmai/beets
    def test_default_paths_preserved(self):
        default_formats = ui.get_path_formats()

        self._reset_config()
        with self.write_config_file() as config:
            config.write('paths: {x: y}')
        self.run_command('test', lib=None)
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, 'x')
        self.assertEqual(template.original, 'y')
        self.assertEqual(self.test_cmd.lib.path_formats[1:], default_formats)
コード例 #9
0
ファイル: test_ui.py プロジェクト: nanux/beets
    def test_default_paths_preserved(self):
        default_formats = ui.get_path_formats()

        self._reset_config()
        with self.write_config_file() as config:
            config.write("paths: {x: y}")

        ui._raw_main(["test"])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, "x")
        self.assertEqual(template.original, "y")
        self.assertEqual(self.test_cmd.lib.path_formats[1:], default_formats)
コード例 #10
0
ファイル: convert.py プロジェクト: zammottomate/beets
def convert_func(lib, opts, args):
    if not opts.dest:
        opts.dest = config['convert']['dest'].get()
    if not opts.dest:
        raise ui.UserError('no convert destination set')
    opts.dest = util.bytestring_path(opts.dest)

    if not opts.threads:
        opts.threads = config['convert']['threads'].get(int)

    if config['convert']['paths']:
        path_formats = ui.get_path_formats(config['convert']['paths'])
    else:
        path_formats = ui.get_path_formats()

    if not opts.format:
        opts.format = config['convert']['format'].get(unicode).lower()

    command, ext = get_format(opts.format)

    pretend = opts.pretend if opts.pretend is not None else \
        config['convert']['pretend'].get(bool)

    if not pretend:
        ui.commands.list_items(lib, ui.decargs(args), opts.album, None)

        if not ui.input_yn("Convert? (Y/n)"):
            return

    if opts.album:
        items = (i for a in lib.albums(ui.decargs(args)) for i in a.items())
    else:
        items = iter(lib.items(ui.decargs(args)))
    convert = [
        convert_item(opts.dest, opts.keep_new, path_formats, command, ext,
                     pretend) for _ in range(opts.threads)
    ]
    pipe = util.pipeline.Pipeline([items, convert])
    pipe.run_parallel()
コード例 #11
0
ファイル: convert.py プロジェクト: KumaraKL/beets
def convert_func(lib, opts, args):
    if not opts.dest:
        opts.dest = config['convert']['dest'].get()
    if not opts.dest:
        raise ui.UserError('no convert destination set')
    opts.dest = util.bytestring_path(opts.dest)

    if not opts.threads:
        opts.threads = config['convert']['threads'].get(int)

    if config['convert']['paths']:
        path_formats = ui.get_path_formats(config['convert']['paths'])
    else:
        path_formats = ui.get_path_formats()

    if not opts.format:
        opts.format = config['convert']['format'].get(unicode).lower()

    command, ext = get_format(opts.format)

    ui.commands.list_items(lib, ui.decargs(args), opts.album, None)

    if not ui.input_yn("Convert? (Y/n)"):
        return

    if opts.album:
        items = (i for a in lib.albums(ui.decargs(args)) for i in a.items())
    else:
        items = iter(lib.items(ui.decargs(args)))
    convert_stages = []
    for i in range(opts.threads):
        convert_stages.append(
            convert_item(opts.dest, opts.keep_new, path_formats, command, ext)
        )
    pipe = util.pipeline.Pipeline([items, convert_stages])
    pipe.run_parallel()
コード例 #12
0
    def convert_func(self, lib, opts, args):
        dest = opts.dest or self.config['dest'].get()
        if not dest:
            raise ui.UserError(u'no convert destination set')
        dest = util.bytestring_path(dest)

        threads = opts.threads or self.config['threads'].get(int)

        path_formats = ui.get_path_formats(self.config['paths'] or None)

        fmt = opts.format or self.config['format'].as_str().lower()

        if opts.pretend is not None:
            pretend = opts.pretend
        else:
            pretend = self.config['pretend'].get(bool)

        if opts.album:
            albums = lib.albums(ui.decargs(args))
            items = [i for a in albums for i in a.items()]
            if not pretend:
                for a in albums:
                    ui.print_(format(a, u''))
        else:
            items = list(lib.items(ui.decargs(args)))
            if not pretend:
                for i in items:
                    ui.print_(format(i, u''))

        if not items:
            self._log.error(u'Empty query result.')
            return
        if not (pretend or opts.yes or ui.input_yn(u"Convert? (Y/n)")):
            return

        if opts.album and self.config['copy_album_art']:
            for album in albums:
                self.copy_album_art(album, dest, path_formats, pretend)

        convert = [self.convert_item(dest,
                                     opts.keep_new,
                                     path_formats,
                                     fmt,
                                     pretend)
                   for _ in range(threads)]
        pipe = util.pipeline.Pipeline([iter(items), convert])
        pipe.run_parallel()
コード例 #13
0
    def parse_config(self, config):
        if 'paths' in config:
            path_config = config['paths']
        else:
            path_config = beets.config['paths']
        self.path_formats = get_path_formats(path_config)
        self.query, _ = parse_query_string(config['query'].get(unicode), Item)

        self.removable = config.get(dict).get('removable', True)

        if 'directory' in config:
            dir = config['directory'].get(str)
        else:
            dir = self.name
        if not os.path.isabs(dir):
            dir = os.path.join(self.lib.directory, dir)
        self.directory = bytestring_path(dir)
コード例 #14
0
    def parse_config(self, config):
        if 'paths' in config:
            path_config = config['paths']
        else:
            path_config = beets.config['paths']
        self.path_formats = get_path_formats(path_config)
        query = get_unicode_config(config, 'query')
        self.query, _ = parse_query_string(query, Item)

        self.removable = config.get(dict).get('removable', True)

        if 'directory' in config:
            dir = config['directory'].get(str)
        else:
            dir = self.name
        if not os.path.isabs(dir):
            dir = os.path.join(self.lib.directory, dir)
        self.directory = bytestring_path(dir)
コード例 #15
0
    def parse_config(self, config):
        if 'paths' in config:
            path_config = config['paths']
        else:
            path_config = beets.config['paths']
        self.path_formats = get_path_formats(path_config)
        query = config['query'].as_str()
        self.query, _ = parse_query_string(query, Item)

        self.removable = config.get(dict).get('removable', True)
        self.copy_album_art = config.get(dict).get('copy_album_art', False)

        if 'directory' in config:
            dir = config['directory'].as_str()
        else:
            dir = self.name
        dir = bytestring_path(dir)
        if not os.path.isabs(syspath(dir)):
            dir = os.path.join(self.lib.directory, dir)
        self.directory = dir
コード例 #16
0
 def test_multiline_formats_with_strip(self):
     config['paths'] = {u'default': '  foo\n    bar\n    baz  '}
     pf = ui.get_path_formats()
     key, tmpl = pf[0]
     self.assertEqual(key, u'default')
     self.assertEqual(tmpl.original, u'foobarbaz')