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


Python path.fsnative函数代码示例

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


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

示例1: test_conv

 def test_conv(self):
     empty = fsnative(u"")
     in_ = fsnative(u"foo \u00c1 \u1234")
     out = fsnative(u"foo _ _")
     v = self.c.filter(empty, in_)
     self.failUnlessEqual(v, out)
     self.failUnless(is_fsnative(v))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:7,代码来源:test_qltk_renamefiles.py

示例2: test_disctrack

 def test_disctrack(self):
     pat = TagsFromPattern('<discnumber><tracknumber>. <title>')
     self.assertEquals(pat.match_path(fsnative(u'101. T1.ogg')),
         dict(discnumber='1', tracknumber='01', title='T1'))
     self.assertEquals(pat.match_path(fsnative(u'1318. T18.ogg')),
         dict(discnumber='13', tracknumber='18', title='T18'))
     self.assertEquals(pat.match_path(fsnative(u'24. T4.ogg')),
         dict(discnumber='2', tracknumber='4', title='T4'))
开发者ID:bp0,项目名称:quodlibet,代码行数:8,代码来源:test_util_tagsfrompath.py

示例3: 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

示例4: test_uri_from_path

 def test_uri_from_path(self):
     if os.name != "nt":
         uri = uri_from_path(fsnative(u"/öäü.txt"))
         self.assertEqual(uri, u"file:///%C3%B6%C3%A4%C3%BC.txt")
     else:
         uri = uri_from_path(fsnative(u"C:\\öäü.txt"))
         self.assertEqual(
             uri, "file:///C:/%C3%B6%C3%A4%C3%BC.txt")
         self.assertEqual(
             uri_from_path(u"C:\\SomeDir\xe4"), "file:///C:/SomeDir%C3%A4")
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:10,代码来源:test_util_path.py

示例5: 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

示例6: 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

示例7: init_test_environ

def init_test_environ():
    """This needs to be called before any test can be run.

    Before exiting the process call exit_test_environ() to clean up
    any resources created.
    """

    global _TEMP_DIR, _BUS_INFO

    # create a user dir in /tmp and set env vars
    _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-"))

    # needed for dbus/dconf
    runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR)
    os.chmod(runtime_dir, 0o700)
    environ["XDG_RUNTIME_DIR"] = runtime_dir

    # force the old cache dir so that GStreamer can re-use the GstRegistry
    # cache file
    environ["XDG_CACHE_HOME"] = xdg_get_cache_home()
    # GStreamer will update the cache if the environment has changed
    # (in Gst.init()). Since it takes 0.5s here and doesn't add much,
    # disable it. If the registry cache is missing it will be created
    # despite this setting.
    environ["GST_REGISTRY_UPDATE"] = fsnative(u"no")

    # set HOME and remove all XDG vars that default to it if not set
    home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR)
    environ["HOME"] = home_dir

    # set to new default
    environ.pop("XDG_DATA_HOME", None)

    _BUS_INFO = None
    if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ:
        try:
            out = subprocess.check_output(["dbus-launch"])
        except (subprocess.CalledProcessError, OSError):
            pass
        else:
            if PY3:
                out = out.decode("ascii")
            _BUS_INFO = dict([l.split("=", 1) for l in out.splitlines()])
            environ.update(_BUS_INFO)

    # Ideally nothing should touch the FS on import, but we do atm..
    # Get rid of all modules so QUODLIBET_USERDIR gets used everywhere.
    for key in list(sys.modules.keys()):
        if key.startswith('quodlibet'):
            del(sys.modules[key])

    import quodlibet
    quodlibet.init(no_translations=True, no_excepthook=True)
    quodlibet.app.name = "QL Tests"
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:54,代码来源:__init__.py

示例8: test_masked_handling

    def test_masked_handling(self):
        if os.name == "nt":
            # FIXME: masking isn't properly implemented on Windows
            return
        # playlists can contain songs and paths for masked handling..
        lib = FileLibrary("foobar")
        pl = Playlist(self.temp, "playlist", lib)
        song = Fakesong({"date": "2038", "~filename": fsnative(u"/fake")})
        song.sanitize()
        lib.add([song])

        # mask and update
        lib.mask("/")
        pl.append(song)
        pl.remove_songs([song])
        self.failUnless("/fake" in pl)

        pl.extend(self.TWO_SONGS)

        # check if collections can handle the mix
        self.failUnlessEqual(pl("date"), "2038")

        # unmask and update
        lib.unmask("/")
        pl.add_songs(["/fake"], lib)
        self.failUnless(song in pl)

        pl.delete()
        lib.destroy()
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:29,代码来源:test_util_collection.py

