本文整理汇总了Python中twisted.python.filepath.FilePath类的典型用法代码示例。如果您正苦于以下问题:Python FilePath类的具体用法?Python FilePath怎么用?Python FilePath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilePath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_load_error_on_unreadable_key_file
def test_load_error_on_unreadable_key_file(self):
"""
A ``PathError`` is raised if the key file path given to
``UserCredential.from_path`` cannot be opened for reading.
"""
path = FilePath(self.mktemp())
path.makedirs()
crt_path = path.child(self.cert_file_name)
crt_file = crt_path.open(b'w')
crt_file.write(b"dummy")
crt_file.close()
key_path = path.child(self.key_file_name)
key_file = key_path.open(b'w')
key_file.write(b"dummy")
key_file.close()
# make file unreadable
key_path.chmod(0o100)
e = self.assertRaises(
PathError, cls.from_path,
path, **kwargs
)
expected = (
"Private key file could not be opened. "
"Permission denied {path}"
).format(path=key_path.path)
self.assertEqual(str(e), expected)
开发者ID:wallnerryan,项目名称:flocker,代码行数:26,代码来源:test_ca.py
示例2: pathEntryTree
def pathEntryTree(self, tree):
"""
Create some files in a hierarchy, based on a dictionary describing those
files. The resulting hierarchy will be placed onto sys.path for the
duration of the test.
@param tree: A dictionary representing a directory structure. Keys are
strings, representing filenames, dictionary values represent
directories, string values represent file contents.
@return: another dictionary similar to the input, with file content
strings replaced with L{FilePath} objects pointing at where those
contents are now stored.
"""
def makeSomeFiles(pathobj, dirdict):
pathdict = {}
for (key, value) in dirdict.items():
child = pathobj.child(key)
if isinstance(value, bytes):
pathdict[key] = child
child.setContent(value)
elif isinstance(value, dict):
child.createDirectory()
pathdict[key] = makeSomeFiles(child, value)
else:
raise ValueError("only strings and dicts allowed as values")
return pathdict
base = FilePath(self.mktemp().encode("utf-8"))
base.makedirs()
result = makeSomeFiles(base, tree)
# On Python 3, sys.path cannot include byte paths:
self.replaceSysPath([base.path.decode("utf-8")] + sys.path)
self.replaceSysModules(sys.modules.copy())
return result
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:35,代码来源:test_deprecate.py
示例3: test_stop
def test_stop(self):
"""
Stop will stop a running process.
"""
runner = Runner()
# I'm getting AF_UNIX path too long errors using self.mktemp()
base = FilePath(tempfile.mkdtemp())
log.msg('tmpdir: %r' % base.path)
root = base.child('root')
src = base.child('src')
dst = base.child('dst')
_ = yield runner.start(root.path, 'unix:'+src.path, 'unix:'+dst.path)
pidfile = root.child('grace.pid')
pid = pidfile.getContent()
self.addCleanup(self.kill, pid)
_ = yield runner.stop(root.path)
# tail the log until you see Server Shut Down
# XXX stop should maybe do the same... so that it doesn't return until
# the process has actually stopped.
logfile = root.child('grace.log')
self.assertTrue(logfile.exists())
_ = yield self.tailUntil(logfile.path, 'Server Shut Down.')
self.assertFalse(pidfile.exists(), "pidfile should be gone: %r" % pidfile.path)
开发者ID:iffy,项目名称:grace,代码行数:28,代码来源:test_cli.py
示例4: test_parseFileAndReportMismatchedTags
def test_parseFileAndReportMismatchedTags(self):
"""
If the contents of the file passed to L{tree.parseFileAndReport}
contain a mismatched tag, L{process.ProcessingFailure} is raised
indicating the location of the open and close tags which were
mismatched.
"""
path = FilePath(self.mktemp())
path.setContent(' <foo>\n\n </bar>')
err = self.assertRaises(
process.ProcessingFailure, tree.parseFileAndReport, path.path)
self.assertEqual(
str(err),
"mismatched close tag at line 3, column 4; expected </foo> "
"(from line 1, column 2)")
# Test a case which requires involves proper close tag handling.
path.setContent('<foo><bar></bar>\n </baz>')
err = self.assertRaises(
process.ProcessingFailure, tree.parseFileAndReport, path.path)
self.assertEqual(
str(err),
"mismatched close tag at line 2, column 4; expected </foo> "
"(from line 1, column 0)")
开发者ID:0004c,项目名称:VTK,代码行数:26,代码来源:test_lore.py
示例5: test_getProcessor
def test_getProcessor(self):
base = FilePath(self.mktemp())
base.makedirs()
input = base.child("simple3.html")
FilePath(__file__).sibling("simple3.html").copyTo(input)
options = { 'template': sp('template.tpl'), 'ext': '.xhtml', 'baseurl': 'burl',
'filenameMapping': None }
p = process.getProcessor(default, "html", options)
p(input.path, self.linkrel)
self.assertXMLEqual(
"""\
<?xml version="1.0" ?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head><title>Twisted Documentation: My Test Lore Input</title></head>
<body bgcolor="white">
<h1 class="title">My Test Lore Input</h1>
<div class="content">
<span/>
<p>A Body.</p>
</div>
<a href="index.xhtml">Index</a>
</body>
</html>""",
base.child("simple3.xhtml").getContent())
开发者ID:0004c,项目名称:VTK,代码行数:25,代码来源:test_lore.py
示例6: postOptions
def postOptions(self):
if self['distribution'] is None:
raise UsageError("Distribution required.")
if self['config-file'] is not None:
config_file = FilePath(self['config-file'])
self['config'] = yaml.safe_load(config_file.getContent())
else:
self['config'] = {}
provider = self['provider'].lower()
provider_config = self['config'].get(provider, {})
package_source = PackageSource(
version=self['flocker-version'],
branch=self['branch'],
build_server=self['build-server'],
)
try:
get_runner = getattr(self, "_runner_" + provider.upper())
except AttributeError:
raise UsageError(
"Provider {!r} not supported. Available providers: {}".format(
provider, ', '.join(
name.lower() for name in self._get_provider_names()
)
)
)
else:
self.runner = get_runner(
package_source=package_source,
dataset_backend=self.dataset_backend(),
provider_config=provider_config,
)
开发者ID:uedzen,项目名称:flocker,代码行数:34,代码来源:acceptance.py
示例7: copyPackage
def copyPackage(title):
"""
Copy package directory to db path using a file lock to avoid potential
concurrency race conditions.
@param title: string to use in log entry
@type title: C{str}
"""
dbpath = FilePath(TimezoneCache.getDBPath())
pkgpath = TimezoneCache.FilteredFilePath(TimezoneCache._getPackageDBPath())
lockfile = FilesystemLock(dbpath.path + ".lock")
result = lockfile.lock()
try:
if result and not dbpath.exists():
log.info(
"{title} timezones from {pkg} to {to}",
title=title,
pkg=pkgpath.path,
to=dbpath.path
)
# Copy over the entire package
pkgpath.copyFilteredDirectoryTo(dbpath)
finally:
if result:
lockfile.unlock()
开发者ID:red-hood,项目名称:calendarserver,代码行数:27,代码来源:timezones.py
示例8: test_bootstrap_pyc
def test_bootstrap_pyc(self):
"""
``create_virtualenv`` creates links to the pyc files for all the
modules required for the virtualenv bootstrap process.
"""
target_path = FilePath(self.mktemp())
create_virtualenv(root=target_path)
py_files = []
for module_name in VIRTUALENV_REQUIRED_MODULES:
py_base = target_path.descendant(['lib', 'python2.7', module_name])
py = py_base.siblingExtension('.py')
pyc = py_base.siblingExtension('.pyc')
if py.exists() and False in (py.islink(), pyc.islink()):
py_files.append('PY: {} > {}\nPYC: {} > {}\n'.format(
'/'.join(py.segmentsFrom(target_path)),
py.realpath().path,
'/'.join(pyc.segmentsFrom(target_path)),
pyc.islink() and pyc.realpath().path or 'NOT A SYMLINK'
))
if py_files:
self.fail(
'Non-linked bootstrap pyc files in {}: \n{}'.format(
target_path, '\n'.join(py_files)
)
)
开发者ID:hanwoody,项目名称:flocker,代码行数:27,代码来源:test_packaging.py
示例9: test_internal_symlinks_only
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
)
)
开发者ID:hanwoody,项目名称:flocker,代码行数:32,代码来源:test_packaging.py
示例10: flocker_deploy
def flocker_deploy(test_case, deployment_config, application_config):
"""
Run ``flocker-deploy`` with given configuration files.
:param test_case: The ``TestCase`` running this unit test.
:param dict deployment_config: The desired deployment configuration.
:param dict application_config: The desired application configuration.
"""
# This is duplicate code, see
# https://clusterhq.atlassian.net/browse/FLOC-1903
control_node = environ.get("FLOCKER_ACCEPTANCE_CONTROL_NODE")
certificate_path = environ["FLOCKER_ACCEPTANCE_API_CERTIFICATES_PATH"]
if control_node is None:
raise SkipTest("Set control node address using "
"FLOCKER_ACCEPTANCE_CONTROL_NODE environment variable.")
temp = FilePath(test_case.mktemp())
temp.makedirs()
deployment = temp.child(b"deployment.yml")
deployment.setContent(safe_dump(deployment_config))
application = temp.child(b"application.yml")
application.setContent(safe_dump(application_config))
check_call([b"flocker-deploy", b"--certificates-directory",
certificate_path, control_node, deployment.path,
application.path])
开发者ID:runcom,项目名称:flocker,代码行数:27,代码来源:testtools.py
示例11: reportEnvironment
def reportEnvironment():
revision = twisted.version.short().split('r', 1)[1]
packageDirectory = FilePath(twisted.__file__).parent()
try:
import pysvn
except ImportError:
entries = packageDirectory.child('.svn').child('entries').getContent()
lines = entries.splitlines()
revision = lines[3]
date = lines[9][:20].replace('T', ' ')
else:
client = pysvn.Client()
[entry] = client.log(
packageDirectory.path,
pysvn.Revision(pysvn.opt_revision_kind.number, int(revision)),
limit=1)
date = str(datetime.fromtimestamp(entry['date']))
return {
'project': 'Twisted',
'executable': executable,
'environment': uname()[1],
'commitid': revision,
'revision_date': date,
'result_date': str(datetime.now()),
}
开发者ID:AlekSi,项目名称:twisted-benchmarks,代码行数:28,代码来源:speedcenter.py
示例12: Tests
class Tests(SynchronousTestCase):
def setUp(self):
self.options = options_type()
self.scratch_directory = FilePath(self.mktemp())
self.scratch_directory.makedirs()
self.sample_content = yaml.safe_dump({
u"control-service": {
u"hostname": u"10.0.0.1",
u"port": 4524,
},
u"version": 1,
})
self.config = self.scratch_directory.child('dataset-config.yml')
self.config.setContent(self.sample_content)
def test_default_config_file(self):
"""
The default config file is a FilePath with path
``/etc/flocker/agent.yml``.
"""
self.options.parseOptions([])
self.assertEqual(
self.options["agent-config"],
FilePath("/etc/flocker/agent.yml"))
def test_custom_config_file(self):
"""
The ``--config-file`` command-line option allows configuring
the config file.
"""
self.options.parseOptions(
[b"--agent-config", b"/etc/foo.yml"])
self.assertEqual(
self.options["agent-config"],
FilePath("/etc/foo.yml"))
开发者ID:sysuwbs,项目名称:flocker,代码行数:35,代码来源:test_script.py
示例13: test_branch_multi_volumes
def test_branch_multi_volumes(self, volumes):
"""
Always show the last checked-out branch for all volumes in ``list``.
"""
tmpdir = FilePath(self.mktemp())
tmpdir.makedirs()
dvol = VoluminousOptions()
for volume, branch in volumes:
dvol.parseOptions(ARGS + ["-p", tmpdir.path, "init", volume])
dvol.parseOptions(ARGS + ["-p", tmpdir.path, "commit", "-m", "hello"])
dvol.parseOptions(ARGS + ["-p", tmpdir.path, "checkout", "-b", branch])
dvol.parseOptions(ARGS + ["-p", tmpdir.path, "list"])
lines = dvol.voluminous.getOutput()[-1].split("\n")
header, rest = lines[0], lines[1:]
expected_volumes = [[volume, branch] for volume, branch in volumes]
# `init` activates the volume, so the last initialized volume is the
# active one.
expected_volumes[-1] = [
'*', expected_volumes[-1][0], expected_volumes[-1][1]]
self.assertEqual(['VOLUME', 'BRANCH', 'CONTAINERS'], header.split())
self.assertEqual(
sorted(expected_volumes),
sorted([line.split() for line in rest]),
)
开发者ID:lalyos,项目名称:dvol,代码行数:27,代码来源:test_dvol.py
示例14: test_functional_centos_7
def test_functional_centos_7(self):
"""
The expected RPM files are built for CentOS 7
"""
output_dir = FilePath(self.mktemp())
check_call([
FLOCKER_PATH.descendant([b'admin', b'build-package']).path,
'--destination-path', output_dir.path,
'--distribution', 'centos-7',
FLOCKER_PATH.path
])
python_version = __version__
rpm_version = make_rpm_version(python_version)
expected_basenames = (
('clusterhq-python-flocker', 'x86_64'),
('clusterhq-flocker-cli', 'noarch'),
('clusterhq-flocker-node', 'noarch'),
)
expected_filenames = []
for basename, arch in expected_basenames:
f = '{}-{}-{}.{}.rpm'.format(
basename, rpm_version.version, rpm_version.release, arch)
expected_filenames.append(f)
self.assertEqual(
set(expected_filenames),
set(f.basename() for f in output_dir.children())
)
for f in output_dir.children():
assert_rpm_lint(self, f)
开发者ID:hanwoody,项目名称:flocker,代码行数:32,代码来源:test_packaging.py
示例15: VoluminousTests
class VoluminousTests(TestCase):
def setUp(self):
self.tmpdir = FilePath(self.mktemp())
self.tmpdir.makedirs()
def test_create_volume(self):
dvol = VoluminousOptions()
dvol.parseOptions(ARGS + ["-p", self.tmpdir.path, "init", "foo"])
self.assertTrue(self.tmpdir.child("foo").exists())
self.assertTrue(self.tmpdir.child("foo").child("branches")
.child("master").exists())
self.assertEqual(dvol.voluminous.getOutput()[-1],
"Created volume foo\nCreated branch foo/master")
# Verify operation with `list`
dvol.parseOptions(ARGS + ["-p", self.tmpdir.path, "list"])
header, rest = self._parse_list_output(dvol)
expected_volumes = [["*", "foo", "master"]]
self.assertEqual(
sorted(expected_volumes),
sorted(rest),
)
def test_create_volume_already_exists(self):
dvol = VoluminousOptions()
# Create the repository twice, second time should have the error
expected_output = "Error: volume foo already exists"
dvol.parseOptions(ARGS + ["-p", self.tmpdir.path, "init", "foo"])
try:
dvol.parseOptions(ARGS + ["-p", self.tmpdir.path, "init", "foo"])
self.assertEqual(dvol.voluminous.getOutput()[-1], expected_output)
except CalledProcessErrorWithOutput, error:
self.assertIn(expected_output, error.original.output)
self.assertTrue(error.original.returncode != 0)
开发者ID:lalyos,项目名称:dvol,代码行数:33,代码来源:test_dvol.py
示例16: test_functional_ubuntu_1404
def test_functional_ubuntu_1404(self):
"""
The expected deb files are generated on Ubuntu14.04.
"""
output_dir = FilePath(self.mktemp())
check_call([
FLOCKER_PATH.descendant([b'admin', b'build-package']).path,
'--destination-path', output_dir.path,
'--distribution', 'ubuntu-14.04',
FLOCKER_PATH.path
])
python_version = __version__
rpm_version = make_rpm_version(python_version)
expected_basenames = (
('clusterhq-python-flocker', 'amd64'),
('clusterhq-flocker-cli', 'all'),
('clusterhq-flocker-node', 'all'),
)
expected_filenames = []
for basename, arch in expected_basenames:
f = '{}_{}-{}_{}.deb'.format(
basename, rpm_version.version, rpm_version.release, arch)
expected_filenames.append(f)
self.assertEqual(
set(expected_filenames),
set(f.basename() for f in output_dir.children())
)
for f in output_dir.children():
assert_deb_lint(self, f)
开发者ID:hanwoody,项目名称:flocker,代码行数:32,代码来源:test_packaging.py
示例17: test_functional
def test_functional(self):
"""
It works
"""
root = FilePath(self.mktemp())
root.makedirs()
foo = root.child('foo')
foo.setContent('#!%s\n'
'import sys, os\n'
'print sys.argv[1]\n'
'print sys.stdin.read()\n' % (sys.executable,))
foo.chmod(0777)
history = []
runner = ScriptRunner(root.path, history.append)
r = runner.run('foo', ['something'], 'guts')
def check(proto):
self.assertEqual(proto.stdout, 'something\nguts\n')
self.assertEqual(proto.stderr, '')
self.assertTrue(len(history) > 0)
def eb(res):
print res
print ''
for i in history:
if i.key in [1,2,3]:
print i.data['line']
return res
return r.done.addCallback(check).addErrback(eb)
开发者ID:hagna,项目名称:mold,代码行数:29,代码来源:test_process.py
示例18: setUp
def setUp(self):
self.factory = OpenSSHFactory()
self.keysDir = FilePath(self.mktemp())
self.keysDir.makedirs()
self.factory.dataRoot = self.keysDir.path
self.moduliDir = FilePath(self.mktemp())
self.moduliDir.makedirs()
self.factory.moduliRoot = self.moduliDir.path
self.keysDir.child("ssh_host_foo").setContent(b"foo")
self.keysDir.child("bar_key").setContent(b"foo")
self.keysDir.child("ssh_host_one_key").setContent(
keydata.privateRSA_openssh)
self.keysDir.child("ssh_host_two_key").setContent(
keydata.privateDSA_openssh)
self.keysDir.child("ssh_host_three_key").setContent(
b"not a key content")
self.keysDir.child("ssh_host_one_key.pub").setContent(
keydata.publicRSA_openssh)
self.moduliDir.child("moduli").setContent(b"""
# $OpenBSD: moduli,v 1.xx 2016/07/26 12:34:56 jhacker Exp $
# Time Type Tests Tries Size Generator Modulus
20030501000000 2 6 100 2047 2 FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF
19981111000000 2 6 100 1023 2 FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF
""")
self.mockos = MockOS()
self.patch(os, "seteuid", self.mockos.seteuid)
self.patch(os, "setegid", self.mockos.setegid)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:32,代码来源:test_openssh_compat.py
示例19: get_backend_api
def get_backend_api(test_case, cluster_id):
"""
Get an appropriate BackendAPI for the specified dataset backend.
Note this is a backdoor that is useful to be able to interact with cloud
APIs in tests. For many dataset backends this does not make sense, but it
provides a convenient means to interact with cloud backends such as EBS or
cinder.
:param test_case: The test case that is being run.
:param cluster_id: The unique cluster_id, used for backend APIs that
require this in order to be constructed.
"""
backend_config_filename = environ.get(
"FLOCKER_ACCEPTANCE_TEST_VOLUME_BACKEND_CONFIG")
if backend_config_filename is None:
raise SkipTest(
'This test requires the ability to construct an IBlockDeviceAPI '
'in order to verify construction. Please set '
'FLOCKER_ACCEPTANCE_TEST_VOLUME_BACKEND_CONFIG to a yaml filepath '
'with the dataset configuration.')
backend_name = environ.get("FLOCKER_ACCEPTANCE_VOLUME_BACKEND")
if backend_name is None:
raise SkipTest(
"Set acceptance testing volume backend using the " +
"FLOCKER_ACCEPTANCE_VOLUME_BACKEND environment variable.")
backend_config_filepath = FilePath(backend_config_filename)
full_backend_config = yaml.safe_load(
backend_config_filepath.getContent())
backend_config = full_backend_config.get(backend_name)
if 'backend' in backend_config:
backend_config.pop('backend')
backend = get_backend(backend_name)
return get_api(backend, pmap(backend_config), reactor, cluster_id)
开发者ID:james-w,项目名称:flocker,代码行数:35,代码来源:testtools.py
示例20: _get_device_path_virtio_blk
def _get_device_path_virtio_blk(self, volume):
"""
The virtio_blk driver allows a serial number to be assigned to virtual
blockdevices.
OpenStack will set a serial number containing the first 20
characters of the Cinder block device ID.
This was introduced in
* https://github.com/openstack/nova/commit/3a47c02c58cefed0e230190b4bcef14527c82709 # noqa
* https://bugs.launchpad.net/nova/+bug/1004328
The udev daemon will read the serial number and create a
symlink to the canonical virtio_blk device path.
We do this because libvirt does not return the correct device path when
additional disks have been attached using a client other than
cinder. This is expected behaviour within Cinder and libvirt See
https://bugs.launchpad.net/cinder/+bug/1387945 and
http://libvirt.org/formatdomain.html#elementsDisks (target section)
:param volume: The Cinder ``Volume`` which is attached.
:returns: ``FilePath`` of the device created by the virtio_blk
driver.
"""
expected_path = FilePath(
"/dev/disk/by-id/virtio-{}".format(volume.id[:20])
)
if expected_path.exists():
return expected_path.realpath()
else:
raise UnattachedVolume(volume.id)
开发者ID:justinclayton,项目名称:flocker,代码行数:31,代码来源:cinder.py
注:本文中的twisted.python.filepath.FilePath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论