How to use the beets.util.displayable_path function in beets

To help you get started, we’ve selected a few beets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beetbox / beets / beetsplug / badfiles.py View on Github external
def run_command(self, cmd):
        self._log.debug(u"running command: {}",
                        displayable_path(list2cmdline(cmd)))
        try:
            output = check_output(cmd, stderr=STDOUT)
            errors = 0
            status = 0
        except CalledProcessError as e:
            output = e.output
            errors = 1
            status = e.returncode
        except OSError as e:
            raise CheckerCommandException(cmd, e)
        output = output.decode(sys.getfilesystemencoding())
        return status, errors, [line for line in output.split("\n") if line]
github rembo10 / headphones / lib / beets / importer.py View on Github external
albums.
        """
        if self.is_album:
            replaced_album = self.replaced_albums.get(self.album.path)
            if replaced_album:
                self.album.added = replaced_album.added
                self.album.update(replaced_album._values_flex)
                self.album.artpath = replaced_album.artpath
                self.album.store()
                log.debug(
                    u'Reimported album: added {0}, flexible '
                    u'attributes {1} from album {2} for {3}',
                    self.album.added,
                    replaced_album._values_flex.keys(),
                    replaced_album.id,
                    displayable_path(self.album.path)
                )

        for item in self.imported_items():
            dup_items = self.replaced_items[item]
            for dup_item in dup_items:
                if dup_item.added and dup_item.added != item.added:
                    item.added = dup_item.added
                    log.debug(
                        u'Reimported item added {0} '
                        u'from item {1} for {2}',
                        item.added,
                        dup_item.id,
                        displayable_path(item.path)
                    )
                item.update(dup_item._values_flex)
                log.debug(
github clinton-hall / nzbToMedia / libs / beets / ui / __init__.py View on Github external
def _open_library(config):
    """Create a new library instance from the configuration.
    """
    dbpath = config['library'].as_filename()
    try:
        lib = library.Library(
            dbpath,
            config['directory'].as_filename(),
            get_path_formats(),
            get_replacements(),
        )
        lib.get_item(0)  # Test database connection.
    except (sqlite3.OperationalError, sqlite3.DatabaseError):
        log.debug(u'{}', traceback.format_exc())
        raise UserError(u"database file {0} could not be opened".format(
            util.displayable_path(dbpath)
        ))
    log.debug(u'library database: {0}\n'
              u'library directory: {1}',
              util.displayable_path(lib.path),
              util.displayable_path(lib.directory))
    return lib
github beetbox / beets / beetsplug / embedart.py View on Github external
def embed_func(lib, opts, args):
            if opts.file:
                imagepath = normpath(opts.file)
                if not os.path.isfile(syspath(imagepath)):
                    raise ui.UserError(u'image file {0} not found'.format(
                        displayable_path(imagepath)
                    ))

                items = lib.items(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(items, not opts.file):
                    return

                for item in items:
                    art.embed_item(self._log, item, imagepath, maxwidth, None,
                                   compare_threshold, ifempty)
            else:
                albums = lib.albums(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(albums, not opts.file):
github rembo10 / headphones / lib / beetsplug / fetchart.py View on Github external
images.append(fn)

    # Look for "preferred" filenames.
    images = sorted(images, key=lambda x: filename_priority(x, cover_names))
    cover_pat = r"(\b|_)({0})(\b|_)".format('|'.join(cover_names))
    for fn in images:
        if re.search(cover_pat, os.path.splitext(fn)[0], re.I):
            log.debug(u'fetchart: using well-named art file {0}'.format(
                util.displayable_path(fn)
            ))
            return os.path.join(path, fn)

    # Fall back to any image in the folder.
    if images and not cautious:
        log.debug(u'fetchart: using fallback art file {0}'.format(
            util.displayable_path(images[0])
        ))
        return os.path.join(path, images[0])
github clinton-hall / nzbToMedia / libs / beets / importer.py View on Github external
def album(self, paths, dirs=None):
        """Return a `ImportTask` with all media files from paths.

        `dirs` is a list of parent directories used to record already
        imported albums.
        """
        if not paths:
            return None

        if dirs is None:
            dirs = list(set(os.path.dirname(p) for p in paths))

        if self.session.already_imported(self.toppath, dirs):
            log.debug(u'Skipping previously-imported path: {0}',
                      displayable_path(dirs))
            self.skipped += 1
            return None

        items = map(self.read_item, paths)
        items = [item for item in items if item]

        if items:
            return ImportTask(self.toppath, dirs, items)
        else:
            return None
github beetbox / beets / beets / ui / __init__.py View on Github external
their differences highlighted in the specified color. Strings are
    highlighted intelligently to show differences; other values are
    stringified and highlighted in their entirety.
    """
    if not isinstance(a, basestring) or not isinstance(b, basestring):
        # Non-strings: use ordinary equality.
        a = unicode(a)
        b = unicode(b)
        if a == b:
            return a, b
        else:
            return colorize(highlight, a), colorize(highlight, b)

    if isinstance(a, bytes) or isinstance(b, bytes):
        # A path field.
        a = util.displayable_path(a)
        b = util.displayable_path(b)

    a_out = []
    b_out = []

    matcher = SequenceMatcher(lambda x: False, a, b)
    for op, a_start, a_end, b_start, b_end in matcher.get_opcodes():
        if op == 'equal':
            # In both strings.
            a_out.append(a[a_start:a_end])
            b_out.append(b[b_start:b_end])
        elif op == 'insert':
            # Right only.
            b_out.append(colorize(highlight, b[b_start:b_end]))
        elif op == 'delete':
            # Left only.