11#! py -3
22"""
3- Extract code examples from TIJ4 Refreshed. Extracts from plain text file.
3+ Extract code examples from TIJ Director's Cut plain text file.
44Creates Ant build.xml file for each subdirectory.
55"""
66from pathlib import Path
@@ -64,7 +64,6 @@ def extractExamples():
6464 codeListing .write ("\n " )
6565
6666
67- @CmdLine ("x" )
6867def clean ():
6968 "Remove ExtractedExamples directory"
7069 print ("Cleaning ..." )
@@ -120,23 +119,22 @@ def show(lines, sep="#"):
120119
121120
122121
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 }
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}
127126
128127
129- def destDirs (pattern = "**" ):
130- leader = len (str (destination )) + 1
131- return {str (file )[leader :] for file in destination .glob (pattern )}
128+ # def destDirs(pattern="**"):
129+ # leader = len(str(destination)) + 1
130+ # return {str(file)[leader:] for file in destination.glob(pattern)}
132131
133132
134133
135- @CmdLine ("a" )
136134def copySupplementalFilesFromGithub ():
137135 "Copy supplemental files from Github repository to extracted examples"
138136 print ("Copying supplemental files from Github ..." )
139- def _copy (dir , name_or_pattern , trace = False ):
137+ def _copy_from_github (dir , name_or_pattern , trace = False ):
140138 source = (github / dir ).glob (name_or_pattern )
141139 dest_dir = examples / dir
142140 assert dest_dir .is_dir ()
@@ -145,14 +143,15 @@ def _copy(dir, name_or_pattern, trace=False):
145143 print ("source: {}" .format (f ))
146144 print ("dest: {}" .format (dest_dir ))
147145 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" )
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 )
156155
157156 patterns = destination / "patterns"
158157 trash = patterns / "recycleap" / "Trash.dat"
@@ -339,25 +338,9 @@ def makeBuildFile(self):
339338 </exec>
340339"""
341340
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" )
341+ #@CmdLine("m")
359342def createAntFiles ():
360- "Make ant files that don't exist "
343+ "Make ant files"
361344 print ("Creating Ant Files ..." )
362345 chapters = [Chapter (fd ) for fd in destination .glob ("*" ) if fd .is_dir () if not (fd / "build.xml" ).exists ()]
363346 for chapter in chapters :
@@ -393,7 +376,6 @@ def extractAndCreateBuildFiles():
393376 run .write (r"python ..\Validate.py -e" + "\n " )
394377
395378
396- @CmdLine ('g' )
397379def generateAntClean ():
398380 "Generate directives for Ant-Clean.xml"
399381 others = set ([f .name for f in examples .rglob ("*" ) if not f .is_dir ()
@@ -408,11 +390,10 @@ def generateAntClean():
408390 for f in others :
409391 print (""" <exclude name="**/{}" />""" .format (f ))
410392
411- # pprint.pprint([f for f in others if "test" in f or "Test" in f])
412393
413- tagRE = re .compile ("{.*?}" , re .DOTALL )
414394
415395def findTags (lines ):
396+ tagRE = re .compile ("{.*?}" , re .DOTALL )
416397 topblock = []
417398 for line in lines :
418399 if line .startswith ("//" ):
@@ -442,4 +423,6 @@ def findAllCommentTags():
442423
443424
444425
445- if __name__ == '__main__' : CmdLine .run ()
426+ if __name__ == '__main__' :
427+ print (__doc__ )
428+ CmdLine .run ()
0 commit comments