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


Python yaml.dump_all方法代码示例

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


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

示例1: save_current_file

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def save_current_file():
	print("Saving current file: {}".format(current_file))
	def order_dict(d):
		return OrderedDict([
			("title", d["title"]),
			("type", d["type"]),
			("has_source", d["has_source"]),
			("info", OrderedDict([
				(key, d["info"][key] if key in d["info"] else "") for key in info_keys
			])),
			("streams", OrderedDict([
				(key, d["streams"][key] if key in d["streams"] else "") for key in stream_keys
			]))
		])
	
	try:
		sorted_docs = [order_dict(doc) for doc in current_docs]
		with open(current_file, "w", encoding="UTF-8") as f:
			yaml.dump_all(sorted_docs, f, default_flow_style=False, indent=4, allow_unicode=True)
	except:
		from traceback import print_exc
		print_exc()
		return False
	return True 
开发者ID:r-anime,项目名称:holo,代码行数:26,代码来源:editor.py

示例2: main

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def main():
  parser = ArgumentParser()
  parser.add_argument(
      "-m",
      "--manifest",
      dest="manifest",
      help="the manifest file to be parsed and updated")
  parser.add_argument(
      "-a",
      "--appname",
      dest="application_name",
      help="the application instance name")
  args = parser.parse_args()
  manifest = args.manifest
  app_name = args.application_name
  resources = load_resources_yaml(manifest)
  resources = [ensure_resource_has_app_label(r, app_name) for r in resources]
  with open(manifest, "w", encoding='utf-8') as out:
    yaml.dump_all(resources, out, default_flow_style=False, explicit_start=True) 
开发者ID:GoogleCloudPlatform,项目名称:marketplace-k8s-app-tools,代码行数:21,代码来源:ensure_k8s_apps_labels.py

示例3: dump_data_to_temp_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def dump_data_to_temp_yaml(data, temp_yaml):
    """
    Dump data to temporary yaml file

    Args:
        data (dict or list): dict or list (in case of multi_document) with
            data to dump to the yaml file.
        temp_yaml (str): file path of yaml file

    Returns:
        str: dumped yaml data

    """
    dumper = yaml.dump if isinstance(data, dict) else yaml.dump_all
    yaml_data = dumper(data)
    with open(temp_yaml, 'w') as yaml_file:
        yaml_file.write(yaml_data)
    if isinstance(data, dict):
        yaml_data_censored = dumper(censor_values(deepcopy(data)))
    else:
        yaml_data_censored = [
            dumper(censor_values(deepcopy(doc))) for doc in data
        ]
    logger.info(yaml_data_censored)
    return yaml_data 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:27,代码来源:templating.py

示例4: __init__

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def __init__(self, name, obj_dict_list, project, tmp_path):
        """
        Args:
            name (str): Name of this object config file
            obj_dict_list (list): List of dictionaries with k8s objects
            project (ocp.OCP): Instance of :class:`ocp.OCP` of ``Project``
                kind, specifying namespace where the object will be deployed.
            tmp_path (pathlib.Path): Directory where a temporary yaml file will
                be created. In test context, use pytest fixture `tmp_path`_.

        .. _`tmp_path`: https://docs.pytest.org/en/latest/tmpdir.html#the-tmp-path-fixture
        """
        self.name = name
        self.project = project
        # dump the job description in yaml format into a temporary file
        self._tmp_path = tmp_path
        self.yaml_file = tmp_path / f"objectconfig.{self.name}.yaml"
        self.yaml_file.write_text(yaml.dump_all(obj_dict_list)) 
开发者ID:red-hat-storage,项目名称:ocs-ci,代码行数:20,代码来源:objectconfigfile.py

示例5: formatted_response_handler

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def formatted_response_handler(response):
    """Base format handler for either json or yaml depending on call"""
    call = response.headers['Content-Type']
    if 'json' in call:
        try:
            return json.dumps(response.json(), sort_keys=True, indent=4)
        except ValueError:
            return (
                "This is not json and could not be printed as such. \n" +
                response.text
            )

    else:  # all others should be yaml
        try:
            return (yaml.dump_all(
                yaml.safe_load_all(response.content),
                width=79,
                indent=4,
                default_flow_style=False))
        except ValueError:
            return (
                "This is not yaml and could not be printed as such.\n" +
                response.text
            ) 
开发者ID:airshipit,项目名称:shipyard,代码行数:26,代码来源:format_utils.py

示例6: test_create_configdocs

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def test_create_configdocs(*args):
    succ_resp = stubs.gen_err_resp(message='Validations succeeded',
                                   sub_error_count=0,
                                   sub_info_count=0,
                                   reason='Validation',
                                   code=200)
    responses.add(responses.POST,
                  'http://shiptest/configdocs/design',
                  body=succ_resp,
                  status=201)

    filename = 'tests/unit/cli/create/sample_yaml/sample.yaml'
    document_data = yaml.dump_all(filename)
    file_list = (filename,)

    response = CreateConfigdocs(stubs.StubCliContext(),
                                'design',
                                'append',
                                False,
                                document_data,
                                file_list).invoke_and_return_resp()
    assert 'Configuration documents added.'
    assert 'Status: Validations succeeded' in response
    assert 'Reason: Validation' in response 
开发者ID:airshipit,项目名称:shipyard,代码行数:26,代码来源:test_create_actions.py

