diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-01-18 13:39:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 13:39:43 -0500 |
commit | 7a0228f432a0d68bd63a68b940a7913d4a6a7e7c (patch) | |
tree | 351507d1744326f27bcf23e523e0bacc6de2a7fe /roles/lib_openshift/src/generate.py | |
parent | b4d76724b764d0f18ace622bafb9ce390fdd9f19 (diff) | |
parent | 3fd3cd3a07d9f000c8cb8bd1b7a49ac2af675696 (diff) | |
download | openshift-7a0228f432a0d68bd63a68b940a7913d4a6a7e7c.tar.gz openshift-7a0228f432a0d68bd63a68b940a7913d4a6a7e7c.tar.bz2 openshift-7a0228f432a0d68bd63a68b940a7913d4a6a7e7c.tar.xz openshift-7a0228f432a0d68bd63a68b940a7913d4a6a7e7c.zip |
Merge pull request #3092 from kwoodson/lib_openshift_3.3
lib_openshift. This is the initial commit that has oc_route.
Diffstat (limited to 'roles/lib_openshift/src/generate.py')
-rwxr-xr-x | roles/lib_openshift/src/generate.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/roles/lib_openshift/src/generate.py b/roles/lib_openshift/src/generate.py new file mode 100755 index 000000000..8451d99ab --- /dev/null +++ b/roles/lib_openshift/src/generate.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +''' + Generate the openshift-ansible/roles/lib_openshift_cli/library/ modules. +''' + +import argparse +import os +import yaml +import six + +OPENSHIFT_ANSIBLE_PATH = os.path.dirname(os.path.realpath(__file__)) +OPENSHIFT_ANSIBLE_SOURCES_PATH = os.path.join(OPENSHIFT_ANSIBLE_PATH, 'sources.yml') # noqa: E501 + + +class GenerateAnsibleException(Exception): + '''General Exception for generate function''' + pass + + +def parse_args(): + '''parse arguments to generate''' + parser = argparse.ArgumentParser(description="Generate ansible modules.") + parser.add_argument('--verify', action='store_true', default=False, + help='Verify library code matches the generated code.') + + return parser.parse_args() + + +def generate(parts): + '''generate the source code for the ansible modules''' + + data = six.StringIO() + for fpart in parts: + # first line is pylint disable so skip it + with open(os.path.join(OPENSHIFT_ANSIBLE_PATH, fpart)) as pfd: + for idx, line in enumerate(pfd): + if idx in [0, 1] and 'flake8: noqa' in line or 'pylint: skip-file' in line: # noqa: E501 + continue + + data.write(line) + + return data + + +def main(): + ''' combine the necessary files to create the ansible module ''' + args = parse_args() + + library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/') + sources = yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read()) + + for fname, parts in sources.items(): + data = generate(parts) + fname = os.path.join(library, fname) + if args.verify: + if not open(fname).read() == data.getvalue(): + raise GenerateAnsibleException('Generated content does not match for %s' % fname) + + continue + + with open(fname, 'w') as afd: + afd.seek(0) + afd.write(data.getvalue()) + + +if __name__ == '__main__': + main() |