本文整理汇总了Python中util.path函数的典型用法代码示例。如果您正苦于以下问题:Python path函数的具体用法?Python path怎么用?Python path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: builder
def builder(srcdir):
"""
:param str srcdir: app.srcdir
"""
srcdir = path(srcdir)
for dirpath, dirs, files in os.walk(srcdir):
dirpath = path(dirpath)
for f in [f for f in files if f.endswith('.po')]:
po = dirpath / f
mo = srcdir / 'xx' / 'LC_MESSAGES' / (
os.path.relpath(po[:-3], srcdir) + '.mo')
if not mo.parent.exists():
mo.parent.makedirs()
write_mo(mo, read_po(po))
示例2: setup_module
def setup_module():
if not root.exists():
(rootdir / 'roots' / 'test-intl').copytree(root)
# Delete remnants left over after failed build
# Compile all required catalogs into binary format (*.mo).
for dirpath, dirs, files in os.walk(root):
dirpath = path(dirpath)
for f in [f for f in files if f.endswith('.po')]:
po = dirpath / f
mo = root / 'xx' / 'LC_MESSAGES' / (
os.path.relpath(po[:-3], root) + '.mo')
if not mo.parent.exists():
mo.parent.makedirs()
try:
p = Popen(['msgfmt', po, '-o', mo],
stdout=PIPE, stderr=PIPE)
except OSError:
raise SkipTest # most likely msgfmt was not found
else:
stdout, stderr = p.communicate()
if p.returncode != 0:
print(stdout)
print(stderr)
assert False, \
'msgfmt exited with return code %s' % p.returncode
assert mo.isfile(), 'msgfmt failed'
示例3: __init__
def __init__(self, meta, p):
self.p = p
path_builder = path("{topdir}/{p}")
self.path_builder = path_builder.fill(topdir=meta.topdir, p=self.p)
self.key = key.key(p=p)
# perparam differs from meta
self.ndims = meta.params[self.p]
self.allzs = meta.allzs[:self.ndims+1]#sorted(set(self.zlos+self.zhis))
self.zlos = self.allzs[:-1]#meta.allzlos[:self.ndims]
self.zhis = self.allzs[1:]#meta.allzhis[:self.ndims]
self.zmids = (self.zlos+self.zhis)/2.
self.zavg = sum(self.zmids)/self.ndims
# define realistic underlying P(z) for this number of parameters
self.realsum = sum(meta.realistic[:self.ndims])
self.realistic_pdf = np.array([meta.realistic[k]/self.realsum/meta.zdifs[k] for k in xrange(0,self.ndims)])
self.truePz = self.realistic_pdf
self.logtruePz = np.array([m.log(max(tPz,sys.float_info.epsilon)) for tPz in self.truePz])
# define flat P(z) for this number of parameters
self.avgprob = 1./self.ndims/meta.zdif
self.logavgprob = m.log(self.avgprob)
self.flatPz = [self.avgprob]*self.ndims
self.logflatPz = [self.logavgprob]*self.ndims
print('initialized '+str(self.ndims)+' parameter test')
示例4: test_multibyte_path
def test_multibyte_path(app):
srcdir = path(app.srcdir)
mb_name = u"\u65e5\u672c\u8a9e"
(srcdir / mb_name).makedirs()
(srcdir / mb_name / (mb_name + ".txt")).write_text(
dedent(
"""
multi byte file name page
==========================
"""
)
)
master_doc = srcdir / "contents.txt"
master_doc.write_bytes(
(
master_doc.text()
+ dedent(
"""
.. toctree::
%(mb_name)s/%(mb_name)s
"""
% locals()
)
).encode("utf-8")
)
app.builder.build_all()
示例5: groupDocument
def groupDocument(self, doc):
"""Called, if grouping is enabled, to group the document."""
i = self._items[doc]
p = util.path(doc.url())
new_parent = self._paths.get(p)
if new_parent is None:
new_parent = self._paths[p] = QTreeWidgetItem(self)
new_parent._path = p
new_parent.setText(0, p or _("Untitled"))
new_parent.setIcon(0, icons.get("folder-open"))
new_parent.setFlags(Qt.ItemIsEnabled)
new_parent.setExpanded(True)
self.sortItems(0, Qt.AscendingOrder)
old_parent = i.parent()
if old_parent == new_parent:
return
if old_parent:
old_parent.takeChild(old_parent.indexOfChild(i))
if old_parent.childCount() == 0:
self.takeTopLevelItem(self.indexOfTopLevelItem(old_parent))
del self._paths[old_parent._path]
else:
self.takeTopLevelItem(self.indexOfTopLevelItem(i))
new_parent.addChild(i)
new_parent.sortChildren(0, Qt.AscendingOrder)
示例6: _script_names
def _script_names(src_dir):
if not src_dir:
return []
is_script = lambda f: isfile(path(src_dir, f)) and f.endswith('.sh')
return [f for f in listdir(src_dir) if is_script(f)]
示例7: db_connect
def db_connect(password):
db = dbapi2.connect(path(app.config['DB_NAME']))
# TODO: Use something better than re.escape for this
# For some reason, normal '?' placeholders don't work for PRAGMA's
db.execute("PRAGMA key = '%s'" % re.escape(password))
db.execute("PRAGMA foreign_keys = ON")
return db
示例8: _get_db_log_path
def _get_db_log_path(conf):
logs = []
if conf.db_logs_dir:
log_file_path = lambda f : path(conf.db_logs_dir) + f
collect_logs = conf.db_logs_files if conf.db_logs_files else ls(conf.db_logs_dir)
for file in collect_logs:
logs.append(log_file_path(file))
return logs
示例9: setDocumentStatus
def setDocumentStatus(self, doc):
if doc in self.docs:
index = self.docs.index(doc)
text = doc.documentName().replace('&', '&&')
if self.tabText(index) != text:
self.setTabText(index, text)
tooltip = util.path(doc.url())
self.setTabToolTip(index, tooltip)
self.setTabIcon(index, documenticon.icon(doc, self.window()))
示例10: test_docutils_source_link_with_nonascii_file
def test_docutils_source_link_with_nonascii_file(app, status, warning):
srcdir = path(app.srcdir)
mb_name = u'\u65e5\u672c\u8a9e'
try:
(srcdir / (mb_name + '.txt')).write_text('')
except UnicodeEncodeError:
from path import FILESYSTEMENCODING
raise SkipTest(
'nonascii filename not supported on this filesystem encoding: '
'%s', FILESYSTEMENCODING)
app.builder.build_all()
示例11: parse_docs_configuration
def parse_docs_configuration():
doc_path = util.path("docs", "configuration.rst")
with open(doc_path, encoding="utf-8") as file:
doc_lines = file.readlines()
sections = {}
sec_name = None
options = None
opt_name = None
opt_desc = None
name = None
last = last2 = None
for line in doc_lines:
# start of new section
if re.match(r"^=+$", line):
if sec_name and options:
sections[sec_name] = options
sec_name = last.strip()
options = {}
elif re.match(r"^=+ =+$", line):
# start of option table
if re.match(r"^-+$", last):
opt_name = last2.strip()
opt_desc = {}
# end of option table
elif opt_desc:
options[opt_name] = opt_desc
opt_name = None
name = None
# inside option table
elif opt_name:
if line[0].isalpha():
name, _, line = line.partition(" ")
opt_desc[name] = ""
line = line.strip()
if line.startswith(("* ", "- ")):
line = "\n" + line
elif line.startswith("| "):
line = line[2:] + "\n.br"
opt_desc[name] += line + "\n"
last2 = last
last = line
sections[sec_name] = options
return sections
示例12: test_second_update
def test_second_update():
# delete, add and "edit" (change saved mtime) some files and update again
env.all_docs['contents'] = 0
root = path(app.srcdir)
# important: using "autodoc" because it is the last one to be included in
# the contents.txt toctree; otherwise section numbers would shift
(root / 'autodoc.txt').unlink()
(root / 'new.txt').write_text('New file\n========\n')
updated = env.update(app.config, app.srcdir, app.doctreedir, app)
# "includes" and "images" are in there because they contain references
# to nonexisting downloadable or image files, which are given another
# chance to exist
assert set(updated) == set(['contents', 'new', 'includes', 'images'])
assert 'autodoc' not in env.all_docs
assert 'autodoc' not in env.found_docs
示例13: setDocumentStatus
def setDocumentStatus(self, doc):
try:
i = self._items[doc]
except KeyError:
# this fails when a document is closed that had a job running,
# in that case setDocumentStatus is called twice (the second time
# when the job quits, but then we already removed the document)
return
# set properties according to document
i.setText(0, doc.documentName())
i.setIcon(0, documenticon.icon(doc, self.parentWidget().mainwindow()))
i.setToolTip(0, util.path(doc.url()))
# handle ordering in groups if desired
if self._group:
self.groupDocument(doc)
else:
self.sortItems(0, Qt.AscendingOrder)
示例14: test_image_glob
def test_image_glob(app, status, warning):
app.builder.build_all()
# index.rst
doctree = pickle.loads((app.doctreedir / 'index.doctree').bytes())
assert isinstance(doctree[0][1], nodes.image)
assert doctree[0][1]['candidates'] == {'*': 'rimg.png'}
assert doctree[0][1]['uri'] == 'rimg.png'
assert isinstance(doctree[0][2], nodes.figure)
assert isinstance(doctree[0][2][0], nodes.image)
assert doctree[0][2][0]['candidates'] == {'*': 'rimg.png'}
assert doctree[0][2][0]['uri'] == 'rimg.png'
assert isinstance(doctree[0][3], nodes.image)
assert doctree[0][3]['candidates'] == {'application/pdf': 'img.pdf',
'image/gif': 'img.gif',
'image/png': 'img.png'}
assert doctree[0][3]['uri'] == 'img.*'
assert isinstance(doctree[0][4], nodes.figure)
assert isinstance(doctree[0][4][0], nodes.image)
assert doctree[0][4][0]['candidates'] == {'application/pdf': 'img.pdf',
'image/gif': 'img.gif',
'image/png': 'img.png'}
assert doctree[0][4][0]['uri'] == 'img.*'
# subdir/index.rst
doctree = pickle.loads((app.doctreedir / 'subdir/index.doctree').bytes())
assert isinstance(doctree[0][1], nodes.image)
sub = path('subdir')
assert doctree[0][1]['candidates'] == {'*': sub / 'rimg.png'}
assert doctree[0][1]['uri'] == sub / 'rimg.png'
assert isinstance(doctree[0][2], nodes.image)
assert doctree[0][2]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'}
assert doctree[0][2]['uri'] == sub / 'svgimg.*'
assert isinstance(doctree[0][3], nodes.figure)
assert isinstance(doctree[0][3][0], nodes.image)
assert doctree[0][3][0]['candidates'] == {'application/pdf': 'subdir/svgimg.pdf',
'image/svg+xml': 'subdir/svgimg.svg'}
assert doctree[0][3][0]['uri'] == sub / 'svgimg.*'
示例15: save_registered_trojans
def save_registered_trojans(self, filename):
"""
saves the already registered trojans from the internal list into a given textfile
:param filename: (string) the name of the text file in which the trojan info is saved
:return: (void)
"""
if "\\" in filename:
filepath = filename
else:
filepath = path()+"\\"+filename+".txt"
# opens the file of the filename passed, in case it exists
if not os.path.exists(filepath):
createfile(filepath)
with open(filepath, "w") as file:
# itering through the list of registered trojans and writing the information into the lines, separated
# by semicolons
for trojan in self.registered:
file.write(trojan.ip + ";")
file.write(trojan.port + ";")
file.write(trojan.name)
file.write("\n")