示例7: test_create_configdocs_409

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def test_create_configdocs_409(*args):
    err_resp = stubs.gen_err_resp(message='Invalid collection',
                                  sub_message='Buffer is either not...',
                                  sub_error_count=1,
                                  sub_info_count=0,
                                  reason='Buffermode : append',
                                  code=409)
    responses.add(responses.POST,
                  'http://shiptest/configdocs/design',
                  body=err_resp,
                  status=409)

    filename = 'tests/unit/cli/create/sample_yaml/sample.yaml'
    document_data = yaml.dump_all(filename)
    file_list = (filename,)

    response = CreateConfigdocs(stubs.StubCliContext(),
                                'design',
                                'append',
                                False,
                                document_data,
                                file_list).invoke_and_return_resp()
    assert 'Error: Invalid collection' in response
    assert 'Reason: Buffermode : append' in response
    assert 'Buffer is either not...' in response 
开发者ID:airshipit,项目名称:shipyard,代码行数:27,代码来源:test_create_actions.py

示例8: monkey_patch_pyyaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def monkey_patch_pyyaml():
    global pyyaml_load
    global pyyaml_load_all
    global pyyaml_dump_all

    if not pyyaml_load:
        log.info("monkey patching yaml.load...")
        pyyaml_load = yaml.load
        yaml.load = safe_yaml_load
    if not pyyaml_load_all:
        log.info("monkey patching yaml.load_all...")
        pyyaml_load_all = yaml.load_all
        yaml.load_all = safe_yaml_load_all
    if not pyyaml_dump_all:
        log.info("monkey patching yaml.dump_all... (affects all yaml dump operations)")
        pyyaml_dump_all = yaml.dump_all
        yaml.dump_all = safe_yaml_dump_all 
开发者ID:DataDog,项目名称:integrations-core,代码行数:19,代码来源:ddyaml.py

示例9: monkey_patch_pyyaml_reverse

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def monkey_patch_pyyaml_reverse():
    global pyyaml_load
    global pyyaml_load_all
    global pyyaml_dump_all

    if pyyaml_load:
        log.info("reversing monkey patch for yaml.load...")
        yaml.load = pyyaml_load
        pyyaml_load = None
    if pyyaml_load_all:
        log.info("reversing monkey patch for yaml.load_all...")
        yaml.load_all = pyyaml_load_all
        pyyaml_load_all = None
    if pyyaml_dump_all:
        log.info("reversing monkey patch for yaml.dump_all... (affects all yaml dump operations)")
        yaml.dump_all = pyyaml_dump_all
        pyyaml_dump_all = None 
开发者ID:DataDog,项目名称:integrations-core,代码行数:19,代码来源:ddyaml.py

示例10: safe_dump

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def safe_dump(data, **kwargs):
    kwargs["default_flow_style"] = False
    return yaml.dump_all(
        [data], None, Dumper=PrettyPrinterDumper, **kwargs) 
开发者ID:google,项目名称:rekall,代码行数:6,代码来源:yaml_utils.py

示例11: create_season_config

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def create_season_config(config, db, output_file):
	info("Checking for new shows")
	shows = _get_primary_source_shows(config)
	
	debug("Outputting new shows")
	with open(output_file, "w", encoding="utf-8") as f:
		yaml.dump_all(shows, f, explicit_start=True, default_flow_style=False) 
开发者ID:r-anime,项目名称:holo,代码行数:9,代码来源:module_find_shows.py

示例12: cluster

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def cluster(kind_cluster) -> Generator[dict, None, None]:
    docker_image = os.getenv("TEST_IMAGE")
    kind_cluster.load_docker_image(docker_image)

    logging.info("Deploying kube-web-view ...")
    deployment_manifests_path = Path(__file__).parent / "deployment.yaml"

    kubectl = kind_cluster.kubectl

    with NamedTemporaryFile(mode="w+") as tmp:
        with deployment_manifests_path.open() as f:
            resources = list(yaml.safe_load_all(f))
        dep = resources[-1]
        assert (
            dep["kind"] == "Deployment" and dep["metadata"]["name"] == "kube-web-view"
        )
        dep["spec"]["template"]["spec"]["containers"][0]["image"] = docker_image
        yaml.dump_all(documents=resources, stream=tmp)
        kubectl("apply", "-f", tmp.name)

    logging.info("Deploying other test resources ...")
    kubectl("apply", "-f", str(Path(__file__).parent / "test-resources.yaml"))

    logging.info("Waiting for rollout ...")
    kubectl("rollout", "status", "deployment/kube-web-view")

    with kind_cluster.port_forward("service/kube-web-view", 80) as port:
        url = f"http://localhost:{port}/"
        yield {"url": url} 
开发者ID:hjacobs,项目名称:kube-web-view,代码行数:31,代码来源:conftest.py

示例13: dump

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def dump(value: SequenceView):
    st = dump_all(value, default_flow_style=False)
    if not st.startswith('---'):
        st = '---\n' + st
    return st 
开发者ID:datawire,项目名称:ambassador,代码行数:7,代码来源:parser.py

示例14: services

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def services(generation_counter, kind):
    if kind in app.elements:
        return yaml.dump_all(app.elements[kind], Dumper=yaml_dumper), 200
    else:
        return "no such element", 404 
开发者ID:datawire,项目名称:ambassador,代码行数:7,代码来源:fake_configd.py

示例15: _write

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import dump_all [as 别名]
def _write(self, output_dir):
        documents = self.get_documents()
        with open(os.path.join(output_dir, 'certificates.yaml'), 'w') as f:
            # Don't use safe_dump_all so we can block format certificate data.
            yaml.dump_all(
                documents,
                stream=f,
                default_flow_style=False,
                explicit_start=True,
                indent=2) 
开发者ID:airshipit,项目名称:promenade,代码行数:12,代码来源:generator.py


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