• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python path.is_fsnative函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中quodlibet.util.path.is_fsnative函数的典型用法代码示例。如果您正苦于以下问题:Python is_fsnative函数的具体用法?Python is_fsnative怎么用?Python is_fsnative使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_fsnative函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: show_files_win32

def show_files_win32(path, files):
    """Takes a path to a directory and a list of filenames in that directory
    to display.

    Returns True on success.
    """

    assert os.name == "nt"

    import pywintypes
    from win32com.shell import shell

    assert is_fsnative(path)
    assert all(is_fsnative(f) for f in files)

    normalized_files = map(normalize_path, files)

    try:
        folder_pidl = shell.SHILCreateFromPath(path, 0)[0]
        desktop = shell.SHGetDesktopFolder()
        shell_folder = desktop.BindToObject(
            folder_pidl, None, shell.IID_IShellFolder)
        items = []
        for item in shell_folder:
            name = desktop.GetDisplayNameOf(item, 0)
            if normalize_path(name) in normalized_files:
                items.append(item)
        shell.SHOpenFolderAndSelectItems(folder_pidl, items, 0)
    except pywintypes.com_error:
        return False
    else:
        return True
开发者ID:MikeiLL,项目名称:quodlibet,代码行数:32,代码来源:browsefolders.py


示例2: test_uri_to_path

 def test_uri_to_path(self):
     if os.name != "nt":
         path = uri_to_path("file:///home/piman/cr%21azy")
         self.assertTrue(is_fsnative(path))
         self.assertEqual(path, fsnative(u"/home/piman/cr!azy"))
     else:
         path = uri_to_path("file:///C:/foo")
         self.assertTrue(is_fsnative(path))
         self.assertEqual(path, fsnative(u"C:\\foo"))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:9,代码来源:test_util_path.py


示例3: test_lyric_filename

 def test_lyric_filename(self):
     song = AudioFile()
     song["~filename"] = fsnative(u"filename")
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["title"] = u"Title"
     song["artist"] = u"Artist"
     self.assertTrue(is_fsnative(song.lyric_filename))
     song["lyricist"] = u"Lyricist"
     self.assertTrue(is_fsnative(song.lyric_filename))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:9,代码来源:test_formats__audio.py


示例4: test_conv

    def test_conv(self):
        empty = fsnative(u"")

        v = self.c.filter(empty, fsnative(u"foobar baz"))
        self.failUnlessEqual(v, fsnative(u"foobar baz"))
        self.failUnless(is_fsnative(v))

        v = self.c.filter(empty, fsnative(u"Foobar.BAZ"))
        self.failUnlessEqual(v, fsnative(u"foobar.baz"))
        self.failUnless(is_fsnative(v))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:10,代码来源:test_qltk_renamefiles.py


示例5: test_main

    def test_main(self):
        v = fsnative(u"foo")
        self.assertTrue(is_fsnative(v))

        v2 = glib2fsnative(fsnative2glib(v))
        self.assertTrue(is_fsnative(v2))
        self.assertEqual(v, v2)

        v3 = bytes2fsnative(fsnative2bytes(v))
        self.assertTrue(is_fsnative(v3))
        self.assertEqual(v, v3)
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:11,代码来源:test_util.py


示例6: test_cover_path

    def test_cover_path(self):
        song = AudioFile({"musicbrainz_albumid": u"foobar"})
        song2 = AudioFile()

        # missing Soup
        if "lastfm-cover" in self.plugins:
            cls = self.plugins["lastfm-cover"].cls
            self.assertTrue(is_fsnative(cls(song).cover_path))
            self.assertTrue(is_fsnative(cls(song2).cover_path))

        # missing Soup
        if "musicbrainz-cover" in self.plugins:
            cls = self.plugins["musicbrainz-cover"].cls
            self.assertTrue(is_fsnative(cls(song).cover_path))
            self.assertTrue(is_fsnative(cls(song2).cover_path))
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:15,代码来源:test_covers.py


