From e7ed20d307bcb56ddc8c6d767a8b9fe3cb48b0ca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 24 May 2021 15:38:41 -0400 Subject: [PATCH] hack to allow processing individual files. handle a few more substitutions --- tools/coding_standard/homepage.py | 33 ++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/tools/coding_standard/homepage.py b/tools/coding_standard/homepage.py index 66a92672c7..299729f15d 100644 --- a/tools/coding_standard/homepage.py +++ b/tools/coding_standard/homepage.py @@ -72,8 +72,10 @@ def fix_file(path, check_result): with open(path, 'r', encoding=check_result['encoding']) as src: for line in src: newline = line.replace("lammps.sandia.gov/doc/","docs.lammps.org/") + newline = newline.replace("http://lammps.sandia.gov/","https://www.lammps.org/") newline = newline.replace("http://lammps.sandia.gov,","https://www.lammps.org/") newline = newline.replace("lammps.sandia.gov","www.lammps.org") + newline = newline.replace("http://www.lammps.org","https://www.lammps.org") print(newline, end='', file=out) shutil.copymode(path, newfile) shutil.move(newfile, path) @@ -115,7 +117,7 @@ def main(): parser.add_argument('-c', '--config', metavar='CONFIG_FILE', help='location of a optional configuration file') parser.add_argument('-f', '--fix', action='store_true', help='automatically fix URLs') parser.add_argument('-v', '--verbose', action='store_true', help='verbose output') - parser.add_argument('DIRECTORY', help='directory that should be checked') + parser.add_argument('DIRECTORY', help='directory (or file) that should be checked') args = parser.parse_args() if args.config: @@ -124,8 +126,33 @@ def main(): else: config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader) - if not check_folder(args.DIRECTORY, config, args.fix, args.verbose): - sys.exit(1) + if os.path.isdir(args.DIRECTORY): + if not check_folder(args.DIRECTORY, config, args.fix, args.verbose): + sys.exit(1) + else: + success = True + path = os.path.normpath(args.DIRECTORY) + + if args.verbose: + print("Checking file:", path) + + result = check_file(path) + + has_resolvable_errors = False + + for lineno in result['homepage_errors']: + print("[Error] Incorrect LAMMPS homepage @ {}:{}".format(path, lineno)) + has_resolvable_errors = True + + if has_resolvable_errors: + if args.fix: + print("Applying automatic fixes to file:", path) + fix_file(path, result) + else: + success = False + + if not success: + sys.exit(1) if __name__ == "__main__": main()