本文整理汇总了Python中twisted.python.filepath.FilePath.walk方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.walk方法的具体用法?Python FilePath.walk怎么用?Python FilePath.walk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.filepath.FilePath
的用法示例。
在下文中一共展示了FilePath.walk方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_internal_symlinks_only
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import walk [as 别名]
def test_internal_symlinks_only(self):
"""
The resulting ``virtualenv`` only contains symlinks to files inside the
virtualenv and to /usr on the host OS.
"""
target_path = FilePath(self.mktemp())
create_virtualenv(root=target_path)
allowed_targets = (target_path, FilePath('/usr'),)
bad_links = []
for path in target_path.walk():
if path.islink():
realpath = path.realpath()
for allowed_target in allowed_targets:
try:
realpath.segmentsFrom(allowed_target)
except ValueError:
pass
else:
# The target is a descendent of an allowed_target.
break
else:
bad_links.append(path)
if bad_links:
self.fail(
"Symlinks outside of virtualenv detected:" +
'\n'.join(
'/'.join(
path.segmentsFrom(target_path)
) + ' -> ' + path.realpath().path
for path in bad_links
)
)
示例2: main
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import walk [as 别名]
def main():
existing = set(md.key for v, md in etcd.get_prefix(prefix))
written = set()
root = FilePath('config')
print 'reading at %s' % root
for f in root.walk():
if f.isfile() and f.path.endswith('.n3'):
n3 = f.getContent()
key = prefix + b'/'.join(f.segmentsFrom(root))
etcd.put(key, n3)
written.add(key)
print 'wrote %s' % key
for k in existing - written:
etcd.delete(k)
print 'removed %s' % k
示例3: assert_deb_content
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import walk [as 别名]
def assert_deb_content(test_case, expected_paths, package_path):
"""
Fail unless the ``deb`` file at ``package_path`` contains all the
``expected_paths``.
:param test_case: The ``TestCase`` whose assert methods will be called.
:param set expected_paths: A set of ``FilePath`` s
:param FilePath package_path: The path to the package under test.
"""
output_dir = FilePath(test_case.mktemp())
output_dir.makedirs()
check_output(['dpkg', '--extract', package_path.path, output_dir.path])
actual_paths = set()
for f in output_dir.walk():
if f.isdir():
continue
actual_paths.add(FilePath('/').descendant(f.segmentsFrom(output_dir)))
test_case.assertEqual(expected_paths, actual_paths)
示例4: _run
# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import walk [as 别名]
def _run(package, path, newversion, patch, rc, dev, create,
_date=None, _getcwd=None, _print=print):
if not _getcwd:
_getcwd = os.getcwd
if not _date:
_date = datetime.date.today()
if type(package) != str:
package = package.encode('utf8')
if not path:
path = _findPath(_getcwd(), package)
else:
path = FilePath(path)
if newversion and patch or newversion and dev or newversion and rc:
raise ValueError("Only give --newversion")
if dev and patch or dev and rc:
raise ValueError("Only give --dev")
if create and dev or create and patch or create and rc or \
create and newversion:
raise ValueError("Only give --create")
if newversion:
from pkg_resources import parse_version
existing = _existing_version(path)
st_version = parse_version(newversion)._version
release = list(st_version.release)
if len(release) == 1:
release.append(0)
if len(release) == 2:
release.append(0)
v = Version(
package, *release,
release_candidate=st_version.pre[1] if st_version.pre else None,
dev=st_version.dev[1] if st_version.dev else None)
elif create:
v = Version(package, _date.year - _YEAR_START, _date.month, 0)
existing = v
elif rc and not patch:
existing = _existing_version(path)
if existing.release_candidate:
v = Version(package, existing.major, existing.minor,
existing.micro, existing.release_candidate + 1)
else:
v = Version(package, _date.year - _YEAR_START, _date.month, 0, 1)
elif patch:
if rc:
rc = 1
else:
rc = None
existing = _existing_version(path)
v = Version(package, existing.major, existing.minor,
existing.micro + 1, rc)
elif dev:
existing = _existing_version(path)
if existing.dev is None:
_dev = 0
else:
_dev = existing.dev + 1
v = Version(package, existing.major, existing.minor,
existing.micro, existing.release_candidate, dev=_dev)
else:
existing = _existing_version(path)
if existing.release_candidate:
v = Version(package,
existing.major, existing.minor, existing.micro)
else:
raise ValueError(
"You need to issue a rc before updating the major/minor")
NEXT_repr = repr(Version(package, "NEXT", 0, 0)).split("#")[0]
NEXT_repr_bytes = NEXT_repr.encode('utf8')
version_repr = repr(v).split("#")[0]
version_repr_bytes = version_repr.encode('utf8')
existing_version_repr = repr(existing).split("#")[0]
existing_version_repr_bytes = existing_version_repr.encode('utf8')
_print("Updating codebase to %s" % (v.public()))
for x in path.walk():
#.........这里部分代码省略.........