示例7: get_thumbnail_from_file

def get_thumbnail_from_file(fileobj, boundary):
    """Like get_thumbnail() but works with files that can't be reopened.

    This is needed on Windows where NamedTemporaryFile can't be reopened.

    Returns Pixbuf or None. Thread-safe.
    """

    assert fileobj

    try:
        path = fileobj.name
        assert is_fsnative(path), path
        return get_thumbnail(path, boundary)
    except GLib.GError:
        try:
            loader = GdkPixbuf.PixbufLoader()
            loader.set_size(*boundary)
            loader.write(fileobj.read())
            loader.close()
            fileobj.seek(0, 0)
            # can return None in case of partial data
            return loader.get_pixbuf()
        except (GLib.GError, EnvironmentError):
            pass
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:25,代码来源:thumbnails.py


示例8: get_cache_info

def get_cache_info(path, boundary):
    """For an image at `path` return (cache_path, thumb_size)

    cache_path points to a potential cache file
    thumb size is either 128 or 256
    """

    assert is_fsnative(path)

    width, height = boundary

    if width <= ThumbSize.NORMAL and height <= ThumbSize.NORMAL:
        size_name = "normal"
        thumb_size = ThumbSize.NORMAL
    else:
        size_name = "large"
        thumb_size = ThumbSize.LARGE

    thumb_folder = get_thumbnail_folder()
    cache_dir = os.path.join(thumb_folder, size_name)

    uri = "file://" + pathname2url(path)
    thumb_name = hashlib.md5(uri).hexdigest() + ".png"
    thumb_path = os.path.join(cache_dir, thumb_name)

    return (thumb_path, thumb_size)
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:26,代码来源:thumbnails.py


示例9: test_long_filename

 def test_long_filename(s):
     if os.name == "nt":
         a = AudioFile({"title": "x" * 300, "~filename": u"C:\\f.mp3"})
         path = s._create(u'C:\\foobar\\ä<title>\\<title>').format(a)
         assert is_fsnative(path)
         s.failUnlessEqual(len(path), 3 + 6 + 1 + 255 + 1 + 255)
         path = s._create(u'äüö<title><title>').format(a)
         assert is_fsnative(path)
         s.failUnlessEqual(len(path), 255)
     else:
         a = AudioFile({"title": "x" * 300, "~filename": "/f.mp3"})
         path = s._create(u'/foobar/ä<title>/<title>').format(a)
         assert is_fsnative(path)
         s.failUnlessEqual(len(path), 1 + 6 + 1 + 255 + 1 + 255)
         path = s._create(u'äüö<title><title>').format(a)
         assert is_fsnative(path)
         s.failUnlessEqual(len(path), 255)
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:17,代码来源:test_pattern.py


示例10: sanitize

    def sanitize(self, filename=None):
        """Fill in metadata defaults. Find ~mountpoint, ~#mtime, ~#filesize
        and ~#added. Check for null bytes in tags.

        Does not raise.
        """

        # Replace nulls with newlines, trimming zero-length segments
        for key, val in self.items():
            if isinstance(val, string_types) and '\0' in val:
                self[key] = '\n'.join(filter(lambda s: s, val.split('\0')))
            # Remove unnecessary defaults
            if key in INTERN_NUM_DEFAULT and val == 0:
                del self[key]

        if filename:
            self["~filename"] = filename
        elif "~filename" not in self:
            raise ValueError("Unknown filename!")

        assert is_fsnative(self["~filename"])

        if self.is_file:
            self["~filename"] = normalize_path(
                self["~filename"], canonicalise=True)
            # Find mount point (terminating at "/" if necessary)
            head = self["~filename"]
            while "~mountpoint" not in self:
                head, tail = os.path.split(head)
                # Prevent infinite loop without a fully-qualified filename
                # (the unit tests use these).
                head = head or "/"
                if os.path.ismount(head):
                    self["~mountpoint"] = head
        else:
            self["~mountpoint"] = fsnative(u"/")

        # Fill in necessary values.
        self.setdefault("~#added", int(time.time()))

        # For efficiency, do a single stat here. See Issue 504
        try:
            stat = os.stat(self['~filename'])
            self["~#mtime"] = stat.st_mtime
            self["~#filesize"] = stat.st_size

            # Issue 342. This is a horrible approximation (due to headers) but
            # on FLACs, the most common case, this should be close enough
            if "~#bitrate" not in self:
                try:
                    # kbps = bytes * 8 / seconds / 1000
                    self["~#bitrate"] = int(stat.st_size /
                                            (self["~#length"] * (1000 / 8)))
                except (KeyError, ZeroDivisionError):
                    pass
        except OSError:
            self["~#mtime"] = 0
