2015-12-02 09:20:27 -08:00
|
|
|
# Requires Python 3.5 or greater
|
2015-12-15 11:47:04 -08:00
|
|
|
# (c)2016 MindView LLC: see Copyright.txt
|
2015-12-02 09:20:27 -08:00
|
|
|
# We make no guarantees that this code is fit for any purpose.
|
|
|
|
# Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
|
|
"""
|
|
|
|
ToDo:
|
|
|
|
- Validate errors
|
|
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from output_duet import Duet, Valid
|
|
|
|
import os
|
2015-12-15 11:47:04 -08:00
|
|
|
import collections
|
|
|
|
import pprint
|
2015-12-16 13:50:01 -08:00
|
|
|
import itertools
|
2015-12-02 09:20:27 -08:00
|
|
|
|
2015-12-15 11:47:04 -08:00
|
|
|
def trace(*str): pass
|
|
|
|
# trace = print
|
2015-12-02 09:20:27 -08:00
|
|
|
|
2015-12-16 13:50:01 -08:00
|
|
|
def clean():
|
|
|
|
for p in (Path(f) for f in [
|
|
|
|
"update_output.bat",
|
|
|
|
"edit_errors.bat",
|
|
|
|
"strategies.txt",
|
|
|
|
"validate_successes.txt",
|
|
|
|
"validate_failures.txt",
|
2016-01-25 18:05:55 -08:00
|
|
|
]):
|
2015-12-16 13:50:01 -08:00
|
|
|
if p.exists():
|
|
|
|
p.unlink()
|
|
|
|
|
|
|
|
|
2015-12-02 09:20:27 -08:00
|
|
|
if __name__ == '__main__':
|
2015-12-16 13:50:01 -08:00
|
|
|
clean()
|
2015-12-15 11:47:04 -08:00
|
|
|
jfiles = sorted([java.name for java in Path(".").glob("**/*.java")])
|
|
|
|
duplicates = sorted([x for x, y in collections.Counter(jfiles).items() if y > 1])
|
|
|
|
if duplicates:
|
|
|
|
print("Duplicates:")
|
|
|
|
pprint.pprint(duplicates)
|
|
|
|
|
2015-12-02 09:20:27 -08:00
|
|
|
count = 0
|
2015-12-16 13:50:01 -08:00
|
|
|
for output in itertools.chain(Path(".").glob("**/*.out"), Path(".").glob("**/*.err")):
|
2015-12-02 09:20:27 -08:00
|
|
|
duet = Duet(output)
|
2015-12-16 13:50:01 -08:00
|
|
|
# if duet.error:
|
|
|
|
# os.system("subl {}".format(duet.java_path))
|
2015-12-15 11:47:04 -08:00
|
|
|
trace("duet.ignore:", duet.ignore, duet.java_path )
|
|
|
|
if duet.ignore:
|
|
|
|
continue
|
2015-12-02 09:20:27 -08:00
|
|
|
v = duet.validate()
|
|
|
|
if v is Valid.fail:
|
|
|
|
with Path("validate_failures.txt").open('a') as vf:
|
|
|
|
print(duet, file = vf)
|
|
|
|
with Path("strategies.txt").open('a') as st:
|
2015-12-15 11:47:04 -08:00
|
|
|
print(' "' + duet.java_path.name + '" : IgnoreSortedLines(),', file = st)
|
2015-12-02 09:20:27 -08:00
|
|
|
with Path("update_output.bat").open('a') as uo:
|
2015-12-16 13:50:01 -08:00
|
|
|
print('call no ' + str(duet.out_path.with_suffix(".new")), file = uo)
|
|
|
|
with Path("edit_errors.bat").open('a') as eo:
|
|
|
|
print('subl ' + str(duet.java_path), file = eo)
|
|
|
|
if duet.error:
|
|
|
|
duet.out_path.with_suffix(".new").write_text(duet.generated_un_adjusted)
|
|
|
|
os.system('subl ' + str(duet.out_path.with_suffix(".new")))
|
|
|
|
else:
|
|
|
|
with Path("validate_successes.txt").open('a') as vs:
|
|
|
|
print("{:<20}".format(v) + "{}".format(duet.java_path), file = vs)
|
2015-12-02 09:20:27 -08:00
|
|
|
count += 1
|
2015-12-15 11:47:04 -08:00
|
|
|
print("\n" + " Verified files = {} ".format(count).center(60, "*"))
|
2015-12-16 13:50:01 -08:00
|
|
|
|
2015-12-15 11:47:04 -08:00
|
|
|
if Path("validate_failures.txt").exists():
|
2015-12-16 13:50:01 -08:00
|
|
|
os.system("subl "
|
|
|
|
"update_output.bat "
|
|
|
|
"edit_errors.bat "
|
|
|
|
"strategies.txt "
|
|
|
|
"validate_successes.txt "
|
|
|
|
"validate_failures.txt")
|
2015-12-15 11:47:04 -08:00
|
|
|
else:
|
|
|
|
print("\n" + " No Output Errors ".center(60, "="))
|