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


Python pyaml.dump方法代码示例

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


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

示例1: test_pretty_dumping

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_pretty_dumping(self):
        "Use pyaml to dump nicer"
        # pyaml only runs on 2.7 and above
        if sys.version_info > (2, 6) and pyaml is not None:

            with codecs.open("tests/unpretty.md", "r", "utf-8") as f:
                data = f.read()

            post = frontmatter.load("tests/unpretty.md")
            yaml = pyaml.dump(post.metadata)

            # the unsafe dumper gives you nicer output, for times you want that
            dump = frontmatter.dumps(post, Dumper=pyaml.UnsafePrettyYAMLDumper)

            self.assertEqual(dump, data)
            self.assertTrue(yaml in dump) 
开发者ID:eyeseast,项目名称:python-frontmatter,代码行数:18,代码来源:test.py

示例2: process_playbook

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def process_playbook(playbook_path):
    print('Processing playbook %s' % playbook_path)
    with open(playbook_path, 'r') as fh:
        data = yaml.load(fh)


    for task in data:
        task_keys = frozenset(task.keys())
        for key in task_keys:
            if key.startswith('netscaler_'):
                module_name = key
        print('module name is %s' % module_name)
        module_arguments = task[module_name]
        del module_arguments['nsip']
        del module_arguments['nitro_user']
        del module_arguments['nitro_pass']
        module_arguments['mas_ip'] = '{{ nsip }}'
        module_arguments['mas_auth_token'] = '{{ mas_login_result.nitro_auth_token }}'
        module_arguments['mas_proxy_call'] = 'true'
        module_arguments['instance_ip'] = '{{ instance_ip }}'

    with open(playbook_path, 'w') as fh:
        pyaml.dump(data,fh, indent=2) 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:25,代码来源:transpile_integration_tests_to_mas.py

示例3: test_dumping_with_custom_delimiters

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_dumping_with_custom_delimiters(self):
        "dump with custom delimiters"
        post = frontmatter.load("tests/hello-world.markdown")
        dump = frontmatter.dumps(post, start_delimiter="+++", end_delimiter="+++")

        self.assertTrue("+++" in dump) 
开发者ID:eyeseast,项目名称:python-frontmatter,代码行数:8,代码来源:test.py

示例4: test_dump_to_file

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_dump_to_file(self):
        "dump post to filename"
        post = frontmatter.load("tests/hello-world.markdown")

        tempdir = tempfile.mkdtemp()
        filename = os.path.join(tempdir, "hello.md")
        frontmatter.dump(post, filename)

        with open(filename) as f:
            self.assertEqual(f.read(), frontmatter.dumps(post))

        # cleanup
        shutil.rmtree(tempdir) 
开发者ID:eyeseast,项目名称:python-frontmatter,代码行数:15,代码来源:test.py

示例5: sanity_check

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def sanity_check(self, filename, handler_type):
        "Ensure we can load -> dump -> load"
        post = frontmatter.load(filename)

        self.assertIsInstance(post.handler, handler_type)

        # dump and reload
        repost = frontmatter.loads(frontmatter.dumps(post))

        self.assertEqual(post.metadata, repost.metadata)
        self.assertEqual(post.content, repost.content)
        self.assertEqual(post.handler, repost.handler) 
开发者ID:eyeseast,项目名称:python-frontmatter,代码行数:14,代码来源:test.py

示例6: transform

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def transform(self, app_config):
        converted_app_config = self._spec_factory.transform(app_config, strip_defaults=True)
        return pyaml.dump(converted_app_config) 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:5,代码来源:transformer.py

示例7: test_config_from_file

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_config_from_file(self, key, attr, value, tmpdir):
        config_file = tmpdir.join("config.yaml")
        with config_file.open("w") as fobj:
            pyaml.dump({key: value}, fobj, safe=True, default_style='"')
        config = Configuration(["--config-file", config_file.strpath])
        assert getattr(config, attr) == value 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:8,代码来源:test_config.py

示例8: test_host_rewrite_rules_from_file

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_host_rewrite_rules_from_file(self, tmpdir):
        args = ("pattern=value", r"(\d+)\.\example\.com=$1.example.net", "www.([a-z]+.com)={env}.$1")
        config_file = tmpdir.join("config.yaml")
        with config_file.open("w") as fobj:
            pyaml.dump({"host-rewrite-rule": args}, fobj, safe=True, default_style='"')
        config = Configuration(["--config-file", config_file.strpath])
        assert config.host_rewrite_rules == [HostRewriteRule(arg) for arg in args] 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:9,代码来源:test_config.py

