本文整理汇总了Python中senf.path2fsn函数的典型用法代码示例。如果您正苦于以下问题:Python path2fsn函数的具体用法?Python path2fsn怎么用?Python path2fsn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了path2fsn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: call
def call(args):
args = [path2fsn(a) for a in args]
with capture_output() as (out, err):
try:
return_code = operon_main([path2fsn("operon.py")] + args)
except SystemExit as e:
return_code = e.code
return (return_code, out.getvalue(), err.getvalue())
开发者ID:LudoBike,项目名称:quodlibet,代码行数:9,代码来源:test_operon.py
示例2: get_available_languages
def get_available_languages(domain):
"""Returns a list of available translations for a given gettext domain.
Args:
domain (str)
Returns:
List[text_type]
"""
locale_dir = gettext.bindtextdomain(domain)
if locale_dir is None:
return []
try:
entries = os.listdir(locale_dir)
except OSError:
return []
langs = [u"C"]
for lang in entries:
mo_path = os.path.join(
locale_dir, lang, "LC_MESSAGES", "%s.mo" % domain)
if os.path.exists(mo_path):
langs.append(fsn2text(path2fsn(lang)))
return langs
开发者ID:elfalem,项目名称:quodlibet,代码行数:25,代码来源:i18n.py
示例3: print_exc
def print_exc(exc_info=None, context=None):
"""Prints the stack trace of the current exception or the passed one.
Depending on the configuration will either print a short summary or the
whole stacktrace.
"""
if exc_info is None:
exc_info = sys.exc_info()
etype, value, tb = exc_info
if const.DEBUG:
string = u"".join(format_exception(etype, value, tb))
else:
# try to get a short error message pointing at the cause of
# the exception
text = u"".join(format_exception_only(etype, value))
try:
filename, lineno, name, line = extract_tb(tb)[-1]
except IndexError:
# no stack
string = text
else:
string = u"%s:%s:%s: %s" % (
fsn2text(path2fsn(os.path.basename(filename))),
lineno, name, text)
_print_message(string, context, False, "E", "red", "errors")
开发者ID:elfalem,项目名称:quodlibet,代码行数:28,代码来源:dprint.py
示例4: get_user_dir
def get_user_dir():
"""Place where QL saves its state, database, config etc."""
if os.name == "nt":
USERDIR = os.path.join(windows.get_appdata_dir(), "Quod Libet")
elif is_osx():
USERDIR = os.path.join(os.path.expanduser("~"), ".quodlibet")
else:
USERDIR = os.path.join(xdg_get_config_home(), "quodlibet")
if not os.path.exists(USERDIR):
tmp = os.path.join(os.path.expanduser("~"), ".quodlibet")
if os.path.exists(tmp):
USERDIR = tmp
if 'QUODLIBET_USERDIR' in environ:
USERDIR = environ['QUODLIBET_USERDIR']
if build.BUILD_TYPE == u"windows-portable":
USERDIR = os.path.normpath(os.path.join(
os.path.dirname(path2fsn(sys.executable)), "..", "..", "config"))
# XXX: users shouldn't assume the dir is there, but we currently do in
# some places
mkdir(USERDIR, 0o750)
return USERDIR
开发者ID:zsau,项目名称:quodlibet,代码行数:27,代码来源:_main.py
示例5: __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 isinstance(value, fsnative):
value = path2fsn(value)
return value
开发者ID:zsau,项目名称:quodlibet,代码行数:8,代码来源:remote.py
示例6: get_devices_from_path
def get_devices_from_path(udev_ctx, path):
"""A list of device attribute dicts for the given device path and all its
parents.
Either returns a non empty list or raises EnvironmentError.
"""
path = fsn2bytes(path2fsn(path), None)
enum = udev.UdevEnumerate.new(udev_ctx)
if not enum:
raise EnvironmentError
# only match the device we want
if enum.add_match_property(b"DEVNAME", path) != 0:
enum.unref()
raise EnvironmentError
# search for it
if enum.scan_devices() != 0:
enum.unref()
raise EnvironmentError
# take the first entry
entry = enum.get_list_entry()
if not entry:
enum.unref()
raise EnvironmentError
sys_path = entry.get_name()
enum.unref()
device = udev.UdevDevice.new_from_syspath(udev_ctx, sys_path)
if not device:
raise EnvironmentError
devices = []
while device:
devices.append(device)
device = device.get_parent()
device_attrs = []
for device in devices:
entry = device.get_properties_list_entry()
if not entry:
continue
attrs = {}
for e in entry:
name = e.get_name()
value = e.get_value()
attrs[name] = escape_decode(value)
device_attrs.append(attrs)
# the first device owns its parents
devices[0].unref()
return device_attrs
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:57,代码来源:__init__.py
示例7: _normalize_path
def _normalize_path(filename, canonicalise=False):
"""Normalize a path on Windows / Linux
If `canonicalise` is True, dereference symlinks etc
by calling `os.path.realpath`
"""
filename = path2fsn(filename)
if canonicalise:
filename = os.path.realpath(filename)
filename = os.path.normpath(filename)
return os.path.normcase(filename)
开发者ID:elfalem,项目名称:quodlibet,代码行数:10,代码来源:path.py
示例8: get_module_dir
def get_module_dir(module=None):
"""Returns the absolute path of a module. If no module is given
the one this is called from is used.
"""
if module is None:
file_path = sys._getframe(1).f_globals["__file__"]
else:
file_path = getattr(module, "__file__")
file_path = path2fsn(file_path)
return os.path.dirname(os.path.realpath(file_path))
开发者ID:zsau,项目名称:quodlibet,代码行数:11,代码来源:misc.py
示例9: __init__
def __init__(self, parent, path):
title = _("File exists")
fn_format = "<b>%s</b>" % util.escape(fsn2text(path2fsn(path)))
description = _("Replace %(file-name)s?") % {"file-name": fn_format}
super(ConfirmFileReplace, self).__init__(
parent, title, description, buttons=Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Replace File"), Icons.DOCUMENT_SAVE,
self.RESPONSE_REPLACE)
self.set_default_response(Gtk.ResponseType.CANCEL)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:12,代码来源:msg.py
示例10: parse_m3u
def parse_m3u(filename, library=None):
plname = fsn2text(path2fsn(os.path.basename(
os.path.splitext(filename)[0])))
filenames = []
with open(filename, "rb") as h:
for line in h:
line = line.strip()
if line.startswith("#"):
continue
else:
filenames.append(line)
return __parse_playlist(plname, filename, filenames, library)
开发者ID:urielz,项目名称:quodlibet,代码行数:14,代码来源:util.py
示例11: open_chooser
def open_chooser(self, action):
if action.get_name() == "AddFolders":
fns = choose_folders(self, _("Add Music"), _("_Add Folders"))
if fns:
# scan them
copool.add(self.__library.scan, fns, cofuncid="library",
funcid="library")
else:
patterns = ["*" + path2fsn(k) for k in formats.loaders.keys()]
choose_filter = create_chooser_filter(_("Music Files"), patterns)
fns = choose_files(
self, _("Add Music"), _("_Add Files"), choose_filter)
if fns:
for filename in fns:
self.__library.add_filename(filename)
开发者ID:zsau,项目名称:quodlibet,代码行数:15,代码来源:quodlibetwindow.py
示例12: __init__
def __init__(self, filename):
with translate_errors():
with open(filename, "rb") as h:
head = h.read(46)
if len(head) != 46 or \
head[:27] != b'SNES-SPC700 Sound File Data':
raise IOError("Not a valid SNES-SPC700 file")
if getbyte(head, 35) == b'\x1a':
data = h.read(210)
if len(data) == 210:
self.update(parse_id666(data))
self.setdefault(
"title", fsn2text(path2fsn(os.path.basename(filename)[:-4])))
self.sanitize(filename)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:16,代码来源:spc.py
示例13: _normalize_darwin_path
def _normalize_darwin_path(filename, canonicalise=False):
filename = path2fsn(filename)
if canonicalise:
filename = os.path.realpath(filename)
filename = os.path.normpath(filename)
data = fsn2bytes(filename, "utf-8")
decoded = data.decode("utf-8", "quodlibet-osx-path-decode")
try:
return bytes2fsn(
NSString.fileSystemRepresentation(decoded), "utf-8")
except ValueError:
return filename
开发者ID:elfalem,项目名称:quodlibet,代码行数:16,代码来源:path.py
示例14: create_chooser_filter
def create_chooser_filter(name, patterns):
"""Create a Gtk.FileFilter that also works on Windows
Args:
name (str): The name of the filter
patterns (List[pathlike]): A list of glob patterns
Returns:
Gtk.FileFilter
"""
# The Windows FileChooserNative implementation only supports patterns
filter_ = Gtk.FileFilter()
filter_.set_name(name)
for pattern in sorted(set(patterns)):
filter_.add_pattern(fsn2glib(path2fsn(pattern)))
return filter_
开发者ID:zsau,项目名称:quodlibet,代码行数:16,代码来源:chooser.py
示例15: extract_tb
def extract_tb(*args, **kwargs):
"""Returns a list of tuples containing
(fsnative, int, text_type, text_type)
"""
tp = traceback.extract_tb(*args, **kwargs)
if not PY2:
return tp
result = []
for filename, line_number, function_name, text in tp:
filename = path2fsn(filename)
function_name = decode(function_name)
text = decode(text or u"")
result.append((filename, line_number, function_name, text))
return result
开发者ID:elfalem,项目名称:quodlibet,代码行数:17,代码来源:dprint.py
示例16: parse_m3u
def parse_m3u(filename, library=None):
plname = fsn2text(path2fsn(os.path.basename(
os.path.splitext(filename)[0])))
filenames = []
with open(filename, "rb") as h:
for line in h:
line = line.strip()
if line.startswith(b"#"):
continue
else:
try:
filenames.append(bytes2fsn(line, "utf-8"))
except ValueError:
continue
return __parse_playlist(plname, filename, filenames, library)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:17,代码来源:util.py
示例17: parse_pls
def parse_pls(filename, name="", library=None):
plname = fsn2text(path2fsn(os.path.basename(
os.path.splitext(filename)[0])))
filenames = []
with open(filename) as h:
for line in h:
line = line.strip()
if not line.lower().startswith("file"):
continue
else:
try:
line = line[line.index("=") + 1:].strip()
except ValueError:
pass
else:
filenames.append(line)
return __parse_playlist(plname, filename, filenames, library)
开发者ID:urielz,项目名称:quodlibet,代码行数:18,代码来源:util.py
示例18: __setitem__
def __setitem__(self, key, value):
# validate key
if not isinstance(key, str):
raise TypeError("key has to be str")
# validate value
if key.startswith("~#"):
if not isinstance(value, (int, float)):
raise TypeError
elif key in FILESYSTEM_TAGS:
if not isinstance(value, fsnative):
value = path2fsn(value)
else:
value = str(value)
dict.__setitem__(self, key, value)
pop = self.__dict__.pop
pop("album_key", None)
pop("sort_key", None)
开发者ID:zsau,项目名称:quodlibet,代码行数:20,代码来源:_audio.py
示例19: get_available_languages
def get_available_languages(domain):
"""Returns a set of available translations for a given gettext domain.
Args:
domain (str)
Returns:
Set[text_type]
"""
langs = set(["C"])
for locale_dir in iter_locale_dirs():
try:
entries = os.listdir(locale_dir)
except OSError:
continue
for lang in entries:
mo_path = os.path.join(
locale_dir, lang, "LC_MESSAGES", "%s.mo" % domain)
if os.path.exists(mo_path):
langs.add(fsn2text(path2fsn(lang)))
return langs
开发者ID:LudoBike,项目名称:quodlibet,代码行数:24,代码来源:i18n.py
示例20: __setitem__
def __setitem__(self, key, value):
# validate key
if PY3:
if not isinstance(key, text_type):
raise TypeError("key has to be str")
else:
if isinstance(key, text_type):
# we try to save keys as encoded ASCII to save memory
# under PY2. Everything else besides ASCII combined with
# unicode breaks hashing even if the default encoding
# it utf-8.
try:
key = key.encode("ascii")
except UnicodeEncodeError:
pass
elif isinstance(key, bytes):
# make sure we set ascii keys only
key.decode("ascii")
else:
raise TypeError("key needs to be unicode or ASCII str")
# validate value
if key.startswith("~#"):
if not isinstance(value, number_types):
raise TypeError
elif key in FILESYSTEM_TAGS:
if not isinstance(value, fsnative):
value = path2fsn(value)
else:
value = text_type(value)
dict.__setitem__(self, key, value)
pop = self.__dict__.pop
pop("album_key", None)
pop("sort_key", None)
开发者ID:elfalem,项目名称:quodlibet,代码行数:36,代码来源:_audio.py
注:本文中的senf.path2fsn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论