diff options
-rwxr-xr-x | validate.py | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/validate.py b/validate.py index faae744..30e7479 100755 --- a/validate.py +++ b/validate.py @@ -29,7 +29,7 @@ def publish_result(result_message_list): print_stderr(result_message) -def pep8_check(filepath, ignore_options=None): +def pep8_check(filepath, ignore_options=[]): _fmt = "%(row)d:%(col)d: %(code)s %(text)s" options = { 'ignore': ignore_options, @@ -58,12 +58,13 @@ def pep8_check(filepath, ignore_options=None): print_stderr(message) return 0 + def metadata_check(filepath): if filepath.lower().endswith("yaml"): with open(filepath, "r") as f: result_message_list = [] y = yaml.load(f.read()) - if not 'metadata' in y.keys(): + if 'metadata' not in y.keys(): result_message_list.append("* METADATA [FAILED]: " + filepath) result_message_list.append("\tmetadata section missing") publish_result(result_message_list) @@ -78,10 +79,10 @@ def metadata_check(filepath): 'devices']) if not mandatory_keys.issubset(set(metadata_dict.keys())): result_message_list.append("* METADATA [FAILED]: " + filepath) - result_message_list.append("\tmandatory keys missing: %s" % \ - mandatory_keys.difference(set(metadata_dict.keys()))) - result_message_list.append("\tactual keys present: %s" % \ - metadata_dict.keys()) + result_message_list.append("\tmandatory keys missing: %s" % + mandatory_keys.difference(set(metadata_dict.keys()))) + result_message_list.append("\tactual keys present: %s" % + metadata_dict.keys()) publish_result(result_message_list) return 1 for key in mandatory_keys: @@ -94,6 +95,7 @@ def metadata_check(filepath): publish_result(result_message_list) return 0 + def validate_yaml(filename): with open(filename, "r") as f: try: @@ -116,7 +118,9 @@ def validate_yaml(filename): def validate_shell(filename, ignore_options): ignore_string = "" if ignore_options is not None: - ignore_string = "-e %s" % ignore_options + ignore_string = "-e %s" % " ".join(ignore_options) + if len(ignore_string) < 4: # contains only "-e " + ignore_string = "" cmd = 'shellcheck %s' % ignore_string return validate_external(cmd, filename, "SHELLCHECK") @@ -192,28 +196,28 @@ def main(args): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-p", - "--pep8-ignore", - nargs="*", - default="E501", - help="Space separated list of pep8 exclusions", - dest="pep8_ignore") + "--pep8-ignore", + nargs="*", + default=["E501"], + help="Space separated list of pep8 exclusions", + dest="pep8_ignore") parser.add_argument("-s", - "--shellcheck-ignore", - nargs="*", - help="Space separated list of shellcheck exclusions", - dest="shellcheck_ignore") + "--shellcheck-ignore", + nargs="*", + help="Space separated list of shellcheck exclusions", + dest="shellcheck_ignore") parser.add_argument("-g", - "--git-latest", - action="store_true", - default=False, - help="If set, the script will try to evaluate files in last git \ - commit instead of the whole repository", - dest="git_latest") + "--git-latest", + action="store_true", + default=False, + help="If set, the script will try to evaluate files in last git \ + commit instead of the whole repository", + dest="git_latest") parser.add_argument("-f", - "--file-path", - default="", - help="Path to the file that should be checked", - dest="file_path") + "--file-path", + default="", + help="Path to the file that should be checked", + dest="file_path") args = parser.parse_args() main(args) |