From 6d5be38ccbcbf665a343bebc80d676ce9534783f Mon Sep 17 00:00:00 2001 From: Bruce Eckel <BruceTEckel@gmail.com> Date: Wed, 13 May 2015 10:53:49 -0700 Subject: [PATCH] Moved python support files to tools --- Examples.py => tools/Examples.py | 4 +- tools/Macros.vba | 158 +++++++++++++++++- .../OutputGenerator.py | 0 OutputVerifier.py => tools/OutputVerifier.py | 0 Validate.py => tools/Validate.py | 26 +++ tools/v.bat | 1 + 6 files changed, 186 insertions(+), 3 deletions(-) rename Examples.py => tools/Examples.py (99%) rename OutputGenerator.py => tools/OutputGenerator.py (100%) rename OutputVerifier.py => tools/OutputVerifier.py (100%) rename Validate.py => tools/Validate.py (93%) create mode 100644 tools/v.bat diff --git a/Examples.py b/tools/Examples.py similarity index 99% rename from Examples.py rename to tools/Examples.py index a5e9bf20..6fac3dd8 100644 --- a/Examples.py +++ b/tools/Examples.py @@ -345,7 +345,7 @@ def extractAndCreateBuildFiles(): with open("run.bat", 'w') as run: run.write(r"python ..\Validate.py -p" + "\n") run.write(r"powershell .\runall.ps1" + "\n") - with open("v.bat", 'w') as run: - run.write(r"python ..\Validate.py %*" + "\n") + # with open("v.bat", 'w') as run: + # run.write(r"python ..\Validate.py %*" + "\n") if __name__ == '__main__': CmdLine.run() diff --git a/tools/Macros.vba b/tools/Macros.vba index 2f6ef4e6..581d50fb 100644 --- a/tools/Macros.vba +++ b/tools/Macros.vba @@ -69,9 +69,10 @@ Sub UpdateCode() Selection.Find.Execute Call updateFile Selection.MoveRight wdCharacter, 1 + Selection.Find.ClearFormatting End Sub -Sub FreshenAllCode() +Sub FreshenAllCode_StripTrailingNewlinesFirst() ' Update the entire book's code listings 'Application.ScreenUpdating = False @@ -112,6 +113,161 @@ Sub SaveAsText() SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _ , LineEnding:=wdCRLF, CompatibilityMode:=0 + Application.Quit End Sub +Private Sub OLDUpdateAllCode() +' Update the entire book's code listings +' Macro created 7/7/2002 by Mark Welsh +' + Dim startLoc As Long, endLoc As Long + Dim oldCode As String, i As Integer + Dim fname As String, ln As String + Dim newCode As String + + 'Application.ScreenUpdating = False + Application.EnableCancelKey = xlInterrupt + + Do + ' Find the starting location + Selection.Find.ClearFormatting + startLoc = Selection.Start + With Selection.Find + .Text = "//: " + .Forward = True + .Wrap = wdFindContinue + .Format = False + .MatchCase = False + .MatchWholeWord = False + .MatchWildcards = False + .MatchSoundsLike = False + .MatchAllWordForms = False + End With + Selection.Find.Execute + + startLoc = Selection.Start + ' No new code found, so quit + If startLoc < endLoc Then + Exit Sub + End If + + ' Find the end location + Selection.Find.ClearFormatting + With Selection.Find + .Text = "///:~" + .Forward = True + .Wrap = wdFindContinue + .Format = False + .MatchCase = False + .MatchWholeWord = False + .MatchWildcards = False + .MatchSoundsLike = False + .MatchAllWordForms = False + End With + Selection.Find.Execute + endLoc = Selection.End + + Selection.MoveRight wdCharacter, 1 + Selection.MoveLeft wdCharacter, endLoc - startLoc, wdExtend + + ' Get the file name + oldCode = Selection + i = InStr(5, oldCode, ".java") + fname = Mid(oldCode, 5, i) + fname = Replace(fname, "/", "\") + + If Len(fname) = 0 Then + GoTo skip + End If + + ' Does the file exist? + If Not fileExists(fname) Then + If MsgBox(fname & " could not be found! Continue replace?", vbYesNo + vbExclamation, "UpdateCode") = vbNo Then + Exit Sub + End If + GoTo skip + End If + + 'Open the file + Open basedir & fname For Input As #1 + While Not EOF(1) + Line Input #1, ln + newCode = newCode & ln & vbCrLf + Wend + Close #1 + + 'Add the new code and change the style + Selection = Left(newCode, Len(newCode) - 2) + Selection.Style = ActiveDocument.Styles("Code") + 'Selection.MoveRight wdCharacter, 1 + 'Selection.HomeKey wdLine, wdExtend + 'Selection.Style = ActiveDocument.Styles("CodeInline") + 'Selection.MoveDown wdLine, 1 + 'Selection.Style = ActiveDocument.Styles("CodeInlineTrailer") +skip: + Selection.MoveRight wdCharacter, 2 + newCode = "" + Loop + Application.ScreenUpdating = True +End Sub + +Private Sub oldCodeBody() + Selection.MoveRight wdCharacter, 1 + Selection.MoveLeft wdCharacter, endLoc - startLoc, wdExtend + + ' Get the file name + oldCode = Selection + i = InStr(5, oldCode, ".java") + fname = Mid(oldCode, 5, i) + fname = Replace(fname, "/", "\") + + If Len(fname) = 0 Then + GoTo skip + End If + + ' Does the file exist? + If Not fileExists(fname) Then + If MsgBox(fname & " could not be found! Continue replace?", vbYesNo + vbExclamation, "UpdateCode") = vbNo Then + Exit Sub + End If + GoTo skip + End If + + 'Open the file + Open basedir & fname For Input As #1 + While Not EOF(1) + Line Input #1, ln + newCode = newCode & ln & vbCrLf + Wend + Close #1 + + 'Add the new code and change the style + Selection = Left(newCode, Len(newCode) - 2) + Selection.Style = ActiveDocument.Styles("Code") +skip: + Selection.MoveRight wdCharacter, 2 + newCode = "" + +End Sub +Sub NextCodeItemOfInterest() +' +' NextCodeItemOfInterest Macro +' +' + Selection.Find.ClearFormatting + Selection.Find.Style = ActiveDocument.Styles("Code") + With Selection.Find + .Text = "->" + .Replacement.Text = "" + .Forward = True + .Wrap = wdFindContinue + .Format = True + .MatchCase = False + .MatchWholeWord = False + .MatchWildcards = False + .MatchSoundsLike = False + .MatchAllWordForms = False + End With + Selection.Find.Execute +End Sub diff --git a/OutputGenerator.py b/tools/OutputGenerator.py similarity index 100% rename from OutputGenerator.py rename to tools/OutputGenerator.py diff --git a/OutputVerifier.py b/tools/OutputVerifier.py similarity index 100% rename from OutputVerifier.py rename to tools/OutputVerifier.py diff --git a/Validate.py b/tools/Validate.py similarity index 93% rename from Validate.py rename to tools/Validate.py index 57718dec..42f27956 100644 --- a/Validate.py +++ b/tools/Validate.py @@ -328,5 +328,31 @@ def findExceptionsFromRun(): print(errfile.read()) head() +@CmdLine("a", "editall") +def editAllJavaFiles(): + """ + Edit all Java files in this directory and beneath + """ + with Path("editall.bat").open('w') as cmdfile: + cmdfile.write("subl ") + for java in Path(".").rglob("*.java"): + cmdfile.write("{} ".format(java)) + +@CmdLine("s", "single", 1) +def attachToSingleFile(): + """ + Attach output to single file. + """ + javafilepath = Path(sys.argv[2]) + if not javafilepath.exists(): + print("Error: cannot find {}".format(javafilepath)) + sys.exit(1) + result = Result.create(javafilepath) + if not result: + print("Error: no output or error files for {}".format(javafilepath)) + sys.exit(1) + print(result) + + if __name__ == '__main__': CmdLine.run() diff --git a/tools/v.bat b/tools/v.bat new file mode 100644 index 00000000..f610c358 --- /dev/null +++ b/tools/v.bat @@ -0,0 +1 @@ +python C:\Users\Bruce\Dropbox\__TIJ4-ebook\Validate.py %*