#76 Stick to the pep8 style standard-inventory-local
Closed 6 years ago by astepano. Opened 6 years ago by sturivny.
Unknown source pep8-local-inventory  into  master

@@ -3,10 +3,10 @@

  import argparse

  import json

  import os

- import shlex

  import sys

  

- def main(argv):

+ 

+ def main():

      parser = argparse.ArgumentParser(description="Inventory for local")

      parser.add_argument("--list", action="store_true", help="Verbose output")

      parser.add_argument('--host', help="Get host variables")
@@ -19,26 +19,29 @@

              data = list()

          sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))

      except RuntimeError as ex:

-         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))

+         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]),

+                                              str(ex)))

          return 1

- 

      return 0

  

+ 

  def list():

-     rpms = [ ]

-     hosts = [ ]

-     variables = { }

+     hosts = []

+     variables = {}

      if os.environ.get("TEST_SUBJECTS", None) == "local":

          vars = host("local")

          if vars:

              hosts.append("local")

              variables["local"] = vars

-     return { "subjects": { "hosts": hosts, "vars": { } }, "localhost": { "hosts": hosts, "vars": { } }, "_meta": { "hostvars": variables } }

+     return {"subjects": {"hosts": hosts, "vars": {}}, "localhost":

+         {"hosts": hosts, "vars": {}}, "_meta": {"hostvars": variables}}

+ 

  

  def host(host):

      if host == "local":

-         return { "ansible_connection": "local" }

+         return {"ansible_connection": "local"}

      return None

  

+ 

  if __name__ == '__main__':

-     sys.exit(main(sys.argv))

+     sys.exit(main())

Remove unused import.
Groome code to pep8 style.

Updated standard-inventory-local.py file

1 new commit added

  • Fix exception flow in standard-inventory-local
6 years ago

It is a bit not easy to review PR with two commits. Two commits change the same code twice.

Second commit:

54   if __name__ == '__main__':
55 -     sys.exit(main())
56 +     main()

First commit:

50 -     sys.exit(main(sys.argv))
51 +     sys.exit(main())

This PR has two logicaly independent commits. One of the PEP8, other commit fixes exceptions.

Such PR requires a more time to review.

1 new commit added

  • Stick to the pep8 style
6 years ago

It is a bit not easy to review PR with two commits. Two commits change the same code twice.
Second commit:
54 if name == 'main':
55 - sys.exit(main())
56 + main()

First commit:
50 - sys.exit(main(sys.argv))
51 + sys.exit(main())

This PR has two logicaly independent commits. One of the PEP8, other commit fixes exceptions.
Such PR requires a more time to review.

Updated, now there only Stick to the pep8 style standard-inventory-local commit

Pull-Request has been closed by astepano

6 years ago
Metadata