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


Python yaml.safe_dump_all方法代码示例

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


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

示例1: main

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def main():
  parser = ArgumentParser(description=_PROG_HELP)
  schema_values_common.add_to_argument_parser(parser)
  parser.add_argument('--deployer_image', required=True)
  parser.add_argument('--deployer_entrypoint', default=None)
  parser.add_argument('--deployer_service_account_name', required=True)
  parser.add_argument('--version_repo', default=None)
  parser.add_argument('--image_pull_secret', default=None)
  args = parser.parse_args()

  schema = schema_values_common.load_schema(args)
  values = schema_values_common.load_values(args)
  manifests = process(
      schema,
      values,
      deployer_image=args.deployer_image,
      deployer_entrypoint=args.deployer_entrypoint,
      version_repo=args.version_repo,
      image_pull_secret=args.image_pull_secret,
      deployer_service_account_name=args.deployer_service_account_name)
  print(yaml.safe_dump_all(manifests, default_flow_style=False, indent=2)) 
开发者ID:GoogleCloudPlatform,项目名称:marketplace-k8s-app-tools,代码行数:23,代码来源:provision.py

示例2: create_new_app_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def create_new_app_yaml(source_file, app_name):
  yaml_spec = YamlSpec(source_file).to_file()
  with open(yaml_spec, 'r') as stream:
    try:
      yaml_content = list(yaml.load_all(stream))
    except yaml.YAMLError as exc:
      raise HokusaiError("Cannot read source yaml file %s." % source_file)

  for c in yaml_content: update_namespace(c, clean_string(app_name))

  new_namespace = OrderedDict([
      ('apiVersion', 'v1'),
      ('kind', 'Namespace'),
      ('metadata', {
        'name': clean_string(app_name)
      })
    ])
  yaml_content = [new_namespace] + yaml_content

  with open(os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % app_name), 'w') as output:
    output.write(YAML_HEADER)
    yaml.safe_dump_all(yaml_content, output, default_flow_style=False)

  print_green("Created %s/%s.yml" % (HOKUSAI_CONFIG_DIR, app_name)) 
开发者ID:artsy,项目名称:hokusai,代码行数:26,代码来源:namespace.py

示例3: dump

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def dump(self, stream):
        """
        Dump the generated settings file contents to the given stream.

        Arguments:
            stream (file):
                An open writable file object to dump settings into.
        """
        # only dump the secrets yaml document if it is populated
        docs_to_dump = [self.data]
        if self.secrets:
            docs_to_dump.append(self.secrets)

        yaml.safe_dump_all(
            docs_to_dump,
            stream=stream,
            default_flow_style=False,  # Represent objects using indented blocks
                                       # rather than inline enclosures.
            explicit_start=True,  # Begin the first document with '---', per
                                  # our usual settings file syntax.
        ) 
开发者ID:edx-unsupported,项目名称:edx-load-tests,代码行数:23,代码来源:settings.py

示例4: _generage

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def _generage(self):
        """
        第一次产生测试yaml的方法
        :return:
        """
        file_list = glob.glob('./test/conf/*')
        for file_name in file_list:
            yaml_info_list = load_from_yaml(file_name)
            print file_name
            yaml_list = []
            for yaml_info in yaml_info_list:
                match_dict_list = Nlu_Framework.match(force_utf8_new(yaml_info['input']))
                result_dict = {"input": force_utf8_new(yaml_info['input']),
                               "output": match_dict_list[0]}
                yaml_list.append(result_dict)
            yaml_list = force_utf8_new(yaml_list)
            print yaml.safe_dump_all(yaml_list, allow_unicode=True, encoding='utf-8') 
开发者ID:JK-River,项目名称:RobotAIEngine,代码行数:19,代码来源:nlu_test.py

示例5: CompileReport

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def CompileReport(self, mediator):
    """Compiles an analysis report.

    Args:
      mediator (AnalysisMediator): mediates interactions between analysis
          plugins and other components, such as storage and dfvfs.

    Returns:
      AnalysisReport: report.
    """
    # TODO: move YAML representation out of plugin and into serialization.
    lines_of_text = []
    if self._output_format == 'yaml':
      lines_of_text.append(
          yaml.safe_dump_all(self._service_collection.services))
    else:
      lines_of_text.append('Listing Windows Services')
      for service in self._service_collection.services:
        lines_of_text.append(self._FormatServiceText(service))
        lines_of_text.append('')

    lines_of_text.append('')
    report_text = '\n'.join(lines_of_text)
    return reports.AnalysisReport(plugin_name=self.NAME, text=report_text)

  # pylint: disable=unused-argument 
