generate.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  32. def main():
  33. ''' combine the necessary files to create the ansible module '''
  34. library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
  35. for fname, parts in FILES.items():
  36. with open(os.path.join(library, fname), 'w') as afd:
  37. afd.seek(0)
  38. afd.write(GEN_STR)
  39. for fpart in parts:
  40. with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd:
  41. # first line is pylint disable so skip it
  42. for idx, line in enumerate(pfd):
  43. if idx == 0 and 'skip-file' in line:
  44. continue
  45. afd.write(line)
  46. if __name__ == '__main__':
  47. main()