示例9: _post

    def _post(self, value, song, keep_extension=True):
        if value:
            assert isinstance(value, unicode)
            value = fsnative(value)

            if keep_extension:
                fn = song.get("~filename", ".")
                ext = fn[fn.rfind("."):].lower()
                val_ext = value[-len(ext):].lower()
                if not ext == val_ext:
                    value += ext.lower()

            if os.name == "nt":
                assert isinstance(value, unicode)
                value = strip_win32_incompat_from_path(value)

            value = expanduser(value)

            # Limit each path section to 255 (bytes on linux, chars on win).
            # http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
            path, ext = os.path.splitext(value)
            path = path.split(sep)
            limit = [255] * len(path)
            limit[-1] -= len(ext)
            elip = lambda (p, l): (len(p) > l and p[:l - 2] + "..") or p
            path = sep.join(map(elip, zip(path, limit)))
            value = path + ext

            if sep in value and not os.path.isabs(value):
                raise ValueError("Pattern is not rooted")
        return value
开发者ID:kriskielce88,项目名称:xn--ls8h,代码行数:31,代码来源:_pattern.py

示例10: test_embedded_special_cover_words

    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(u"tests/data/asong.ogg"),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        files = [self.full_path(f) for f in
                 ['back.jpg',
                  'discovery.jpg', "Pharell - frontin'.jpg",
                  'nickelback - Curb.jpg',
                  'foobar.jpg', 'folder.jpg',     # Though this is debatable
                  'Q-Man - foobar.jpg', 'Q-man - foobar (cover).jpg']]
        for f in files:
            file(f, "w").close()
            self.files.append(f)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                self.failUnlessEqual(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failUnless(f, self.full_path('back.jpg'))
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:27,代码来源:test_util_cover.py

示例11: test_rename_to_existing

 def test_rename_to_existing(self):
     quux.rename(quux("~basename"))
     if os.name != "nt":
         self.failUnlessRaises(
             ValueError, quux.rename, fsnative(u"/dev/null"))
     self.failUnlessRaises(ValueError, quux.rename,
                           os.path.join(DATA_DIR, "silence-44-s.ogg"))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py

示例12: test_main

 def test_main(self):
     self.assertEqual(decode_value("~#foo", 0.25), u"0.25")
     self.assertEqual(decode_value("~#foo", 4), u"4")
     self.assertEqual(decode_value("~#foo", "bar"), u"bar")
     self.assertTrue(isinstance(decode_value("~#foo", "bar"), unicode))
     path = fsnative(u"/foobar")
     self.assertEqual(decode_value("~filename", path), fsdecode(path))
开发者ID:pyromaniac2k,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py

示例13: test_embedded_special_cover_words

    def test_embedded_special_cover_words(self):
        """Tests that words incidentally containing embedded "special" words
        album keywords (e.g. cover, disc, back) don't trigger
        See Issue 818"""

        song = AudioFile({
            "~filename": fsnative(os.path.join(self.dir, u"asong.ogg")),
            "album": "foobar",
            "title": "Ode to Baz",
            "artist": "Q-Man",
        })
        data = [('back.jpg', False),
                ('discovery.jpg', False),
                ("Pharell - frontin'.jpg", False),
                ('nickelback - Curb.jpg', False),
                ('foobar.jpg', True),
                ('folder.jpg', True),  # Though this order is debatable
                ('Q-Man - foobar.jpg', True),
                ('Q-man - foobar (cover).jpg', True)]
        for fn, should_find in data:
            f = self.add_file(fn)
            cover = self._find_cover(song)
            if cover:
                actual = os.path.abspath(cover.name)
                self.failUnlessEqual(
                    actual, f, "\"%s\" should trump \"%s\"" % (f, actual))
            else:
                self.failIf(should_find, msg="Couldn't find %s for %s" %
                                             (f, song("~filename")))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:29,代码来源:test_util_cover.py

示例14: lyric_filename

    def lyric_filename(self):
        """Returns the (potential) lyrics filename for this file"""

        filename = self.comma("title").replace(u"/", u"")[:128] + u".lyric"
        sub_dir = (self.comma("lyricist") or self.comma("artist")).replace(u"/", u"")[:128]

        if os.name == "nt":
            # this was added at a later point. only use escape_filename here
            # to keep the linux case the same as before
            filename = escape_filename(filename)
            sub_dir = escape_filename(sub_dir)
        else:
            filename = fsnative(filename)
            sub_dir = fsnative(sub_dir)

        path = os.path.join(expanduser(fsnative(u"~/.lyrics")), sub_dir, filename)
        return path
开发者ID:pfps,项目名称:quodlibet,代码行数:17,代码来源:_audio.py

示例15: test_write

    def test_write(self):
        with self.wrap("playlist") as pl:
            pl.extend(NUMERIC_SONGS)
            pl.extend([fsnative(u"xf0xf0")])
            pl.write()

            with open(pl.filename, "rb") as h:
                self.assertEqual(len(h.read().splitlines()), len(NUMERIC_SONGS) + 1)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:8,代码来源:test_util_collection.py


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