开发者ID:log2timeline,项目名称:plaso,代码行数:28,代码来源:windows_services.py

示例6: test_test_controller_validation_failure_returns_400

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def test_test_controller_validation_failure_returns_400(
            self, mock_tiller, mock_manifest):
        rules = {'armada:test_manifest': '@'}
        self.policy.set_rules(rules)

        manifest_path = os.path.join(
            os.getcwd(), 'examples', 'keystone-manifest.yaml')
        with open(manifest_path, 'r') as f:
            payload = f.read()

        documents = list(yaml.safe_load_all(payload))
        documents[0]['schema'] = 'totally-invalid'
        invalid_payload = yaml.safe_dump_all(documents)

        resp = self.app.simulate_post('/api/v1.0/tests', body=invalid_payload)
        self.assertEqual(400, resp.status_code)

        m_tiller = mock_tiller.return_value
        m_tiller.__enter__.return_value = m_tiller

        resp_body = json.loads(resp.text)
        self.assertEqual(400, resp_body['code'])
        self.assertEqual(1, resp_body['details']['errorCount'])
        self.assertIn(
            {
                'message': (
                    'An error occurred while building chart group: '
                    'Could not build ChartGroup named '
                    '"keystone-infra-services".'),
                'error': True,
                'kind': 'ValidationMessage',
                'level': 'Error',
                'name': 'ARM001',
                'documents': []
            }, resp_body['details']['messageList'])
        self.assertEqual(
            (
                'Failed to validate documents or generate Armada '
                'Manifest from documents.'), resp_body['message'])
        m_tiller.__exit__.assert_called() 
开发者ID:airshipit,项目名称:armada,代码行数:42,代码来源:test_test_controller.py

示例7: test_test_controller_validation_failure_returns_400

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def test_test_controller_validation_failure_returns_400(
            self, *_):
        rules = {'armada:tests_manifest': '@'}
        self.policy.set_rules(rules)

        manifest_path = os.path.join(os.getcwd(), 'examples',
                                     'keystone-manifest.yaml')
        with open(manifest_path, 'r') as f:
            payload = f.read()

        documents = list(yaml.safe_load_all(payload))
        documents[0]['schema'] = 'totally-invalid'
        invalid_payload = yaml.safe_dump_all(documents)

        resp = self.app.simulate_post('/api/v1.0/tests', body=invalid_payload)
        self.assertEqual(400, resp.status_code)

        resp_body = json.loads(resp.text)
        self.assertEqual(400, resp_body['code'])
        self.assertEqual(1, resp_body['details']['errorCount'])
        self.assertIn(
            {'message': (
                'An error occurred while generating the manifest: Could not '
                'find dependency chart helm-toolkit in armada/Chart/v1.'),
             'error': True,
             'kind': 'ValidationMessage',
             'level': 'Error',
             'name': 'ARM001',
             'documents': []},
            resp_body['details']['messageList'])
        self.assertEqual(('Failed to validate documents or generate Armada '
                          'Manifest from documents.'),
                         resp_body['message']) 
开发者ID:att-comdev,项目名称:armada,代码行数:35,代码来源:test_test_controller.py

示例8: FormatArtifacts

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def FormatArtifacts(self, artifacts):
    """Formats artifacts to desired output format.

    Args:
      artifacts (list[ArtifactDefinition]): artifact definitions.

    Returns:
      str: formatted string of artifact definition.
    """
    # TODO: improve output formatting of yaml
    artifact_definitions = [artifact.AsDict() for artifact in artifacts]
    yaml_data = yaml.safe_dump_all(artifact_definitions)
    return yaml_data 
开发者ID:ForensicArtifacts,项目名称:artifacts,代码行数:15,代码来源:writer.py

示例9: _yaml_safe_dump_all

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def _yaml_safe_dump_all(documents):
    f = io.StringIO()
    yaml.safe_dump_all(documents, f)
    return f.getvalue() 
开发者ID:airshipit,项目名称:promenade,代码行数:6,代码来源:renderer.py

示例10: write

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def write(self, path: str):
        """
        Write all current config entries to a yaml file.

        * `path`: The file path to write. Will be overwritten!
        """
        with open(path, mode='w') as file:
            yaml.safe_dump_all((
                {"module": module_name, "config": config_entries}
                for module_name, config_entries in self.config_per_module.items()),
                file,
                default_flow_style=False) 
