generate.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. '''
  3. Generate the openshift-ansible/roles/lib_openshift_cli/library/ modules.
  4. '''
  5. import os
  6. import yaml
  7. # pylint: disable=anomalous-backslash-in-string
  8. GEN_STR = "#!/usr/bin/env python\n" + \
  9. "# pylint: disable=missing-docstring\n" + \
  10. "# ___ ___ _ _ ___ ___ _ _____ ___ ___\n" + \
  11. "# / __| __| \| | __| _ \ /_\_ _| __| \\\n" + \
  12. "# | (_ | _|| .` | _|| / / _ \| | | _|| |) |\n" + \
  13. "# \___|___|_|\_|___|_|_\/_/_\_\_|_|___|___/_ _____\n" + \
  14. "# | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _|\n" + \
  15. "# | |) | (_) | | .` | (_) || | | _|| |) | | | |\n" + \
  16. "# |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_|\n"
  17. OPENSHIFT_ANSIBLE_PATH = os.path.dirname(os.path.realpath(__file__))
  18. OPENSHIFT_ANSIBLE_SOURCES_PATH = os.path.join(OPENSHIFT_ANSIBLE_PATH, 'generate_sources.yml') # noqa: E501
  19. def main():
  20. ''' combine the necessary files to create the ansible module '''
  21. library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
  22. sources = yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read())
  23. for fname, parts in sources.items():
  24. with open(os.path.join(library, fname), 'w') as afd:
  25. afd.seek(0)
  26. afd.write(GEN_STR)
  27. for fpart in parts:
  28. with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd:
  29. # first line is pylint disable so skip it
  30. for idx, line in enumerate(pfd):
  31. if idx in [0, 1] and 'flake8: noqa' in line \
  32. or 'pylint: skip-file' in line:
  33. continue
  34. afd.write(line)
  35. if __name__ == '__main__':
  36. main()