diff options
author | Scott Dodson <sdodson@redhat.com> | 2017-01-10 16:27:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 16:27:29 -0500 |
commit | 393eccd3a5347a13eda5d627f3cc35aeeb42f1cc (patch) | |
tree | 668806139fc108ce6763cc95a640aedffa8a4ecf /git/yaml_validation.py | |
parent | 706c582b2482d5cc3a4fb28b348ce5b856fc9c26 (diff) | |
parent | 33da32dbcdc5e93e26bccf59d0781a60386b6b04 (diff) | |
download | openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.gz openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.bz2 openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.tar.xz openshift-393eccd3a5347a13eda5d627f3cc35aeeb42f1cc.zip |
Merge pull request #3007 from detiber/toxification
More Toxification
Diffstat (limited to 'git/yaml_validation.py')
-rwxr-xr-x | git/yaml_validation.py | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/git/yaml_validation.py b/git/yaml_validation.py deleted file mode 100755 index 6672876bb..000000000 --- a/git/yaml_validation.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# flake8: noqa -# -# python yaml validator for a git commit -# -''' -python yaml validator for a git commit -''' -import shutil -import sys -import os -import tempfile -import subprocess -import yaml - -def get_changes(oldrev, newrev, tempdir): - '''Get a list of git changes from oldrev to newrev''' - proc = subprocess.Popen(['/usr/bin/git', 'diff', '--name-only', oldrev, - newrev, '--diff-filter=ACM'], stdout=subprocess.PIPE) - stdout, _ = proc.communicate() - files = stdout.split('\n') - - # No file changes - if not files: - return [] - - cmd = '/usr/bin/git archive %s %s | /bin/tar x -C %s' % (newrev, " ".join(files), tempdir) - proc = subprocess.Popen(cmd, shell=True) - _, _ = proc.communicate() - - rfiles = [] - for dirpath, _, fnames in os.walk(tempdir): - for fname in fnames: - rfiles.append(os.path.join(dirpath, fname)) - - return rfiles - -def main(): - ''' - Perform yaml validation - ''' - results = [] - try: - tmpdir = tempfile.mkdtemp(prefix='jenkins-git-') - old, new, _ = sys.argv[1:] - - for file_mod in get_changes(old, new, tmpdir): - - print "+++++++ Received: %s" % file_mod - - # if the file extensions is not yml or yaml, move along. - if not file_mod.endswith('.yml') and not file_mod.endswith('.yaml'): - continue - - # We use symlinks in our repositories, ignore them. - if os.path.islink(file_mod): - continue - - try: - yaml.load(open(file_mod)) - results.append(True) - - except yaml.scanner.ScannerError as yerr: - print yerr - results.append(False) - finally: - shutil.rmtree(tmpdir) - - if not all(results): - sys.exit(1) - -if __name__ == "__main__": - main() |