1818destination = Path ('.' ) / "ExtractedExamples"
1919sourceText = Path ('.' ) / "TIJDirectorsCut.txt"
2020github = Path (r'C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut' )
21+ examples = Path (r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples" )
2122
2223startBuild = """\
2324 <?xml version="1.0" ?>
3839"""
3940
4041def extractExamples ():
42+ print ("Extracting examples ..." )
4143 if not destination .exists ():
4244 destination .mkdir ()
4345 if not sourceText .exists ():
@@ -65,7 +67,7 @@ def extractExamples():
6567@CmdLine ("x" )
6668def clean ():
6769 "Remove ExtractedExamples directory"
68- print ("clean " )
70+ print ("Cleaning ... " )
6971 if destination .exists ():
7072 shutil .rmtree (str (destination ))
7173
@@ -129,16 +131,29 @@ def destDirs(pattern="**"):
129131 return {str (file )[leader :] for file in destination .glob (pattern )}
130132
131133
134+
132135@CmdLine ("a" )
133136def copySupplementalFilesFromGithub ():
134- "Copy ant build files from Github repository to extracted examples"
135- shutil .copy (str (github / "build.xml" ), str (destination ))
136- shutil .copy (str (github / "Ant-Common.xml" ), str (destination ))
137- shutil .copy (str (github / "Ant-Clean.xml" ), str (destination ))
138- for face in (github / "gui" ).glob ("*.gif" ):
139- shutil .copy (str (face ), str (destination / "gui" ))
140- # for verifier in ["OutputGenerator.py", "OutputVerifier.py"]:
141- # shutil.copy(str(github/verifier), str(destination))
137+ "Copy supplemental files from Github repository to extracted examples"
138+ print ("Copying supplemental files from Github ..." )
139+ def _copy (dir , name_or_pattern , trace = False ):
140+ source = (github / dir ).glob (name_or_pattern )
141+ dest_dir = examples / dir
142+ assert dest_dir .is_dir ()
143+ for f in source :
144+ if trace :
145+ print ("source: {}" .format (f ))
146+ print ("dest: {}" .format (dest_dir ))
147+ shutil .copy (str (f ), str (dest_dir ))
148+
149+ _copy ("." , "build.xml" )
150+ _copy ("." , "Ant-*.xml" )
151+ _copy ("gui" , "*.gif" )
152+ _copy ("network" , "*.bat" )
153+ _copy ("network" , "build.xml" )
154+ _copy ("remote" , "*.bat" )
155+ _copy ("remote" , "build.xml" )
156+
142157 patterns = destination / "patterns"
143158 trash = patterns / "recycleap" / "Trash.dat"
144159 shutil .copy (str (trash ), str (patterns / "recycleb" ))
@@ -167,7 +182,6 @@ def __init__(self, codeFile):
167182 self .exclude = self .codeFile .name + ".java"
168183 if self .codeFile .subdirs :
169184 self .exclude = '/' .join (self .codeFile .subdirs ) + '/' + self .exclude
170- print ("self.exclude {}" .format (self .exclude ))
171185
172186 self .continue_on_error = None
173187 if "{ThrowsException}" in self .codeFile .code :
@@ -311,7 +325,7 @@ def makeBuildFile(self):
311325 buildFile = startBuild % (self .dir .name , " " .join (self .excludes ))
312326 for cf in self .code_files :
313327 if any ([cf .name + ".java" in f for f in self .excludes ]) or cf .options .validatebyhand :
314- print ("Excluding {}" .format (cf ))
328+ # print("Excluding {}".format(cf))
315329 continue
316330 buildFile += cf .run_command ()
317331 buildFile += endBuild
@@ -325,51 +339,30 @@ def makeBuildFile(self):
325339 </exec>
326340"""
327341
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 )
342+ # def addBatchCommand(target_dir, batch_file_name):
343+ # with (destination/target_dir/"build.xml").open() as build:
344+ # lines = build.readlines()
345+ # for n, line in enumerate(lines):
346+ # if "</target>" in line:
347+ # lines.insert(n, exec.format(batch_file_name, batch_file_name))
348+ # break
349+ # with (destination/target_dir/"build.xml").open("w") as build:
350+ # build.writelines(lines)
337351
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 )
352+ # def addBatchFile(target_dir, batch_file_name, batch_file_text):
353+ # with (destination/target_dir/batch_file_name).open('w') as ss:
354+ # ss.write(batch_file_text)
355+ # addBatchCommand(target_dir, batch_file_name)
342356
343357
344358@CmdLine ("m" )
345359def createAntFiles ():
346360 "Make ant files that don't exist"
361+ print ("Creating Ant Files ..." )
347362 chapters = [Chapter (fd ) for fd in destination .glob ("*" ) if fd .is_dir () if not (fd / "build.xml" ).exists ()]
348363 for chapter in chapters :
349364 chapter .checkPackages ()
350365 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-
373366
374367
375368@CmdLine ("f" )
@@ -391,8 +384,8 @@ def extractAndCreateBuildFiles():
391384 "Clean, then extract examples from TIJDirectorsCut.txt, build ant files"
392385 clean ()
393386 extractExamples ()
394- copySupplementalFilesFromGithub ()
395387 createAntFiles ()
388+ copySupplementalFilesFromGithub ()
396389 os .chdir ("ExtractedExamples" )
397390 with open ("run.bat" , 'w' ) as run :
398391 run .write (r"python ..\Validate.py -p" + "\n " )
@@ -403,7 +396,6 @@ def extractAndCreateBuildFiles():
403396@CmdLine ('g' )
404397def generateAntClean ():
405398 "Generate directives for Ant-Clean.xml"
406- examples = Path (r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples" )
407399 others = set ([f .name for f in examples .rglob ("*" ) if not f .is_dir ()
408400 if not f .suffix == ".java"
409401 if not f .suffix == ".class"
@@ -437,7 +429,6 @@ def findTags(lines):
437429def findAllCommentTags ():
438430 "Find all '{}' comment tags in Java files"
439431 tagdict = defaultdict (list )
440- examples = Path (r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples" )
441432 for jf in [f for f in examples .rglob ("*.java" )]:
442433 with jf .open () as code :
443434 lines = code .readlines ()
0 commit comments