11#! py -3
22"""
3- Run all (possible) java files and capture output and errors
3+ Run all (possible) java files and capture output and errors. Integrate into /* Output:
44"""
55TODO = """
6+ - strip_last_blank_line -> cleanfiles (also strip trailing spaces on each line, remove copyright notice)
7+
68- 1st and last 10 lines, with ... in between? {OutputFirstAndLast: 10 Lines}
79
810- {NoOutput}
1517import os , sys , re
1618import difflib
1719from collections import defaultdict
20+ from itertools import chain
1821from betools import CmdLine , visitDir , ruler , head
1922
2023examplePath = Path (r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples" )
@@ -385,7 +388,7 @@ def showProblemErrors():
385388 continue
386389 print (err )
387390
388- @CmdLine ('w' )
391+ # @CmdLine('w')
389392def findAndEditAllCompileTimeError ():
390393 "Find all files tagged with {CompileTimeError} and edit them"
391394 os .chdir (str (examplePath ))
@@ -419,10 +422,8 @@ def editAllJavaFiles():
419422 """
420423 Edit all Java files in this directory and beneath
421424 """
422- with Path ("editall.bat" ).open ('w' ) as cmdfile :
423- cmdfile .write ("subl " )
424- for java in Path ("." ).rglob ("*.java" ):
425- cmdfile .write ("{} " .format (java ))
425+ for java in Path ("." ).rglob ("*.java" ):
426+ os .system ("ed {}" .format (java ))
426427
427428
428429@CmdLine ("s" , num_args = "+" )
@@ -454,7 +455,6 @@ def findAllMains():
454455 head (jf )
455456 print (m )
456457
457- @CmdLine ("c" )
458458def createChecklist ():
459459 """
460460 Make checklist of chapters and appendices
@@ -470,5 +470,33 @@ def createChecklist():
470470 text = " " .join (h1 .text .split ())
471471 checklist .write (codecs .encode (text + "\n " ))
472472
473+ @CmdLine ('w' )
474+ def checkWidth ():
475+ "Check line width on code examples"
476+ os .chdir (str (examplePath ))
477+ for example in chain (Path ("." ).rglob ("*.java" ), Path ("." ).rglob ("*.cpp" ), Path ("." ).rglob ("*.py" )):
478+ displayed = False
479+ with example .open () as code :
480+ for n , line in enumerate (code .readlines ()):
481+ if "///:~" in line or "/* Output:" in line :
482+ break
483+ if len (line ) > 60 :
484+ if not displayed :
485+ #print(str(example).replace("\\", "/"))
486+ displayed = True
487+ os .system ("ed {}:{}" .format (str (example ), n + 1 ))
488+ # print("{} : {}".format(n, len(line)))
489+
490+ @CmdLine ("c" )
491+ def clean_files ():
492+ "Strip trainling blank lines in all Java files -- prep for reintigration into book"
493+ os .chdir (str (examplePath ))
494+ for j in Path ("." ).rglob ("*.java" ):
495+ print (str (j ), end = " " )
496+ with j .open () as f :
497+ code = f .read ().strip ()
498+ with j .open ('w' ) as w :
499+ w .write (code )
500+
473501
474502if __name__ == '__main__' : CmdLine .run ()
0 commit comments