From 18a32cfa40902dd2b138d5978a41a6d16d2eecae Mon Sep 17 00:00:00 2001 From: Bruno Travouillon Date: Tue, 30 Jun 2020 11:34:03 -0400 Subject: [PATCH] fix: code cleanup in inventory converter helper flake8: - 2 E265 block comment should start with '# ' - 4 E302 expected 2 blank lines, found 1 - 1 E305 expected 2 blank lines after class or function definition, found 1 --- .../inventory-converter-1.3-network_interfaces.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/inventory-converter-1.3-network_interfaces.py b/tools/inventory-converter-1.3-network_interfaces.py index 72ea2d41b..c7a512d75 100755 --- a/tools/inventory-converter-1.3-network_interfaces.py +++ b/tools/inventory-converter-1.3-network_interfaces.py @@ -3,6 +3,7 @@ import sys import yaml + # Indent list with PyYAML # From https://web.archive.org/web/20170903201521/https://pyyaml.org/ticket/64#comment:5 class MyDumper(yaml.Dumper): @@ -15,6 +16,7 @@ def increase_indent(self, flow=False, indentless=False): def represent_dict_preserve_order(self, data): return self.represent_dict(data.items()) + # Search and convert network_interfaces from dict to list # def search_network_interfaces(dictionary): @@ -40,15 +42,17 @@ def search_network_interfaces(dictionary): return dictionary -def usage(): - print(f"Usage: {sys.argv[0]} /etc/bluebanquise/inventory/cluster/nodes/file.yml") + +def usage(command): + print(f"Usage: {command} /etc/bluebanquise/inventory/cluster/nodes/file.yml") + def main(): MyDumper.add_representer(dict, MyDumper.represent_dict_preserve_order) if len(sys.argv) != 2: - usage() + usage(sys.argv[0]) exit(1) hostsfile = sys.argv[1] @@ -57,11 +61,7 @@ def main(): with open(hostsfile, 'r') as fd: try: inventory = yaml.load(fd, Loader=yaml.FullLoader) - #print(yaml.dump(inventory)) - new_inventory = search_network_interfaces(inventory) - #print(yaml.dump(new_inventory, Dumper=MyDumper)) - except yaml.YAMLError as exc: print(exc) @@ -72,5 +72,6 @@ def main(): $ diff -u {hostsfile} {outfile} | less $ mv {outfile} {hostsfile}''') + if __name__ == "__main__": main()