11#! py -3
22"""
3- Extract code examples from TIJ Director's Cut plain text file.
3+ Extract code examples from TIJ4 Refreshed. Extracts from plain text file.
44Creates Ant build.xml file for each subdirectory.
55"""
66from pathlib import Path
@@ -64,6 +64,7 @@ def extractExamples():
6464 codeListing .write ("\n " )
6565
6666
67+ @CmdLine ("x" )
6768def clean ():
6869 "Remove ExtractedExamples directory"
6970 print ("Cleaning ..." )
@@ -119,22 +120,23 @@ def show(lines, sep="#"):
119120
120121
121122
122- # def githubDirs():
123- # leader = len(str(github)) + 1
124- # buildfiles = [str(file)[leader:] for file in github.glob("**/build.xml")]
125- # return {str((github / f).parent)[leader:] for f in buildfiles}
123+ def githubDirs ():
124+ leader = len (str (github )) + 1
125+ buildfiles = [str (file )[leader :] for file in github .glob ("**/build.xml" )]
126+ return {str ((github / f ).parent )[leader :] for f in buildfiles }
126127
127128
128- # def destDirs(pattern="**"):
129- # leader = len(str(destination)) + 1
130- # return {str(file)[leader:] for file in destination.glob(pattern)}
129+ def destDirs (pattern = "**" ):
130+ leader = len (str (destination )) + 1
131+ return {str (file )[leader :] for file in destination .glob (pattern )}
131132
132133
133134
135+ @CmdLine ("a" )
134136def copySupplementalFilesFromGithub ():
135137 "Copy supplemental files from Github repository to extracted examples"
136138 print ("Copying supplemental files from Github ..." )
137- def _copy_from_github (dir , name_or_pattern , trace = False ):
139+ def _copy (dir , name_or_pattern , trace = False ):
138140 source = (github / dir ).glob (name_or_pattern )
139141 dest_dir = examples / dir
140142 assert dest_dir .is_dir ()
@@ -143,15 +145,14 @@ def _copy_from_github(dir, name_or_pattern, trace=False):
143145 print ("source: {}" .format (f ))
144146 print ("dest: {}" .format (dest_dir ))
145147 shutil .copy (str (f ), str (dest_dir ))
146- for args in [
147- ("." , "build.xml" ),
148- ("." , "Ant-*.xml" ),
149- ("gui" , "*.gif" ),
150- ("network" , "*.bat" ),
151- ("network" , "build.xml" ),
152- ("remote" , "*.bat" ),
153- ("remote" , "build.xml" ),
154- ]: _copy_from_github (* args )
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" )
155156
156157 patterns = destination / "patterns"
157158 trash = patterns / "recycleap" / "Trash.dat"
@@ -338,9 +339,25 @@ def makeBuildFile(self):
338339 </exec>
339340"""
340341
341- #@CmdLine("m")
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)
351+
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)
356+
357+
358+ @CmdLine ("m" )
342359def createAntFiles ():
343- "Make ant files"
360+ "Make ant files that don't exist "
344361 print ("Creating Ant Files ..." )
345362 chapters = [Chapter (fd ) for fd in destination .glob ("*" ) if fd .is_dir () if not (fd / "build.xml" ).exists ()]
346363 for chapter in chapters :
@@ -376,6 +393,7 @@ def extractAndCreateBuildFiles():
376393 run .write (r"python ..\Validate.py -e" + "\n " )
377394
378395
396+ @CmdLine ('g' )
379397def generateAntClean ():
380398 "Generate directives for Ant-Clean.xml"
381399 others = set ([f .name for f in examples .rglob ("*" ) if not f .is_dir ()
@@ -390,10 +408,11 @@ def generateAntClean():
390408 for f in others :
391409 print (""" <exclude name="**/{}" />""" .format (f ))
392410
411+ # pprint.pprint([f for f in others if "test" in f or "Test" in f])
393412
413+ tagRE = re .compile ("{.*?}" , re .DOTALL )
394414
395415def findTags (lines ):
396- tagRE = re .compile ("{.*?}" , re .DOTALL )
397416 topblock = []
398417 for line in lines :
399418 if line .startswith ("//" ):
@@ -423,6 +442,4 @@ def findAllCommentTags():
423442
424443
425444
426- if __name__ == '__main__' :
427- print (__doc__ )
428- CmdLine .run ()
445+ if __name__ == '__main__' : CmdLine .run ()
0 commit comments