organization

This commit is contained in:
Bruce Eckel 2015-05-13 16:14:46 -07:00
parent 6d5be38ccb
commit 22a862f420
4 changed files with 83 additions and 13 deletions

View File

@ -345,7 +345,5 @@ 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")
if __name__ == '__main__': CmdLine.run()

View File

@ -0,0 +1,8 @@
from pathlib import Path
for j in Path("ExtractedExamples").glob("**/*.java"):
print(str(j))
with j.open() as f:
code = f.read().strip()
with j.open('w') as w:
w.write(code)

View File

@ -3,6 +3,8 @@
Run all (possible) java files and capture output and errors
TODO: 1st and last 10 lines, with ... in between? {FirstAndLast: 10 Lines}
TODO: format __newOutput() for line width using textwrap
"""
from pathlib import Path
import pprint
@ -278,6 +280,25 @@ class Result:
return result
def appendOutputFiles(self):
if not self.output_tags.has_output: # no /* Output: at all
with self.javaFilePath.open() as jf:
code = jf.read()
lines = code.splitlines()
while lines[-1].strip() is "":
lines.pop()
assert lines[-1].rstrip() == "} ///:~"
lines[-1] = "} /* Output:"
lines.append(self.new_output)
lines.append("*///:~")
result = "\n".join(lines) + "\n"
with self.javaFilePath.open("w") as jf:
jf.write(result)
return result
else:
print("{} already has Output: tags:".format(self.javaFilePath))
print(self.output_tags)
sys.exit()
@CmdLine("d", "discover")
@ -328,6 +349,7 @@ def findExceptionsFromRun():
print(errfile.read())
head()
@CmdLine("a", "editall")
def editAllJavaFiles():
"""
@ -338,20 +360,22 @@ def editAllJavaFiles():
for java in Path(".").rglob("*.java"):
cmdfile.write("{} ".format(java))
@CmdLine("s", "single", 1)
@CmdLine("s", "single", "+")
def attachToSingleFile():
"""
Attach output to single file.
Attach output to selected file(s).
"""
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)
for jfp in sys.argv[2:]:
javafilepath = Path(jfp)
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.appendOutputFiles())

40
tools/backup.bat Normal file
View File

@ -0,0 +1,40 @@
@setlocal enabledelayedexpansion && py -3 -x "%~f0" %* & exit /b !ERRORLEVEL!
#start python code here
import zipfile
import datetime
import os, sys, shutil
from glob import glob
#import platform
#print(platform.python_version())
from pathlib import Path
destdirs = [ # Different paths for different machines:
r'''C:\Users\Bruce Eckel\Box Sync\TIJ4-ebook-Backups''',
r'''C:\Users\Bruce\Box Sync\TIJ4-ebook-Backups''',
]
for destdir in destdirs:
if os.path.exists(destdir):
break
assert(os.path.exists(destdir))
now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M")
zip_file_name = 'TIJDirectorsCut-' + now + '.zip'
dest = os.path.join(destdir, zip_file_name)
with zipfile.ZipFile(dest, 'w') as myzip:
# for f in glob("*.odt") + glob("*.docx") + glob("*.doc") + glob("*.txt") + glob("*.bat") + glob("*.py"):
for f in ["Examples.py", "Validate.py", "Notes.txt", "backup.bat", "backupall.bat"] + glob("*.docx"):
myzip.write(f)
# myzip.write("TIJDirectorsCut.docx")
# copy dest to:
# double_back = os.path.join(r'C:\Users\Bruce\IDrive-Sync\TIJ4-ebook-Backups', zip_file_name)
shutil.copy(dest, r'C:\Users\Bruce\Google Drive\TIJ4RefreshedBackups')
shutil.copy(dest, r'C:\Users\Bruce\IDrive-Sync\TIJ4-ebook-Backups')
shutil.copy("Examples.py", r'C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut\tools')
shutil.copy("Validate.py", r'C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut\tools')
# Touch this file to indicate most recent update time:
os.utime("backup.bat", None)