开发者ID:pensadorramm,项目名称:quodlibet,代码行数:57,代码来源:_audio.py


示例11: show_files_win32

def show_files_win32(path, files):
    """Takes a path to a directory and a list of filenames in that directory
    to display.

    Returns True on success.
    """

    assert os.name == "nt"
    assert is_fsnative(path)
    assert all(is_fsnative(f) for f in files)

    from quodlibet.util.windows import open_folder_and_select_items

    try:
        open_folder_and_select_items(path, files)
    except WindowsError:
        return False
    return True
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:18,代码来源:browsefolders.py


示例12: test_windows_path

    def test_windows_path(self):
        if os.name != "nt":
            return

        win_path = u"C:\\SomeDir\xe4"
        uri = URI.frompath(win_path)
        self.assertEqual(uri, "file:///C:/SomeDir%C3%A4")
        self.assertTrue(uri.is_filename)
        self.assertTrue(is_fsnative(uri.filename))
        self.assertEqual(uri.filename, win_path)
开发者ID:bp0,项目名称:quodlibet,代码行数:10,代码来源:test_util_uri.py


示例13: test_roundtrip

    def test_roundtrip(self):
        if os.name == "nt":
            paths = [u"C:\\öäü.txt"]
        else:
            paths = [u"/öäü.txt", u"//foo/bar", u"///foo/bar"]

        for source in paths:
            path = uri_to_path(uri_from_path(fsnative(source)))
            self.assertTrue(is_fsnative(path))
            self.assertEqual(path, fsnative(source))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py


示例14: test_ends_with_dots_or_spaces

    def test_ends_with_dots_or_spaces(self):
        empty = fsnative(u"")
        v = self.c.filter(empty, fsnative(u"foo. . "))
        self.failUnlessEqual(v, fsnative(u"foo. ._"))
        self.assertTrue(is_fsnative(v))

        if os.name == "nt":
            self.failUnlessEqual(self.c.filter(empty, u"foo. \\bar ."), u"foo._\\bar _")
        else:
            self.failUnlessEqual(self.c.filter(empty, u"foo. /bar ."), "foo._/bar _")
开发者ID:mistotebe,项目名称:quodlibet,代码行数:10,代码来源:test_qltk_renamefiles.py


示例15: __getitem__

    def __getitem__(self, key):
        # we used to save them with the wrong type
        value = super(RemoteFile, self).__getitem__(key)
        if key in ("~filename", "~mountpoint") and not is_fsnative(value):
            if os.name == "nt":
                value = unicode(value)
            else:
                value = value.encode("utf-8")

        return value
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:10,代码来源:remote.py


示例16: new

    def new(cls, dir_, base=_("New Playlist"), library=None):
        assert is_fsnative(dir_)

        if not (dir_ and os.path.realpath(dir_)):
            raise ValueError("Invalid playlist directory %r" % (dir_,))

        for i in range(1000):
            try:
                name = "%s %d" % (base, i) if i else base
                return FileBackedPlaylist(dir_, name, library, validate=True)
            except ValueError:
                pass
        raise ValueError("Couldn't create playlist of name '%s'" % base)
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:13,代码来源:collection.py


