Skip to content

Commit d506345

Browse files
committed
fix
1 parent c157c0e commit d506345

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

tools/Examples.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
maindef = re.compile("public\s+static\s+void\s+main")
1616

17+
# Leave this alone, relative path necessary:
1718
destination = Path('.') / "ExtractedExamples"
1819
sourceText = Path('.') / "TIJDirectorsCut.txt"
1920
github = Path(r'C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut')
@@ -50,7 +51,7 @@ def extractExamples():
5051
if "//: as a special marker" in title:
5152
continue
5253
title = title.split()[1]
53-
print(title)
54+
# print(title)
5455
target = destination / Path(title)
5556
if not target.parent.exists():
5657
target.parent.mkdir(parents=True)
@@ -166,7 +167,7 @@ def __init__(self, codeFile):
166167
self.exclude = self.codeFile.name + ".java"
167168
if self.codeFile.subdirs:
168169
self.exclude = '/'.join(self.codeFile.subdirs) + '/' + self.exclude
169-
print(self.exclude)
170+
print("self.exclude {}".format(self.exclude))
170171

171172
self.continue_on_error = None
172173
if "{ThrowsException}" in self.codeFile.code:
@@ -310,12 +311,34 @@ def makeBuildFile(self):
310311
buildFile = startBuild % (self.dir.name, " ".join(self.excludes))
311312
for cf in self.code_files:
312313
if any([cf.name + ".java" in f for f in self.excludes]) or cf.options.validatebyhand:
314+
print("Excluding {}".format(cf))
313315
continue
314316
buildFile += cf.run_command()
315317
buildFile += endBuild
316318
with (self.dir / "build.xml").open("w") as buildxml:
317319
buildxml.write(buildFile)
318320

321+
exec = """\
322+
<echo message="{}"/>
323+
<exec executable="cmd" dir=".">
324+
<arg line="/c {}" />
325+
</exec>
326+
"""
327+
328+
def addBatchCommand(target_dir, batch_file_name):
329+
with (destination/target_dir/"build.xml").open() as build:
330+
lines = build.readlines()
331+
for n, line in enumerate(lines):
332+
if "</target>" in line:
333+
lines.insert(n, exec.format(batch_file_name, batch_file_name))
334+
break
335+
with (destination/target_dir/"build.xml").open("w") as build:
336+
build.writelines(lines)
337+
338+
def addBatchFile(target_dir, batch_file_name, batch_file_text):
339+
with (destination/target_dir/batch_file_name).open('w') as ss:
340+
ss.write(batch_file_text)
341+
addBatchCommand(target_dir, batch_file_name)
319342

320343

321344
@CmdLine("m")
@@ -325,6 +348,28 @@ def createAntFiles():
325348
for chapter in chapters:
326349
chapter.checkPackages()
327350
chapter.makeBuildFile()
351+
# with (destination/"network"/"SimpleServer.bat").open('w') as ss:
352+
# ss.write("start java SimpleServer\n")
353+
# ss.write("java SimpleClient\n")
354+
# addBatchCommand("network", "SimpleServer.bat")
355+
addBatchFile("network", "SimpleServer.bat",
356+
"""\
357+
start java SimpleServer
358+
java SimpleClient
359+
""")
360+
addBatchFile("network", "ChatterServer.bat",
361+
"""\
362+
start java ChatterServer
363+
timeout /t 1
364+
java ChatterClient
365+
""")
366+
addBatchFile("network", "MultiSimpleServer.bat",
367+
"""\
368+
start java MultiSimpleServer
369+
timeout /t 1
370+
java MultiSimpleClient
371+
""")
372+
328373

329374

330375
@CmdLine("f")
@@ -354,6 +399,7 @@ def extractAndCreateBuildFiles():
354399
run.write(r"powershell .\runall.ps1" + "\n")
355400
run.write(r"python ..\Validate.py -e" + "\n")
356401

402+
357403
@CmdLine('g')
358404
def generateAntClean():
359405
"Generate directives for Ant-Clean.xml"

0 commit comments

Comments
 (0)