本文整理汇总了Python中twisted.python.filepath.FilePath.dirname方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.dirname方法的具体用法?Python FilePath.dirname怎么用?Python FilePath.dirname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.dirname方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_addPyListings
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import dirname [as 别名]
def test_addPyListings(self):
"""
L{tree.addPyListings} accepts a document with nodes with their I{class}
attribute set to I{py-listing} and replaces those nodes with Python
source listings from the file given by the node's I{href} attribute.
"""
listingPath = FilePath(self.mktemp())
listingPath.setContent('def foo():\n pass\n')
parent = dom.Element('div')
listing = dom.Element('a')
listing.setAttribute('href', listingPath.basename())
listing.setAttribute('class', 'py-listing')
parent.appendChild(listing)
tree.addPyListings(parent, listingPath.dirname())
expected = """\
<div><div class="py-listing"><pre><p class="py-linenumber">1
2
</p><span class="py-src-keyword">def</span> <span class="py-src-identifier">foo</span>():
<span class="py-src-keyword">pass</span>
</pre><div class="caption"> - <a href="temp"><span class="filename">temp</span></a></div></div></div>"""
self.assertEqual(parent.toxml(), expected)
示例2: _parse_file
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import dirname [as 别名]
def _parse_file(self, kind, args):
if args == "-":
get_file = lambda: stdout
else:
path = FilePath(args)
get_file = lambda: LogFile(
path.basename(),
path.dirname(),
rotateLength=1024 * 1024 * 1024,
maxRotatedFiles=10,
)
return lambda reactor: FileDestination(get_file())
示例3: do_urlextract
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import dirname [as 别名]
def do_urlextract(dest, url):
global dsklst
dest=FilePath(dest)
# Don't do this if not mounted!
mntpnt=dsklst['/'].real_mountpoint()
if not os.path.ismount(mntpnt):
return False
if not dest.isdir():
return False
try:
uh=urllib2.urlopen(url)
tf=tarfile.open(mode='r|*',fileobj=uh)
os.chroot(mntpnt)
os.chdir(os.path.join(dest.dirname(),dest.basename()))
tf.extractall()
except:
traceback.print_exc()
os.chdir('/')
示例4: __init__
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import dirname [as 别名]
def __init__(self, *argz, **kwz):
super(Logtail, self).__init__(*argz, **kwz)
self.exclude = self.conf.monitor_exclude or list()
if isinstance(self.exclude, types.StringTypes): self.exclude = [self.exclude]
self.exclude = map(re.compile, self.exclude)
paths_watch = self.paths_watch = dict()
self.paths_pos, self.paths_buff = dict(), dict()
masks, paths = self.conf.monitor, list()
if isinstance(masks, bytes): masks = [masks]
for mask in masks:
mask_patterns = self.glob_alter(mask)
for mask_raw in mask_patterns:
mask = FilePath(mask_raw)
# All matched parent dirs - like /x/y/z for /x/*/z/file* - are watched for pattern
# Note that watchers won't be auto-added for /x/m/z, if it'll be created later on
paths_ext = list( (path.realpath(), mask.basename())
for path in it.imap(FilePath, glob(mask.dirname())) )
paths.extend(paths_ext)
# If full pattern already match something, watch it if it's a dir - /x/dir1 for /x/dir*
# Note that watchers won't be auto-added for /x/dir2, if it'll be created later on
if paths_ext: # no point going deeper if parent dirs don't exist
paths.extend( (path.realpath(), '*')
for path in it.imap(FilePath, glob(mask_raw))
if path.realpath().isdir() )
# Aggregate path masks by-realpath
for path, mask in paths:
if not path.isdir():
log.debug('Skipping special path: {}'.format(path))
continue
if path not in paths_watch:
paths_watch[path] = {mask}
else: paths_watch[path].add(mask)
self.notifier_restart()
示例5: test_addPyListingsSkipLines
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import dirname [as 别名]
def test_addPyListingsSkipLines(self):
"""
If a node with the I{py-listing} class also has a I{skipLines}
attribute, that number of lines from the beginning of the source
listing are omitted.
"""
listingPath = FilePath(self.mktemp())
listingPath.setContent('def foo():\n pass\n')
parent = dom.Element('div')
listing = dom.Element('a')
listing.setAttribute('href', listingPath.basename())
listing.setAttribute('class', 'py-listing')
listing.setAttribute('skipLines', 1)
parent.appendChild(listing)
tree.addPyListings(parent, listingPath.dirname())
expected = """\
<div><div class="py-listing"><pre><p class="py-linenumber">1
</p> <span class="py-src-keyword">pass</span>
</pre><div class="caption"> - <a href="temp"><span class="filename">temp</span></a></div></div></div>"""
self.assertEqual(parent.toxml(), expected)