示例9: test_behavior_for_undefined_flags_in_config_yml

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def test_behavior_for_undefined_flags_in_config_yml(self, tmpdir):
        config_flags = {
            "undefined_configuration_parameter": "a value",
            "debug": "true",
        }
        config_file = tmpdir.join("config.yaml")
        with config_file.open("w") as fobj:
            pyaml.dump(config_flags, fobj, safe=True, default_style='"')
        config = Configuration(["--config-file", config_file.strpath])
        # Defined configuration flags should be set
        assert config.debug is True
        # Undefined configuration flags should not be available
        with pytest.raises(AttributeError):
            config.undefined_configuration_parameter 
开发者ID:fiaas,项目名称:fiaas-deploy-daemon,代码行数:16,代码来源:test_config.py

示例10: yaml

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def yaml(self):
        logs_list = None
        if self.logs is not None:
            logs_list = [lm.yaml() for lm in self.logs]

        data = OrderedDict([
            ('service_name', self.name),
            ('team_name', self.team_name),
            ('port', self.port),
            ('healthcheck_url', self.healthcheck_url),
            ('logs', logs_list),
            ('code_deploy_logs', self.code_deploy_logs),
            ('environments', [e.yaml() for e in self.environments])
        ])
        return pyaml.dump(OrderedDict((k, v) for k, v in data.items() if v is not None)) 
开发者ID:saksdirect,项目名称:nova,代码行数:17,代码来源:service.py

示例11: generate_use_stub

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def generate_use_stub(resource_definition, output_yaml):
    #print(json.dumps(usage_playbook_template, indent=4))
    playbook = copy.deepcopy(usage_playbook_template)
    playbook[0]['tasks'][0]['vars'] = copy.deepcopy(resource_definition)
    delete_resource_definition= copy.deepcopy(resource_definition)
    del delete_resource_definition['resource_attributes']
    del delete_resource_definition['resource_non_updateable_attributes']

    playbook[0]['tasks'][1]['vars'] = delete_resource_definition
    #print(json.dumps(playbook, indent=4))
    with open(output_yaml, 'w') as fh:
        pyaml.dump(playbook, fh, indent=2)
    pass 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:15,代码来源:generate_integration_tests.py

示例12: generate_skeleton

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def generate_skeleton(args):

    role_path = os.path.join(args.dir_path, 'citrix_adc_nitro_resource')
    if not os.path.exists(role_path):
        os.makedirs(role_path)

    paths = [
        os.path.join(role_path, 'tasks'),
        os.path.join(role_path, 'defaults'),
        os.path.join(role_path, 'vars'),
        os.path.join(role_path, 'tests/nitro/tasks'),
    ]
    for path in paths:
        if not os.path.exists(path):
            os.makedirs(path)

    with open(os.path.join(role_path, 'tasks', 'main.yaml'), 'w') as fh:
        fh.write(MAIN_ROLE_FILE)

    with open(os.path.join(role_path, 'tasks', 'nitro.yaml'), 'w') as fh:
        fh.write(NITRO_ROLE_FILE)

    with open(os.path.join(role_path, 'defaults', 'main.yaml'), 'w') as fh:
        fh.write(DEFAUTLS_VARIABLES_FILE)

    with open(os.path.join(role_path, 'tests/nitro/tasks', 'nitro_resource_task.yaml'), 'w') as fh:
        fh.write(NITRO_RESOURCE_TASK_FILE)


    workflow_source = os.path.join(HERE, '../../nitro_resource_utils/workflows.yaml')
    with open(workflow_source, 'r') as fh:
        workflow = yaml.load(fh)

    with open(os.path.join(role_path, 'vars', 'main.yaml'), 'w') as fh:
        pyaml.dump(workflow, fh) 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:37,代码来源:__init__.py

示例13: save_test

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def save_test(args, playbook_name, playbook):
    playbook_file = os.path.join(args.dir_path, 'citrix_adc_nitro_resource', 'tests', 'nitro', '%s.yaml' % playbook_name)
    with open(playbook_file, 'w') as fh:
        pyaml.dump(playbook, fh, vspacing=[1,0]) 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:6,代码来源:__init__.py

示例14: yamlstr_to_yaml

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def yamlstr_to_yaml(output_yamlfile, yamlstr):
    with open(output_yamlfile, 'w') as fw:
        load_data = yaml.load(yamlstr)
        yaml_data = pyaml.dump(load_data)
        fw.write(yaml_data) 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:7,代码来源:file_operations.py

示例15: python_to_yaml

# 需要导入模块: import pyaml [as 别名]
# 或者: from pyaml import dump [as 别名]
def python_to_yaml(output_yamlfile, pydata):
    with open(output_yamlfile, 'w') as fw:
        yaml_data = pyaml.dump(pydata)
        fw.write(yaml_data) 
开发者ID:citrix,项目名称:citrix-adc-ansible-modules,代码行数:6,代码来源:file_operations.py


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