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

Python path.normalize_path函数代码示例

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

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



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

示例1: test_types

    def test_types(self):
        from quodlibet.util.path import normalize_path

        assert isinstance(normalize_path(fsnative(u"foo"), False), fsnative)
        assert isinstance(normalize_path("foo", False), fsnative)
        assert isinstance(normalize_path(fsnative(u"foo"), True), fsnative)
        assert isinstance(normalize_path("foo", True), fsnative)
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:test_util.py


示例2: __find_songs

 def __find_songs(self, selection):
     model, rows = selection.get_selected_rows()
     dirs = [model[row][0] for row in rows]
     songs = []
     to_add = []
     for dir in dirs:
         try:
             for file in filter(formats.filter,
                                sorted(os.listdir(dir))):
                 raw_path = os.path.join(dir, file)
                 fn = normalize_path(raw_path, canonicalise=True)
                 if fn in self.__glibrary:
                     songs.append(self.__glibrary[fn])
                 elif fn not in self.__library:
                     song = formats.MusicFile(fn)
                     if song:
                         to_add.append(song)
                         songs.append(song)
                         yield songs
                 if fn in self.__library:
                     song = self.__library[fn]
                     if not song.valid():
                         self.__library.reload(song)
                     if song in self.__library:
                         songs.append(song)
         except OSError:
             pass
     self.__library.add(to_add)
     yield songs
开发者ID:faubiguy,项目名称:quodlibet,代码行数:29,代码来源:filesystem.py


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


示例4: __popup_menu

    def __popup_menu(self, view, fs):
        # get all songs for the selection
        filenames = [normalize_path(f, canonicalise=True)
                     for f in fs.get_selected_paths()]
        maybe_songs = [self.__library.get(f) for f in filenames]
        songs = [s for s in maybe_songs if s]

        if songs:
            menu = self.pm.Menu(self.__library, songs)
            if menu is None:
                menu = Gtk.Menu()
            else:
                menu.prepend(SeparatorMenuItem())
        else:
            menu = Gtk.Menu()

        b = TrashMenuItem()
        b.connect('activate', self.__delete, filenames, fs)
        menu.prepend(b)

        def selection_done_cb(menu):
            menu.destroy()

        menu.connect('selection-done', selection_done_cb)
        menu.show_all()
        return view.popup_menu(menu, 0, Gtk.get_current_event_time())
开发者ID:mistotebe,项目名称:quodlibet,代码行数:26,代码来源:exfalsowindow.py


示例5: test_file_encoding

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

        f = self.add_file(bytes2fsn(b"\xff\xff\xff\xff - cover.jpg", None))
        self.assertTrue(isinstance(self.song("album"), text_type))
        h = self._find_cover(self.song)
        self.assertEqual(h.name, normalize_path(f))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:8,代码来源:test_util_cover.py


示例6: test_file_encoding

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

        f = self.add_file("\xff\xff\xff\xff - cover.jpg")
        self.assertTrue(isinstance(quux("album"), unicode))
        h = self._find_cover(quux)
        self.assertEqual(h.name, normalize_path(f))
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:8,代码来源:test_util_cover.py


示例7: setUp

 def setUp(self):
     config.RATINGS = config.HardCodedRatingsPrefs()
     fd, filename = mkstemp()
     os.close(fd)
     self.quux = AudioFile({
         "~filename": normalize_path(filename, True),
         "album": u"Quuxly"
     })
开发者ID:Muges,项目名称:quodlibet,代码行数:8,代码来源:test_formats__audio.py


示例8: 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 listitems(self):
            self[key] = val
            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 NUMERIC_ZERO_DEFAULT and val == 0:
                del self[key]

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

        assert isinstance(self["~filename"], fsnative)

        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 fsnative(u"/")
                if 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:elfalem,项目名称:quodlibet,代码行数:58,代码来源:_audio.py


示例9: test_file_encoding

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

        f = self.full_path("\xff\xff\xff\xff - cover.jpg")
        file(f, "w").close()
        self.files.append(f)
        self.assertTrue(isinstance(quux("album"), unicode))
        h = self._find_cover(quux)
        self.assertEqual(h.name, normalize_path(f))
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:10,代码来源:test_util_cover.py


示例10: endElement

    def endElement(self, name):
        self._tag = None
        if name == "entry" and self._current is not None:
            current = self._current
            self._current = None
            if len(current) > 1:
                uri = current.pop("location", "")
                try:
                    filename = uri2fsn(uri)
                except ValueError:
                    return

                self._process_song(normalize_path(filename), current)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:13,代码来源:rbimport.py


