ruamel.yaml

merge two yaml files in python

不羁的心 提交于 2019-12-11 15:48:40
问题 I have two yaml files as mentioned below test1.yaml resources: server_group_1: type: OS::Nova::ServerGroup properties: name: { get_param: [server_groups, 5] } policies: [ { get_param: [server_group_types, 5] } ] server_group_2: type: OS::Nova::ServerGroup properties: name: { get_param: [server_groups, 8] } policies: [ { get_param: [server_group_types, 8] } ] output: check_1: description: Name of the instance value: { get_attr: [check_1, vname] } test2.yaml resources: server_group_4: type: OS:

Python Import error on installing ruamel.yaml in custom directory

只谈情不闲聊 提交于 2019-12-11 09:45:08
问题 I am using python 2.7.13 and I am facing problems importing ruamel.yaml when I install it in a custom directory. **ImportError: No module named ruamel.yaml** The command used is as follows: pip install --target=Z:\XYZ\globalpacks ruamel.yaml I have added this custom directory to PYTHONPATH env variable and also have a .pth file in this location with the following lines Z:\XYZ\globalpacks\anotherApp Z:\XYZ\globalpacks\ruamel There is another app installed similarly with the above settings and

Loading and dumping multiple yaml files with ruamel.yaml (python)

坚强是说给别人听的谎言 提交于 2019-12-11 09:33:48
问题 Using python 2 (atm) and ruamel.yaml 0.13.14 (RedHat EPEL) I'm currently writing some code to load yaml definitions, but they are split up in multiple files. The user-editable part contains eg. users: xxxx1: timestamp: '2018-10-22 11:38:28.541810' << : *userdefaults xxxx2: << : *userdefaults timestamp: '2018-10-22 11:38:28.541810' the defaults are stored in another file, which is not editable: userdefaults: &userdefaults # Default values for user settings fileCountQuota: 1000 diskSizeQuota:

How can I add a blank line before some data using Ruamel.yaml

ぃ、小莉子 提交于 2019-12-11 03:49:09
问题 I can't seem to figure out how I can add a blank line between data using Ruamel.yaml. Suppose I have data: --- a: 1 b: 2 I need to add to this so that I will have: --- a: 1 b: 2 c: 3 I understand that the blank line is implemented as a CommentToken: Comment(comment=None, items={'data': [None, None, CommentToken(value=u'\n\n'), None], 'b': [None, None, CommentToken(value=u'\n\n'), None]}) What I don't know is how to manipulate that structure. 回答1: That Comment object is not from the input that

Declare data type to ruamel.yaml so that it can represen/serialize it?

被刻印的时光 ゝ 提交于 2019-12-10 18:05:57
问题 I am using a function from a python library which returns an object with a specific data type. I would like to serialize that object to a yaml file and I would like to use ruamel.yaml. The problem is that ruamel.yaml does not know how to serialize the specific data type that the function returns and throws an exception: RepresenterError: cannot represent an object: <...> The question is how to "declare" the data type to ruamel.yaml so that it knows how to handle it. Note: I can't / I don't

ruamel.yaml equivalent of sort_keys?

China☆狼群 提交于 2019-12-10 15:54:53
问题 I'm trying to dump a Python dict to a YAML file using ruamel.yaml . I'm familiar with the json module's interface, where pretty-printing a dict is as simple as import json with open('outfile.json', 'w') as f: json.dump(mydict, f, indent=4, sort_keys=True) With ruamel.yaml , I've gotten as far as import ruamel.yaml with open('outfile.yaml', 'w') as f: ruamel.yaml.round_trip_dump(mydict, f, indent=2) but it doesn't seem to support the sort_keys option. ruamel.yaml also doesn't seem to have any

How can I get comments from a YAML file using ruamel.yaml in Python?

£可爱£侵袭症+ 提交于 2019-12-10 13:25:46
问题 I'd like to get the comment strings from a YAML file I loaded using ruamel.yaml . The project documentation lacks an API reference and I can't find a relevant example. What's the right way to access the comments? import ruamel.yaml yaml = """\ %YAML 1.2 --- # C1 a: # C2 # C3 # C4 b: 1 # C5 c: # A comment here will not be parsed properly by ruamel.yaml v0.11.14 - abc # C6 - xyz # C7 # C8 # C9 """ loaded = ruamel.yaml.round_trip_load(yaml) # Now what? 回答1: The library author comments on this in

How can I add a comment to a YAML file in Python

别说谁变了你拦得住时间么 提交于 2019-12-05 23:56:38
问题 I am writing a YAML file using https://pypi.python.org/pypi/ruamel.yaml The code is like this: import ruamel.yaml from ruamel.yaml.comments import CommentedSeq d = {} for m in ['B1', 'B2', 'B3']: d2 = {} for f in ['A1', 'A2', 'A3']: d2[f] = CommentedSeq(['test', 'test2']) if f != 'A2': d2[f].fa.set_flow_style() d[m] = d2 with open('test.yml', "w") as f: ruamel.yaml.dump( d, f, Dumper=ruamel.yaml.RoundTripDumper, default_flow_style=False, width=50, indent=8) I just want to add comment at the

How to dump YAML with explicit references?

北城余情 提交于 2019-12-05 08:31:48
Recursive references work great in ruamel.yaml or pyyaml : $ ruamel.yaml.dump(ruamel.yaml.load('&A [ *A ]')) '&id001 - *id001' However it (obviously) does not work on normal references: $ ruamel.yaml.dump(ruamel.yaml.load("foo: &foo { a: 42 }\nbar: { <<: *foo }")) bar: {a: 42} foo: {a: 42} I would like is to explicitly create a reference: data = {} data['foo'] = {'foo': {'a': 42}} data['bar'] = { '<<': data['foo'], 'b': 43 } $ ruamel.yaml.dump(data, magic=True) foo: &foo a: 42 bar: <<: *foo b: 43 This will be very useful to generate YAML output of large data structures that have lots of common

how to keep null value in yaml file while dumping though ruamel.yaml

ぐ巨炮叔叔 提交于 2019-12-04 03:15:53
问题 I have YAML file site.yaml : Kvm_BLOCK: ip_address: 10.X.X.X property: null server_type: zone loaded and then dumped with: ruamel.yaml.dump(site_yaml, new_file, Dumper=ruamel.yaml.RoundTripDumper) it becomes Kvm_BLOCK: ip_address: 10.X.X.X property: server_type: zone how to retain this null value in property block 回答1: The null value in YAML 1.2 (constructed as Python's None ) can be represented as null , Null , NULL and ~ , as specified here. Additionally: Nodes with empty content are