Skip to content

Commit 9286ff8

Browse files
committed
Extractor and viewer working
1 parent 534743f commit 9286ff8

2 files changed

Lines changed: 37 additions & 63 deletions

File tree

tools/AttachResults.py

Lines changed: 35 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
class JavaMain:
33-
33+
max_output_length = 32 # lines beyond which we flag this
3434
maindef = re.compile("public\s+static\s+void\s+main")
3535
ellipses = ["[...]".center(maxlinewidth, '_')]
3636

@@ -40,7 +40,7 @@ class JFile:
4040
def with_main(javaFilePath):
4141
with javaFilePath.open() as doc:
4242
code = doc.read()
43-
if JavaMain.maindef.search(code):
43+
if JavaMain.maindef.search(code) or "{Exec:" in code:
4444
return JavaMain.JFile(javaFilePath, code)
4545
return None
4646
def __init__(self, javaFilePath, code):
@@ -62,6 +62,8 @@ def create(javaFilePath):
6262
return None
6363
if "/* Output: (None) */" in j_file.code:
6464
return None
65+
if "/* Output: (Execute to see)" in j_file.code:
66+
return None
6567
outfile = javaFilePath.with_name(javaFilePath.stem + "-output.txt")
6668
errfile = javaFilePath.with_name(javaFilePath.stem + "-erroroutput.txt")
6769
if outfile.exists() or errfile.exists():
@@ -75,6 +77,7 @@ def __init__(self, javaFilePath, j_file, outfile, errfile):
7577
self.errfile = errfile
7678
self.first_and_last = None
7779
self.first_lines = None
80+
self.long_output = False
7881

7982
ol = self.j_file.output_line
8083
if ol:
@@ -103,6 +106,9 @@ def __init__(self, javaFilePath, j_file, outfile, errfile):
103106
result += err
104107
self.result = JavaMain.wrapOutput(result) + "\n"
105108

109+
if len(self.result.splitlines()) > JavaMain.max_output_length:
110+
self.long_output = True
111+
106112
for line in self.j_file.lines:
107113
if line.startswith("} ///:~"):
108114
self.j_file.newcode += "} /* Output:\n"
@@ -127,6 +133,9 @@ def wrapOutput(output):
127133
result += textwrap.wrap(line.rstrip(), width=maxlinewidth)
128134
return "\n".join(result)
129135

136+
def write_modified_file(self):
137+
with self.j_file.javaFilePath.open('w') as modified:
138+
modified.write(self.j_file.newcode)
130139

131140

132141
@CmdLine('o')
@@ -169,8 +178,6 @@ def extractResults():
169178
if outline:
170179
results.write(outline + "\n")
171180
results.write(j_main.result)
172-
# else:
173-
# results.write("[ No output for {} ]\n".format(jfp))
174181
os.system("subl AttachedResults.txt")
175182

176183
@CmdLine('n')
@@ -201,73 +208,43 @@ def noOutputFixup():
201208
# test.write(ruler(jfp))
202209
# test.write(newcode)
203210

211+
@CmdLine('v')
212+
def viewAttachedFiles():
213+
"""View all files containing output in this directory and below"""
214+
for java in Path(".").rglob("*.java"):
215+
with java.open() as codefile:
216+
code = codefile.read()
217+
if "/* Output:" in code:
218+
if "/* Output: (None)" in code:
219+
continue
220+
if "/* Output: (Execute to see)" in code:
221+
continue
222+
for n, line in enumerate(code.splitlines()):
223+
if "/* Output:" in line:
224+
os.system("subl {}:{}".format(java, n))
225+
continue
226+
204227

205228
@CmdLine('a')
206229
def attachFiles():
207230
"""Attach standard and error output to all files"""
208231
os.chdir(str(examplePath))
209-
test = open("test.txt", 'w')
232+
test = open("AllFilesWithOutput.txt", 'w')
233+
longOutput = open("LongOutput.txt", 'w')
210234
for jfp in Path(".").rglob("*.java"):
211235
if "gui" in jfp.parts or "swt" in jfp.parts:
212236
continue
213237
j_main = JavaMain.create(jfp)
214238
if j_main is None:
215239
continue
240+
j_main.write_modified_file()
216241
test.write(ruler())
217242
test.write(j_main.new_code())
218-
os.system("subl test.txt")
243+
if j_main.long_output:
244+
longOutput.write(ruler())
245+
longOutput.write(j_main.new_code())
246+
os.system("subl AllFilesWithOutput.txt")
247+
os.system("subl LongOutput.txt")
219248

220249
if __name__ == '__main__': CmdLine.run()
221250

222-
223-
224-
# def newOutput(javaFilePath):
225-
# outfile = javaFilePath.with_name(javaFilePath.stem + "-output.txt")
226-
# errfile = javaFilePath.with_name(javaFilePath.stem + "-erroroutput.txt")
227-
# result =""
228-
# if outfile.exists():
229-
# with outfile.open() as f:
230-
# out = f.read().strip()
231-
# if out:
232-
# result += out + "\n"
233-
# if errfile.exists():
234-
# with errfile.open() as f:
235-
# err = f.read().strip()
236-
# if err:
237-
# result += "___[ Error Output ]___\n"
238-
# result += err
239-
# result = wrapOutput(result)
240-
# if result:
241-
# return result + "\n"
242-
# return None
243-
244-
245-
246-
247-
248-
249-
250-
# def appendOutputFiles(javaFilePath):
251-
# jfile = JFile.with_main(javaFilePath)
252-
# if jfile is None:
253-
# return
254-
# output = newOutput(javaFilePath)
255-
# if not output:
256-
# return
257-
# if not self.output_tags.has_output: # no /* Output: at all
258-
# with self.javaFilePath.open() as jf:
259-
# code = jf.read()
260-
# lines = code.splitlines()
261-
# while lines[-1].strip() is "":
262-
# lines.pop()
263-
# assert lines[-1].rstrip() == "} ///:~"
264-
# lines[-1] = "} /* Output:"
265-
# lines.append(self.new_output)
266-
# lines.append("*///:~")
267-
# result = "\n".join(lines) + "\n"
268-
# with self.javaFilePath.open("w") as jf:
269-
# jf.write(result)
270-
# return result
271-
# else:
272-
# print("{} already has Output!".format(self.javaFilePath))
273-
# sys.exit()

tools/Validate.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
###############################################################################
2929
# Powershell: https://gist.github.com/diyan/2850866
3030
# http://marxsoftware.blogspot.com/2008/02/windows-powershell-and-java.html
31-
allflags = dict()
3231

3332
class Flags:
3433
discard = ["{Requires:"]
@@ -49,11 +48,8 @@ def __init__(self, lines):
4948
fl = fl.strip()
5049
arg = arg.strip()
5150
self.flags[fl] = arg
52-
allflags[fl] = arg
5351
else:
5452
self.flags[flag] = None # Make an entry, but no arg
55-
allflags[flag] = None
56-
# allflags.add(flag)
5753

5854
def __contains__(self, elt):
5955
return elt in self.flags
@@ -445,6 +441,8 @@ def editAllJavaFiles():
445441
"""
446442
for java in Path(".").rglob("*.java"):
447443
os.system("ed {}".format(java))
444+
# print("ed %s" % java)
445+
# print(java)
448446

449447

450448
@CmdLine("s", num_args="+")
@@ -524,4 +522,3 @@ def clean_files():
524522

525523
if __name__ == '__main__':
526524
CmdLine.run()
527-
pprint.pprint(allflags)

0 commit comments

Comments
 (0)