forked from lijiext/lammps
hack to allow processing individual files. handle a few more substitutions
This commit is contained in:
parent
63ecb77303
commit
e7ed20d307
|
@ -72,8 +72,10 @@ def fix_file(path, check_result):
|
||||||
with open(path, 'r', encoding=check_result['encoding']) as src:
|
with open(path, 'r', encoding=check_result['encoding']) as src:
|
||||||
for line in src:
|
for line in src:
|
||||||
newline = line.replace("lammps.sandia.gov/doc/","docs.lammps.org/")
|
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("http://lammps.sandia.gov,","https://www.lammps.org/")
|
||||||
newline = newline.replace("lammps.sandia.gov","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)
|
print(newline, end='', file=out)
|
||||||
shutil.copymode(path, newfile)
|
shutil.copymode(path, newfile)
|
||||||
shutil.move(newfile, path)
|
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('-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('-f', '--fix', action='store_true', help='automatically fix URLs')
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.config:
|
if args.config:
|
||||||
|
@ -124,8 +126,33 @@ def main():
|
||||||
else:
|
else:
|
||||||
config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader)
|
config = yaml.load(DEFAULT_CONFIG, Loader=yaml.FullLoader)
|
||||||
|
|
||||||
if not check_folder(args.DIRECTORY, config, args.fix, args.verbose):
|
if os.path.isdir(args.DIRECTORY):
|
||||||
sys.exit(1)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue