Moved python support files to tools

This commit is contained in:
Bruce Eckel 2015-05-13 10:53:49 -07:00
parent 820fa7145a
commit 6d5be38ccb
6 changed files with 186 additions and 3 deletions

View File

@ -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()

View File

@ -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

View File

@ -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()

1
tools/v.bat Normal file
View File

@ -0,0 +1 @@
python C:\Users\Bruce\Dropbox\__TIJ4-ebook\Validate.py %*