示例17: test_main

    def test_main(self):
        if os.name == "nt":
            path = u'C:\\foobar\\ä%s\\%s' % ("x" * 300, "x" * 300)
            path = limit_path(path)
            self.failUnlessEqual(len(path), 3 + 6 + 1 + 255 + 1 + 255)
        else:
            path = '/foobar/ä%s/%s' % ("x" * 300, "x" * 300)
            path = limit_path(path)
            self.failUnlessEqual(len(path), 1 + 6 + 1 + 255 + 1 + 255)

        path = fsnative(u"foo%s.ext" % (u"x" * 300))
        new = limit_path(path, ellipsis=False)
        self.assertTrue(is_fsnative(new))
        self.assertEqual(len(new), 255)
        self.assertTrue(new.endswith(fsnative(u"xx.ext")))

        new = limit_path(path)
        self.assertTrue(is_fsnative(new))
        self.assertEqual(len(new), 255)
        self.assertTrue(new.endswith(fsnative(u"...ext")))

        self.assertTrue(is_fsnative(limit_path(fsnative())))
        self.assertEqual(limit_path(fsnative()), fsnative())
开发者ID:gbtami,项目名称:quodlibet,代码行数:23,代码来源:test_util_path.py


示例18: fromsongs

    def fromsongs(cls, dir_, songs, library=None):
        assert is_fsnative(dir_)

        if len(songs) == 1:
            title = songs[0].comma("title")
        else:
            title = ngettext(
                "%(title)s and %(count)d more",
                "%(title)s and %(count)d more",
                len(songs) - 1) % (
                    {'title': songs[0].comma("title"),
                     'count': len(songs) - 1})

        playlist = cls.new(dir_, title, library)
        playlist.extend(songs)
        return playlist
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:16,代码来源:collection.py


示例19: set_file

    def set_file(self, fileobj):
        if fileobj is None:
            path = None
        else:
            path = fileobj.name
            assert is_fsnative(path)

        # XXX: Don't reload if the file path is the same.
        # Could prevent updates if fileobj.name isn't defined
        if self._path == path:
            return

        self._file = fileobj
        self._path = path
        self._dirty = True
        self.queue_resize()
开发者ID:kriskielce88,项目名称:xn--ls8h,代码行数:16,代码来源:cover.py


示例20: go_to

    def go_to(self, path_to_go):
        assert is_fsnative(path_to_go)

        # FIXME: what about non-normalized paths?
        model = self.get_model()

        # Find the top level row which has the largest common
        # path with the path we want to go to
        roots = dict([(p, i) for (i, p) in model.iterrows(None)])
        head, tail = path_to_go, fsnative(u"")
        to_find = []
        while head and head not in roots:
            new_head, tail = os.path.split(head)
            # this can happen for invalid paths on Windows
            if head == new_head:
                break
            head = new_head
            to_find.append(tail)
        if head not in roots:
            return
        start_iter = roots[head]

        # expand until we find the right directory or the last valid one
        # and select/scroll to it
        def search(view, model, iter_, to_find):
            tree_path = model.get_path(iter_)

            # we are where we want, select and scroll
            if not to_find:
                view.set_cursor(tree_path)
                view.scroll_to_cell(tree_path)
                return

            # expand the row
            view.expand_row(tree_path, False)

            next_ = to_find.pop(-1)
            for sub_iter, path in model.iterrows(iter_):
                if os.path.basename(path) == next_:
                    search(view, model, sub_iter, to_find)
                    break
            else:
                # we haven't found the right sub folder, select the parent
                # and stop
                search(view, model, iter_, [])

        search(self, model, start_iter, to_find)
开发者ID:qwence,项目名称:quodlibet,代码行数:47,代码来源:filesel.py



注:本文中的quodlibet.util.path.is_fsnative函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python path.iscommand函数代码示例发布时间:2022-05-26
下一篇:
Python path.get_temp_cover_file函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap