本文整理汇总了Python中quodlibet.util.path.normalize_path函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_path函数的具体用法?Python normalize_path怎么用?Python normalize_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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
示例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())
示例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))
示例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))
示例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"
})
示例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
示例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))
示例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)
示例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)
示例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)
示例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)
示例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
示例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"))