Skip to content

Commit d24a985

Browse files
committed
improvements
1 parent ded2d52 commit d24a985

7 files changed

Lines changed: 42 additions & 17 deletions

File tree

tools/StripLastBlankLine.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tools/Validate.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
"""
55
TODO = """
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}
@@ -15,6 +17,7 @@
1517
import os, sys, re
1618
import difflib
1719
from collections import defaultdict
20+
from itertools import chain
1821
from betools import CmdLine, visitDir, ruler, head
1922

2023
examplePath = 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')
389392
def 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")
458458
def 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

474502
if __name__ == '__main__': CmdLine.run()

tools/backup.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ cp(dest, gdrive)
4444
cp(dest, idrive)
4545

4646
shortcut = Path(r"C:\Python34\Scripts")
47-
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "StripLastBlankLine.py", "update_git.py",
48-
shortcut / "v.bat", shortcut / "e.bat", shortcut / "g.bat"]
47+
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "update_git.py",
48+
shortcut / "v.bat", shortcut / "e.bat", shortcut / "g.bat", shortcut / "home.bat"]
4949

5050
print("\nCopying tools to Github")
5151
for tool in tools:

tools/e.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
@echo off
12
python C:\Users\Bruce\Dropbox\__TIJ4-ebook\Examples.py %*

tools/g.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
@echo off
12
python C:\Users\Bruce\Dropbox\__TIJ4-ebook\update_git.py %*

tools/home.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
cd C:\Users\Bruce\Dropbox\__TIJ4-ebook

tools/v.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
@echo off
12
python C:\Users\Bruce\Dropbox\__TIJ4-ebook\Validate.py %*

0 commit comments

Comments
 (0)