generate.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. '''
  3. Generate the openshift-ansible/roles/lib_openshift_cli/library/ modules.
  4. '''
  5. import os
  6. # pylint: disable=anomalous-backslash-in-string
  7. GEN_STR = "#!/usr/bin/env python\n" + \
  8. "# ___ ___ _ _ ___ ___ _ _____ ___ ___\n" + \
  9. "# / __| __| \| | __| _ \ /_\_ _| __| \\\n" + \
  10. "# | (_ | _|| .` | _|| / / _ \| | | _|| |) |\n" + \
  11. "# \___|___|_|\_|___|_|_\/_/_\_\_|_|___|___/_ _____\n" + \
  12. "# | \ / _ \ | \| |/ _ \_ _| | __| \_ _|_ _|\n" + \
  13. "# | |) | (_) | | .` | (_) || | | _|| |) | | | |\n" + \
  14. "# |___/ \___/ |_|\_|\___/ |_| |___|___/___| |_|\n"
  15. OPENSHIFT_ANSIBLE_PATH = os.path.dirname(os.path.realpath(__file__))
  16. FILES = {'oc_obj.py': ['src/base.py',
  17. '../../lib_yaml_editor/build/src/yedit.py',
  18. 'src/obj.py',
  19. 'ansible/obj.py',
  20. ],
  21. 'oc_secret.py': ['src/base.py',
  22. '../../lib_yaml_editor/build/src/yedit.py',
  23. 'src/secret.py',
  24. 'ansible/secret.py',
  25. ],
  26. 'oc_edit.py': ['src/base.py',
  27. '../../lib_yaml_editor/build/src/yedit.py',
  28. 'src/edit.py',
  29. 'ansible/edit.py',
  30. ],
  31. 'oadm_router.py': ['src/base.py',
  32. '../../lib_yaml_editor/build/src/yedit.py',
  33. 'src/router.py',
  34. 'ansible/router.py',
  35. ],
  36. }
  37. def main():
  38. ''' combine the necessary files to create the ansible module '''
  39. library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
  40. for fname, parts in FILES.items():
  41. with open(os.path.join(library, fname), 'w') as afd:
  42. afd.seek(0)
  43. afd.write(GEN_STR)
  44. for fpart in parts:
  45. with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd:
  46. # first line is pylint disable so skip it
  47. for idx, line in enumerate(pfd):
  48. if idx == 0 and 'skip-file' in line:
  49. continue
  50. afd.write(line)
  51. if __name__ == '__main__':
  52. main()