当前位置: 首页>>代码示例>>Python>>正文


Python FilePath.child方法代码示例

本文整理汇总了Python中twisted.python.filepath.FilePath.child方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.child方法的具体用法?Python FilePath.child怎么用?Python FilePath.child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.filepath.FilePath的用法示例。


在下文中一共展示了FilePath.child方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_config

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
def setup_config(test):
    """
    Create a configuration file and certificates for a dataset agent in a
    temporary directory.

    Sets ``config`` attribute on the test instance with the path to the
    config file.

    :param test: A ``TestCase`` instance.
    """
    ca_set, _ = get_credential_sets()
    scratch_directory = FilePath(test.mktemp())
    scratch_directory.makedirs()
    test.config = scratch_directory.child('dataset-config.yml')
    test.config.setContent(
        yaml.safe_dump({
            u"control-service": {
                u"hostname": u"10.0.0.1",
                u"port": 1234,
            },
            u"dataset": {
                u"backend": u"zfs",
            },
            u"version": 1,
        }))
    ca_set.copy_to(scratch_directory, node=True)
    test.ca_set = ca_set
    test.non_existent_file = scratch_directory.child('missing-config.yml')
开发者ID:runcom,项目名称:flocker,代码行数:30,代码来源:test_script.py

示例2: test_getProcessor

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
    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,代码行数:27,代码来源:test_lore.py

示例3: test_stop

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
    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,代码行数:30,代码来源:test_cli.py

示例4: setupJobdir

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def setupJobdir(self):
     jobdir = FilePath(self.mktemp())
     jobdir.createDirectory()
     self.jobdir = jobdir.path
     for sub in 'new', 'tmp', 'cur':
         jobdir.child(sub).createDirectory()
     return self.jobdir
开发者ID:cmouse,项目名称:buildbot,代码行数:9,代码来源:test_try_client.py

示例5: test_inputNewVersionWithDefault

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
    def test_inputNewVersionWithDefault(self):
        """
        L{inputNewVersionWithDefault} should prompt for a new version number,
        using C{raw_input}, finding the current version number in a I{NEWS.txt}
        file in the grandparent of the C{initPath} of the project it is passed
        and supplying that as a default.
        """
        projectPath = FilePath(self.mktemp()).child('FakeProject')
        projectPath.makedirs()
        projectPath.child('NEWS.txt').setContent('0.9.99')

        packagePath = projectPath.child('fakeproject')
        initPath = packagePath.child('__init__.py')
        project = Project(name="FakeProject", initPath=initPath,
                          package=None, version=None)

        def checkPrompt(prompt):
            self.assertEqual(prompt, "New version for FakeProject (default 0.9.99)? ")
            return ""

        self.assertEqual(
            inputNewVersionWithDefault(project, raw_input=checkPrompt),
            (0, 9, 99))
        self.assertEqual(
            inputNewVersionWithDefault(project, raw_input=lambda _: "6.7.89"),
            (6, 7, 89))
开发者ID:bne,项目名称:squeal,代码行数:28,代码来源:test_release.py

示例6: test_load_error_on_unreadable_key_file

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 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,代码行数:28,代码来源:test_ca.py

示例7: flocker_deploy

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
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,代码行数:29,代码来源:testtools.py

示例8: test_multipleActions

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def test_multipleActions(self):
     """
     Multiple actions can be specified for each rule.  Each action should
     happen.
     """
     tmpdir = FilePath(self.mktemp())
     rules = [
         {
             'pattern': {
                 'foo': '*',
             },
             'actions': [
                 {'merge_yaml': '{foo}.yml'},
                 {'merge_yaml': '{foo}2.yml'},
             ]
         },
     ]
     dumper = RuleBasedFileDumper(tmpdir.path, rules)
     dumper.dumpObject({
         'foo': 'thefoo',
     })
     self.assertTrue(tmpdir.child('thefoo.yml').exists(),
         "Should have matched and acted on the first rule first action")
     self.assertTrue(tmpdir.child('thefoo2.yml').exists(),
         "Should have matched and acted on the first rule second action")
开发者ID:iffy,项目名称:ppd,代码行数:27,代码来源:test_util.py

示例9: renderXHTML

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
def renderXHTML(markup, tempDir=None, css2xslfo=css2xslfo, fop=fop):
    """
    Render an I{XHTML} document to a I{PDF} document.

    @type  markup: L{str}
    @param markup: I{XHTML} document, encoded as UTF-8, that includes
        stylesheet information.

    @rtype: L{Deferred} firing with L{str}
    @return: Deferred that fires with the generated I{PDF} byte data.
    """
    def _removeTemp(ignored):
        tempDir.remove()

    if tempDir is None:
        tempDir = FilePath(tempfile.mkdtemp())
    xhtmlPath = tempDir.child('input.html')
    xhtmlPath.setContent(markup)
    xslfoPath = tempDir.child('output.fo')
    pdfPath = tempDir.child('output.pdf')

    configPath = FOP_CONFIG
    if not configPath.exists():
        configPath = None

    d = css2xslfo(xhtmlPath, xslfoPath)
    d.addCallback(lambda ignored: fop(xslfoPath, pdfPath, configPath))
    d.addCallback(defertee, _removeTemp)
    return d
开发者ID:fusionapp,项目名称:documint,代码行数:31,代码来源:css2xslfo.py

