当前位置: 首页>>代码示例>>Python>>正文


Python path.is_fsnative函数代码示例

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


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


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