开发者ID:Roboy,项目名称:ravestate,代码行数:14,代码来源:config.py

示例11: dump

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def dump(outfile, resources, included_kinds, app_name, app_uid, app_api_version,
         deployer_name, deployer_uid):

  def maybe_assign_ownership(resource):
    if resource["kind"] in _CLUSTER_SCOPED_KINDS:
      # Cluster-scoped resources cannot be owned by a namespaced resource:
      # https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#owners-and-dependents
      log.info("Application '{:s}' does not own cluster-scoped '{:s}/{:s}'",
               app_name, resource["kind"], resource["metadata"]["name"])

    # Deployer-owned resources should not be owned by the Application, as
    # they should be deleted with the deployer service account (not the app).
    if deployer_name and deployer_uid and should_be_deployer_owned(resource):
      log.info("ServiceAccount '{:s}' owns '{:s}/{:s}'", deployer_name,
               resource["kind"], resource["metadata"]["name"])
      resource = copy.deepcopy(resource)
      set_service_account_resource_ownership(
          account_uid=deployer_uid,
          account_name=deployer_name,
          resource=resource)
    elif included_kinds is None or resource["kind"] in included_kinds:
      log.info("Application '{:s}' owns '{:s}/{:s}'", app_name,
               resource["kind"], resource["metadata"]["name"])
      resource = copy.deepcopy(resource)
      set_app_resource_ownership(
          app_uid=app_uid,
          app_name=app_name,
          app_api_version=app_api_version,
          resource=resource)

    return resource

  to_be_dumped = [maybe_assign_ownership(resource) for resource in resources]
  yaml.safe_dump_all(to_be_dumped, outfile, default_flow_style=False, indent=2) 
开发者ID:GoogleCloudPlatform,项目名称:marketplace-k8s-app-tools,代码行数:36,代码来源:set_ownership.py

示例12: write_resources

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def write_resources(resources, outfile):
  yaml.safe_dump_all(resources, outfile, default_flow_style=False, indent=2) 
开发者ID:GoogleCloudPlatform,项目名称:marketplace-k8s-app-tools,代码行数:4,代码来源:set_app_labels.py

示例13: main

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_dump_all [as 别名]
def main():

  parser = ArgumentParser(description=_PROG_HELP)
  parser.add_argument(
      "--app_name", required=True, help="the name of the application instance")
  parser.add_argument(
      "--app_uid", required=True, help="the uid of the application instance")
  parser.add_argument(
      "--app_api_version",
      required=True,
      help="apiVersion of the Application CRD")
  parser.add_argument(
      "--manifests", required=True, help="the configuration for tests")
  parser.add_argument(
      "--out_manifests",
      required=True,
      help="the file to write non-test resources to")
  parser.add_argument(
      "--out_test_manifests",
      required=True,
      help="the file to write test resources to")
  args = parser.parse_args()

  if os.path.isfile(args.manifests):
    resources = load_resources_yaml(args.manifests)
  else:
    resources = []
    for filename in os.listdir(args.manifests):
      resources += load_resources_yaml(os.path.join(args.manifests, filename))

  test_resources = []
  nontest_resources = []
  for resource in resources:
    full_name = "{}/{}".format(resource['kind'],
                               deep_get(resource, 'metadata', 'name'))
    if deep_get(resource, 'metadata', 'annotations',
                GOOGLE_CLOUD_TEST) == 'test':
      print("INFO Tester resource: {}".format(full_name))
      set_app_resource_ownership(
          app_uid=args.app_uid,
          app_name=args.app_name,
          app_api_version=args.app_api_version,
          resource=resource)
      test_resources.append(resource)
    else:
      print("INFO Prod resource: {}".format(full_name))
      nontest_resources.append(resource)

  if nontest_resources:
    with open(args.out_manifests, "w", encoding='utf-8') as outfile:
      yaml.safe_dump_all(nontest_resources, outfile, default_flow_style=False)

  if test_resources:
    with open(args.out_test_manifests, "a", encoding='utf-8') as test_outfile:
      yaml.safe_dump_all(test_resources, test_outfile, default_flow_style=False) 
开发者ID:GoogleCloudPlatform,项目名称:marketplace-k8s-app-tools,代码行数:57,代码来源:separate_tester_resources.py


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