mirror of
https://github.com/openshift/openshift-ansible.git
synced 2026-02-05 15:45:57 +01:00
Updated the generate.py scripts for tox and virtualenv.
This commit is contained in:
@@ -10,6 +10,7 @@ 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
|
||||
LIBRARY = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
|
||||
|
||||
|
||||
class GenerateAnsibleException(Exception):
|
||||
@@ -42,22 +43,29 @@ def generate(parts):
|
||||
return data
|
||||
|
||||
|
||||
def get_sources():
|
||||
'''return the path to the generate sources'''
|
||||
return yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read())
|
||||
|
||||
|
||||
def verify():
|
||||
'''verify if the generated code matches the library code'''
|
||||
for fname, parts in get_sources().items():
|
||||
data = generate(parts)
|
||||
fname = os.path.join(LIBRARY, fname)
|
||||
if not open(fname).read() == data.getvalue():
|
||||
raise GenerateAnsibleException('Generated content does not match for %s' % fname)
|
||||
|
||||
|
||||
def main():
|
||||
''' combine the necessary files to create the ansible module '''
|
||||
args = parse_args()
|
||||
if args.verify:
|
||||
verify()
|
||||
|
||||
library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
|
||||
sources = yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read())
|
||||
|
||||
for fname, parts in sources.items():
|
||||
for fname, parts in get_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
|
||||
|
||||
fname = os.path.join(LIBRARY, fname)
|
||||
with open(fname, 'w') as afd:
|
||||
afd.seek(0)
|
||||
afd.write(data.getvalue())
|
||||
|
||||
@@ -134,6 +134,12 @@ options:
|
||||
required: false
|
||||
default: true
|
||||
aliases: []
|
||||
separator:
|
||||
description:
|
||||
- The separator being used when parsing strings.
|
||||
required: false
|
||||
default: '.'
|
||||
aliases: []
|
||||
author:
|
||||
- "Kenny Woodson <kwoodson@redhat.com>"
|
||||
extends_documentation_fragment: []
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import six
|
||||
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
|
||||
LIBRARY = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
|
||||
|
||||
|
||||
class GenerateAnsibleException(Exception):
|
||||
@@ -42,22 +43,29 @@ def generate(parts):
|
||||
return data
|
||||
|
||||
|
||||
def get_sources():
|
||||
'''return the path to the generate sources'''
|
||||
return yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read())
|
||||
|
||||
|
||||
def verify():
|
||||
'''verify if the generated code matches the library code'''
|
||||
for fname, parts in get_sources().items():
|
||||
data = generate(parts)
|
||||
fname = os.path.join(LIBRARY, fname)
|
||||
if not open(fname).read() == data.getvalue():
|
||||
raise GenerateAnsibleException('Generated content does not match for %s' % fname)
|
||||
|
||||
|
||||
def main():
|
||||
''' combine the necessary files to create the ansible module '''
|
||||
args = parse_args()
|
||||
if args.verify:
|
||||
verify()
|
||||
|
||||
library = os.path.join(OPENSHIFT_ANSIBLE_PATH, '..', 'library/')
|
||||
sources = yaml.load(open(OPENSHIFT_ANSIBLE_SOURCES_PATH).read())
|
||||
|
||||
for fname, parts in sources.items():
|
||||
for fname, parts in get_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
|
||||
|
||||
fname = os.path.join(LIBRARY, fname)
|
||||
with open(fname, 'w') as afd:
|
||||
afd.seek(0)
|
||||
afd.write(data.getvalue())
|
||||
|
||||
22
setup.py
22
setup.py
@@ -6,7 +6,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import fnmatch
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
# Always prefer setuptools over distutils
|
||||
@@ -170,22 +170,32 @@ class OpenShiftAnsibleGenerateValidation(Command):
|
||||
'playbooks',
|
||||
'utils'],
|
||||
None,
|
||||
'generate.py')
|
||||
'generate.py$')
|
||||
|
||||
if len(generate_files) < 1:
|
||||
print('Did not find any code generation. Please verify module code generation.') # noqa: E501
|
||||
raise SystemExit(1)
|
||||
|
||||
# call them with --verify
|
||||
errors = False
|
||||
for gen in generate_files:
|
||||
print('Checking generated module code: {0}'.format(gen))
|
||||
try:
|
||||
subprocess.call([gen, '--verify'])
|
||||
except subprocess.CalledProcessError as cpe:
|
||||
print(cpe)
|
||||
sys.path.insert(0, os.path.dirname(gen))
|
||||
# we are importing dynamically. This isn't in
|
||||
# the python path.
|
||||
# pylint: disable=import-error
|
||||
import generate
|
||||
generate.verify()
|
||||
except generate.GenerateAnsibleException as gae:
|
||||
print(gae.args)
|
||||
errors = True
|
||||
|
||||
if errors:
|
||||
print('Found errors while generating module code.')
|
||||
raise SystemExit(1)
|
||||
|
||||
print('\nAll generate scripts passed.\n')
|
||||
|
||||
|
||||
class UnsupportedCommand(Command):
|
||||
''' Basic Command to override unsupported commands '''
|
||||
|
||||
Reference in New Issue
Block a user