示例11: rename

    def rename(self, newname):
        """Rename a file. Errors are not handled. This shouldn't be used
        directly; use library.rename instead."""

        if os.path.isabs(newname):
            mkdir(os.path.dirname(newname))
        else:
            newname = os.path.join(self('~dirname'), newname)

        if not os.path.exists(newname):
            shutil.move(self['~filename'], newname)
        elif normalize_path(newname, canonicalise=True) != self['~filename']:
            raise ValueError

        self.sanitize(newname)
开发者ID:elfalem,项目名称:quodlibet,代码行数:15,代码来源:_audio.py


示例12: select

        def select(model, path, iter_, paths_):
            (paths, first) = paths_
            value = model.get_value(iter_)
            if value is None:
                return not bool(paths)
            value = normalize_path(value)

            if value in paths:
                self.get_child().get_selection().select_path(path)
                paths.remove(value)
                if not first:
                    self.get_child().set_cursor(path)
                    # copy treepath, gets invalid after the callback
                    first.append(path.copy())
            else:
                for fpath in paths:
                    if fpath.startswith(value):
                        self.get_child().expand_row(path, False)
            return not bool(paths)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:19,代码来源:filesystem.py


示例13: __select_paths

    def __select_paths(self, paths):
        # AudioFile uses normalized paths, DirectoryTree doesn't

        paths = map(normalize_path, paths)

        def select(model, path, iter_, (paths, first)):
            value = model.get_value(iter_)
            if value is None:
                return not bool(paths)
            value = normalize_path(value)

            if value in paths:
                self.get_child().get_selection().select_path(path)
                paths.remove(value)
                if not first:
                    self.get_child().set_cursor(path)
                    # copy treepath, gets invalid after the callback
                    first.append(path.copy())
            else:
                for fpath in paths:
                    if fpath.startswith(value):
                        self.get_child().expand_row(path, False)
            return not bool(paths)
开发者ID:vrasidas,项目名称:quodlibet,代码行数:23,代码来源:filesystem.py


示例14: add_filename

    def add_filename(self, filename, add=True):
        """Add a song to the library based on filename.

        If 'add' is true, the song will be added and the 'added' signal
        may be fired.

        Example (add=False):
            load many songs and call Library.add(songs) to add all in one go.

        The song is returned if it is in the library after this call.
        Otherwise, None is returned.
        """

        key = normalize_path(filename, True)
        song = None
        if key not in self._contents:
            song = MusicFile(filename)
            if song and add:
                self.add([song])
        else:
            print_d("Already got file %r." % filename)
            song = self._contents[key]

        return song
开发者ID:kriskielce88,项目名称:xn--ls8h,代码行数:24,代码来源:libraries.py


示例15: test_get_link_target

 def test_get_link_target(self):
     path = os.path.join(DATA_DIR, "test.lnk")
     d = windows.get_link_target(path)
     self.assertTrue(isinstance(d, unicode))
     self.assertEqual(
         normalize_path(d), normalize_path(u"C:\Windows\explorer.exe"))
开发者ID:funkyfuture,项目名称:quodlibet,代码行数:6,代码来源:test_windows.py


示例16: dummy_path

def dummy_path(path):
    path = fsnative(path)
    if os.name == "nt":
        return normalize_path(u"z:\\" + path.replace(u"/", u"\\"))
    return path
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:5,代码来源:helper.py


示例17: get_filename

 def get_filename(self, filename):
     key = normalize_path(filename, True)
     return self._contents.get(key)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:3,代码来源:libraries.py


示例18: contains_filename

 def contains_filename(self, filename):
     key = normalize_path(filename, True)
     return key in self._contents
开发者ID:LudoBike,项目名称:quodlibet,代码行数:3,代码来源:libraries.py


示例19: test_file_encoding

 def test_file_encoding(self):
     f = self.add_file(fsnative(u"öäü - cover.jpg"))
     self.assertTrue(isinstance(self.song("album"), text_type))
     h = self._find_cover(self.song)
     self.assertEqual(normalize_path(h.name), normalize_path(f))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:5,代码来源:test_util_cover.py


示例20: test_get_link_target

 def test_get_link_target(self):
     path = get_data_path("test.lnk")
     d = windows.get_link_target(path)
     self.assertTrue(isinstance(d, text_type))
     self.assertEqual(
         normalize_path(d), normalize_path(u"C:\\Windows\\explorer.exe"))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:6,代码来源:test_windows.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python path.unexpand函数代码示例发布时间:2022-05-26
下一篇:
Python path.mtime函数代码示例发布时间: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