Add non-zero exit code on whitespace check failure

This commit is contained in:
Richard Berger
2020-06-16 07:06:37 -04:00
parent 61235308f1
commit 036b2bd82c

View File

@ -3,6 +3,7 @@
#
# Written by Richard Berger (Temple University)
import os
import sys
import glob
import re
import yaml
@ -76,6 +77,7 @@ def fix_file(path, check_result):
shutil.move(newfile, path)
def check_folder(directory, config, fix=False, verbose=False):
success = True
files = []
for base_path in config['include']:
@ -104,14 +106,19 @@ def check_folder(directory, config, fix=False, verbose=False):
if result['encoding'] == 'unknown':
print("[Error] Unknown text encoding @ {}".format(path))
has_resolvable_errors = False
success = False
elif result['encoding'] == 'ISO-8859-1':
print("[Error] Found ISO-8859-1 encoding instead of UTF-8 @ {}".format(path))
has_resolvable_errors = True
if has_resolvable_errors and fix:
print("Applying automatic fixes to file:", path)
fix_file(path, result)
if has_resolvable_errors:
if fix:
print("Applying automatic fixes to file:", path)
fix_file(path, result)
else:
success = False
return success
def main():
parser = argparse.ArgumentParser(description='Utility for detecting and fixing whitespace issues in LAMMPS')
@ -127,7 +134,8 @@ def main():
else:
config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader)
check_folder(args.DIRECTORY, config, args.fix, args.verbose)
if not check_folder(args.DIRECTORY, config, args.fix, args.verbose):
sys.exit(1)
if __name__ == "__main__":
main()