示例10: test_load_error_on_unreadable_key_file

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def test_load_error_on_unreadable_key_file(self):
     """
     A ``PathError`` is raised if the key file path given to
     ``CertificateAuthority.from_path`` cannot be opened for reading.
     """
     path = FilePath(self.mktemp())
     path.makedirs()
     crt_path = path.child(b"cluster.crt")
     crt_file = crt_path.open(b'w')
     crt_file.write(b"dummy")
     crt_file.close()
     key_path = path.child(b"cluster.key")
     key_file = key_path.open(b'w')
     key_file.write(b"dummy")
     key_file.close()
     # make file unreadable
     key_path.chmod(64)
     e = self.assertRaises(
         PathError, CertificateAuthority.from_path, path
     )
     expected = (
         b"Private key file {path} could not be opened. "
         b"Check file permissions."
     ).format(path=key_path.path)
     self.assertEqual(str(e), expected)
开发者ID:ALSEDLAH,项目名称:flocker,代码行数:27,代码来源:test_ca.py

示例11: test_catchAll

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def test_catchAll(self):
     """
     Everything should match a catchall rule.
     """
     tmpdir = FilePath(self.mktemp())
     rules = [
         {
             'pattern': {
                 'foo': '*',
             },
             'actions': [
                 {'merge_yaml': '{foo}.yml'},
             ]
         },
         {
             'pattern': 'all',
             'actions': [
                 {'merge_yaml': 'extra.yml'},
             ]
         }
     ]
     dumper = RuleBasedFileDumper(tmpdir.path, rules)
     dumper.dumpObject({
         'foo': 'thefoo',
     })
     self.assertTrue(tmpdir.child('thefoo.yml').exists(),
         "Should have matched and acted on the first rule")
     dumper.dumpObject({
         'bar': 'hey',
     })
     self.assertTrue(tmpdir.child('extra.yml').exists(),
         "Should have matched and acted on the second rule")
     self.assertEqual(len(tmpdir.children()), 2, "Should only have made "
         "the 2 expected files")
开发者ID:iffy,项目名称:ppd,代码行数:36,代码来源:test_util.py

示例12: test_saveKeysha256

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def test_saveKeysha256(self):
     """
     L{_saveKey} will generate key fingerprint in
     L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': 'passphrase',
         'format': 'sha256-base64'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:\n"
         "ryaugIFT0B8ItuszldMEU7q14rG/wj9HkRosMeBWkts=\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:28,代码来源:test_ckeygen.py

示例13: test_saveKeyECDSA

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
 def test_saveKeyECDSA(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     Test with ECDSA key.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_ecdsa').path
     key = Key.fromString(privateECDSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': 'passphrase',
         'format': 'md5-hex'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "e2:3b:e8:1c:f8:c9:c7:de:8b:c0:00:68:2e:c9:2c:8a\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_ecdsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_ecdsa.pub').getContent()),
         key.public())
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:29,代码来源:test_ckeygen.py

示例14: _makeTree

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
	def _makeTree(self):
		parent = FilePath(self.mktemp())
		parent.makedirs()
		sub = parent.child('sub')
		sub.makedirs()
		subsub = sub.child('sub sub')
		subsub.makedirs()

		parent.child('one.png').setContent("one")
		sub.child("two.png").setContent("two")
		subsub.child("three.png").setContent("three")

		t = {}
		t['md5one'] = hashlib.md5("one").hexdigest()
		t['md5two'] = hashlib.md5("two").hexdigest()
		t['md5three'] = hashlib.md5("three").hexdigest()
		t['md5replacement'] = hashlib.md5("replacement").hexdigest()

		temp = sub.child('style.css')
		original = """\
div { background-image: url(http://127.0.0.1/not-modified.png); }
td { background-image: url(https://127.0.0.1/not-modified.png); }
p { background-image: url(../one.png); }
q { background-image: url(two.png); }
b { background-image: url(sub%20sub/three.png); }
i { background-image: url(/sub/sub%20sub/three.png); }
"""
		temp.setContent(original)
		t['md5original'] = hashlib.md5(original).hexdigest()

		return parent, t
开发者ID:ludios,项目名称:Webmagic,代码行数:33,代码来源:test_untwist.py

示例15: test_add_with_environment

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import child [as 别名]
    def test_add_with_environment(self):
        """
        ``DockerClient.add`` accepts an environment object whose ID and
        variables are used when starting a docker image.
        """
        docker_dir = FilePath(self.mktemp())
        docker_dir.makedirs()
        docker_dir.child(b"Dockerfile").setContent(
            b"FROM busybox\n" b'CMD ["/bin/sh",  "-c", ' b'"while true; do env && echo WOOT && sleep 1; done"]'
        )
        expected_variables = frozenset({"key1": "value1", "key2": "value2"}.items())
        unit_name = random_name(self)

        image = DockerImageBuilder(test=self, source_dir=docker_dir)
        d = image.build()

        def image_built(image_name):
            return self.start_container(
                unit_name=unit_name, image_name=image_name, environment=Environment(variables=expected_variables)
            )

        d.addCallback(image_built)

        def started(_):
            output = ""
            while True:
                output += Client().logs(self.namespacing_prefix + unit_name)
                if "WOOT" in output:
                    break
            assertContainsAll(output, test_case=self, needles=["{}={}\n".format(k, v) for k, v in expected_variables])

        d.addCallback(started)
        return d
开发者ID:dtherrienexagrid,项目名称:flocker,代码行数:35,代码来源:test_docker.py


注:本文中的twisted.python.filepath.FilePath.child方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。