Results
This commit is contained in:
parent
60387953bc
commit
54a9d8c325
95
tools/AttachResults.py
Normal file
95
tools/AttachResults.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#! py -3
|
||||||
|
"""
|
||||||
|
Append output and error files to Java files
|
||||||
|
"""
|
||||||
|
TODO = """
|
||||||
|
- 1st and last 10 lines, with ... in between? {OutputFirstAndLast: 10 Lines}
|
||||||
|
|
||||||
|
- {NoOutput}
|
||||||
|
"""
|
||||||
|
from pathlib import Path
|
||||||
|
import pprint
|
||||||
|
import textwrap
|
||||||
|
import os, sys, re
|
||||||
|
from itertools import chain
|
||||||
|
from betools import CmdLine, visitDir, ruler, head
|
||||||
|
|
||||||
|
maxlinewidth = 60
|
||||||
|
examplePath = Path(r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples")
|
||||||
|
|
||||||
|
class JFile:
|
||||||
|
def __init__(self, javaFilePath):
|
||||||
|
with javaFilePath.open() as doc:
|
||||||
|
self.code = doc.read()
|
||||||
|
self.lines = self.code.splitlines()
|
||||||
|
def has_output(self):
|
||||||
|
return "} /* Output:" in self.code
|
||||||
|
def output_line(self):
|
||||||
|
for line in self.lines:
|
||||||
|
if "} /* Output:" in line:
|
||||||
|
return line
|
||||||
|
|
||||||
|
def newOutput(javaFilePath):
|
||||||
|
outfile = javaFilePath.with_name(javaFilePath.stem + "-output.txt")
|
||||||
|
errfile = javaFilePath.with_name(javaFilePath.stem + "-erroroutput.txt")
|
||||||
|
result =""
|
||||||
|
if outfile.exists():
|
||||||
|
with outfile.open() as f:
|
||||||
|
out = f.read().strip()
|
||||||
|
if out:
|
||||||
|
result += out + "\n"
|
||||||
|
if errfile.exists():
|
||||||
|
with errfile.open() as f:
|
||||||
|
err = f.read().strip()
|
||||||
|
if err:
|
||||||
|
result += "--[ Error Output ]--\n"
|
||||||
|
result += err
|
||||||
|
return textwrap.wrap(result, width=maxlinewidth)
|
||||||
|
|
||||||
|
|
||||||
|
def appendOutputFiles(javaFilePath):
|
||||||
|
jfile = JFile(javaFilePath)
|
||||||
|
output = newOutput(javaFilePath)
|
||||||
|
if not output:
|
||||||
|
return
|
||||||
|
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!".format(self.javaFilePath))
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
@CmdLine('t')
|
||||||
|
def outputTagTypes():
|
||||||
|
"""Show different output tag variations"""
|
||||||
|
types = set()
|
||||||
|
os.chdir(str(examplePath))
|
||||||
|
for jfp in Path(".").rglob("*.java"):
|
||||||
|
jf = JFile(jfp)
|
||||||
|
if jf.has_output():
|
||||||
|
types.add(jf.output_line())
|
||||||
|
pprint.pprint(types)
|
||||||
|
|
||||||
|
@CmdLine('a')
|
||||||
|
def attachFiles():
|
||||||
|
"""Attach standard and error output to all files"""
|
||||||
|
os.chdir(str(examplePath))
|
||||||
|
for jfp in Path(".").rglob("*.java"):
|
||||||
|
jf = JFile(jfp)
|
||||||
|
if jf.has_output():
|
||||||
|
head(jfp)
|
||||||
|
print("\t{}".format(jf.output_line()))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': CmdLine.run()
|
@ -424,5 +424,4 @@ def findAllCommentTags():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(__doc__)
|
|
||||||
CmdLine.run()
|
CmdLine.run()
|
||||||
|
@ -18,6 +18,7 @@ from collections import defaultdict
|
|||||||
from itertools import chain
|
from itertools import chain
|
||||||
from betools import CmdLine, visitDir, ruler, head
|
from betools import CmdLine, visitDir, ruler, head
|
||||||
|
|
||||||
|
maxlinewidth = 60
|
||||||
examplePath = Path(r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples")
|
examplePath = Path(r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples")
|
||||||
|
|
||||||
maindef = re.compile("public\s+static\s+void\s+main")
|
maindef = re.compile("public\s+static\s+void\s+main")
|
||||||
@ -275,8 +276,9 @@ class Result:
|
|||||||
with self.errFilePath.open() as f:
|
with self.errFilePath.open() as f:
|
||||||
err = f.read().strip()
|
err = f.read().strip()
|
||||||
if err:
|
if err:
|
||||||
|
result += "--[ Error Output ]--\n"
|
||||||
result += err
|
result += err
|
||||||
return result.rstrip()
|
return textwrap.wrap(result, width=maxlinewidth)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
result = "\n" + ruler(self.javaFilePath, "=") +"\n"
|
result = "\n" + ruler(self.javaFilePath, "=") +"\n"
|
||||||
@ -301,6 +303,8 @@ class Result:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def appendOutputFiles(self):
|
def appendOutputFiles(self):
|
||||||
|
if not self.new_output:
|
||||||
|
return
|
||||||
if not self.output_tags.has_output: # no /* Output: at all
|
if not self.output_tags.has_output: # no /* Output: at all
|
||||||
with self.javaFilePath.open() as jf:
|
with self.javaFilePath.open() as jf:
|
||||||
code = jf.read()
|
code = jf.read()
|
||||||
@ -478,7 +482,7 @@ def checkWidth():
|
|||||||
for n, line in enumerate(code.readlines()):
|
for n, line in enumerate(code.readlines()):
|
||||||
if "///:~" in line or "/* Output:" in line:
|
if "///:~" in line or "/* Output:" in line:
|
||||||
break
|
break
|
||||||
if len(line) > 60:
|
if len(line) > maxlinewidth:
|
||||||
if not displayed:
|
if not displayed:
|
||||||
#print(str(example).replace("\\", "/"))
|
#print(str(example).replace("\\", "/"))
|
||||||
displayed = True
|
displayed = True
|
||||||
|
2
tools/a.bat
Normal file
2
tools/a.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@echo off
|
||||||
|
python C:\Users\Bruce\Dropbox\__TIJ4-ebook\AttachResults.py %*
|
@ -44,8 +44,8 @@ cp(dest, gdrive)
|
|||||||
cp(dest, idrive)
|
cp(dest, idrive)
|
||||||
|
|
||||||
shortcut = Path(r"C:\Python34\Scripts")
|
shortcut = Path(r"C:\Python34\Scripts")
|
||||||
tools = ["Examples.py", "Validate.py", "backup.bat", "go.bat", "update_git.py",
|
tools = ["Examples.py", "Validate.py", "AttachResults.py", "backup.bat", "go.bat", "update_git.py",
|
||||||
shortcut / "v.bat", shortcut / "e.bat", shortcut / "g.bat", shortcut / "home.bat"]
|
shortcut / "a.bat", shortcut / "v.bat", shortcut / "e.bat", shortcut / "g.bat", shortcut / "home.bat"]
|
||||||
|
|
||||||
print("\nCopying tools to Github")
|
print("\nCopying tools to Github")
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user