diff options
author | Sayed Shah <sayshah@redhat.com> | 2020-06-09 16:28:32 -0400 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-06-15 16:40:38 +0200 |
commit | be822b52e6b27c32cdc9ef34856c852ba4174024 (patch) | |
tree | 290db5117adefdb6b85db2b185af285b864fe235 /tools/generate-docs-nm-settings-docs-merge.py | |
parent | b6febb0fd088ecc93d154b60d758593ec50aa37e (diff) | |
download | NetworkManager-be822b52e6b27c32cdc9ef34856c852ba4174024.tar.gz |
all: reformat python files with python black
Part of !537.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/537
Diffstat (limited to 'tools/generate-docs-nm-settings-docs-merge.py')
-rwxr-xr-x | tools/generate-docs-nm-settings-docs-merge.py | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/tools/generate-docs-nm-settings-docs-merge.py b/tools/generate-docs-nm-settings-docs-merge.py index bf58669819..0da3a0bbaf 100755 --- a/tools/generate-docs-nm-settings-docs-merge.py +++ b/tools/generate-docs-nm-settings-docs-merge.py @@ -61,28 +61,33 @@ _setting_name_order = [ "wpan", ] + def _setting_name_order_idx(name): try: return _setting_name_order.index(name) except ValueError: return len(_setting_name_order) + def key_fcn_setting_name(n1): return (_setting_name_order_idx(n1), n1) -def iter_keys_of_dicts(dicts, key = None): + +def iter_keys_of_dicts(dicts, key=None): keys = set([k for d in dicts for k in d.keys()]) - return sorted(keys, key = key) + return sorted(keys, key=key) + def node_to_dict(node, tag, key_attr): dictionary = collections.OrderedDict() if node is not None: for n in node.iter(tag): k = n.get(key_attr) - assert(k is not None) + assert k is not None dictionary[k] = n return dictionary + def node_get_attr(nodes, name): for n in nodes: if n is None: @@ -92,18 +97,20 @@ def node_get_attr(nodes, name): return x return None + def node_set_attr(dst_node, name, nodes): x = node_get_attr(nodes, name) if x: dst_node.set(name, x) + ############################################################################### gl_only_from_first = False argv = list(sys.argv[1:]) while True: - if argv[0] == '--only-from-first': + if argv[0] == "--only-from-first": gl_only_from_first = True del argv[0] continue @@ -119,54 +126,51 @@ gl_input_files = list(argv[1:]) xml_roots = list([ET.parse(f).getroot() for f in gl_input_files]) -assert(all([root.tag == 'nm-setting-docs' for root in xml_roots])) +assert all([root.tag == "nm-setting-docs" for root in xml_roots]) -settings_roots = list([node_to_dict(root, 'setting', 'name') for root in xml_roots]) +settings_roots = list([node_to_dict(root, "setting", "name") for root in xml_roots]) -root_node = ET.Element('nm-setting-docs') +root_node = ET.Element("nm-setting-docs") for setting_name in iter_keys_of_dicts(settings_roots, key_fcn_setting_name): settings = list([d.get(setting_name) for d in settings_roots]) - if gl_only_from_first \ - and settings[0] is None: + if gl_only_from_first and settings[0] is None: continue - properties = list([node_to_dict(s, 'property', 'name') for s in settings]) + properties = list([node_to_dict(s, "property", "name") for s in settings]) - if gl_only_from_first \ - and not properties[0]: + if gl_only_from_first and not properties[0]: continue - setting_node = ET.SubElement(root_node, 'setting') + setting_node = ET.SubElement(root_node, "setting") - setting_node.set('name', setting_name) + setting_node.set("name", setting_name) - node_set_attr(setting_node, 'description', settings) - node_set_attr(setting_node, 'name_upper', settings) - node_set_attr(setting_node, 'alias', settings) + node_set_attr(setting_node, "description", settings) + node_set_attr(setting_node, "name_upper", settings) + node_set_attr(setting_node, "alias", settings) for property_name in iter_keys_of_dicts(properties): properties_attrs = list([p.get(property_name) for p in properties]) - if gl_only_from_first \ - and properties_attrs[0] is None: + if gl_only_from_first and properties_attrs[0] is None: continue - property_node = ET.SubElement(setting_node, 'property') - property_node.set('name', property_name) - property_node.set('name_upper', property_name.upper().replace('-', '_')) + property_node = ET.SubElement(setting_node, "property") + property_node.set("name", property_name) + property_node.set("name_upper", property_name.upper().replace("-", "_")) - x = node_get_attr(properties_attrs, 'format') + x = node_get_attr(properties_attrs, "format") if x: - property_node.set('type', x) + property_node.set("type", x) else: - node_set_attr(property_node, 'type', properties_attrs) + node_set_attr(property_node, "type", properties_attrs) - node_set_attr(property_node, 'default', properties_attrs) - node_set_attr(property_node, 'description', properties_attrs) - node_set_attr(property_node, 'alias', properties_attrs) + node_set_attr(property_node, "default", properties_attrs) + node_set_attr(property_node, "description", properties_attrs) + node_set_attr(property_node, "alias", properties_attrs) ET.ElementTree(root_node).write(gl_output_xml_file) |