本文整理匯總了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))
示例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))
示例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.
)
示例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')
示例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
示例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()
示例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'])
示例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
示例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()
示例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)
示例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)
示例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)
示例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)