Changeset 125
- Timestamp:
- 02/18/06 14:52:45 (3 years ago)
- Files:
-
- branches/timhtcopy/pyramid/ht2pydir.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/timhtcopy/pyramid/ht2pydir.py
r124 r125 2 2 from optparse import OptionParser 3 3 4 index_yml = """--- !fragment4 ht_index_yml = """--- !fragment 5 5 template: index.html 6 6 # The data to pass to the template 7 7 local: 8 8 title: !htfiledata 9 file: % %(PDO)s%(HTFILE)s9 file: %(PDO)s%(HTFILE)s 10 10 key: title 11 11 content: !fragment content.yml 12 12 """ 13 13 14 content_yml = """--- !fragment14 ht_content_yml = """--- !fragment 15 15 # Type of template to use 16 16 template: content.html … … 20 20 content: 21 21 breadcrumb: !breadcrumb nav.yml nav 22 text: !htfile %%(PDO)s%(HTFILE)s 22 text: !htfile %(PDO)s%(HTFILE)s 23 """ 24 25 wiki_index_yml = """--- !fragment 26 template: index.html 27 # The data to pass to the template 28 local: 29 title: !htfiledata 30 file: %(PDO)s%(HTFILE)s 31 key: title 32 content: !fragment content.yml 33 """ 34 35 wiki_content_yml = """--- !fragment 36 # Type of template to use 37 template: content.html 38 39 # The data to pass to the template 40 local: 41 content: 42 breadcrumb: !breadcrumb nav.yml nav 43 text: !wikiurl %(WIKIPREFIX)s%(WIKIURL)s 23 44 """ 24 45 … … 28 49 </n:invisible> 29 50 """ 30 def ht2pydir(htfile,outputdir):51 def mkpydir(type,dir,path,outputdir): 31 52 OUTPUTDIR = os.path.abspath(outputdir) 32 53 os.mkdir(OUTPUTDIR) 33 54 34 iyml = file(os.path.join(OUTPUTDIR,'index.yml'),'w') 35 iyml.write(index_yml % {'HTFILE':htfile} ) 36 iyml.close() 37 38 cyml = file(os.path.join(OUTPUTDIR,'content.yml'),'w') 39 cyml.write(content_yml % {'HTFILE':htfile} ) 40 cyml.close() 55 if type == 'htfile': 56 iyml = file(os.path.join(OUTPUTDIR,'index.yml'),'w') 57 iyml.write(index_yml % {'HTFILE':htfile} ) 58 iyml.close() 59 60 cyml = file(os.path.join(OUTPUTDIR,'content.yml'),'w') 61 cyml.write(content_yml % {'HTFILE':htfile} ) 62 cyml.close() 63 elif type == 'wikiurl': 64 41 65 42 66 chtml = file(os.path.join(OUTPUTDIR,'content.html'),'w') … … 45 69 46 70 def main(options,args): 47 ht2pydir(options.htfile,options.outputdir) 71 72 mkpydir(options.type,options,dir,options.path,options.outputdir,options.copy) 48 73 49 74 def parseOptions(): 75 usage = "usage: mkpydir -t <type (wikiurl|htfile|html)> [-d <prefixdirforsourcefile>] -p <pathtosourcefile> -o <outputdir> [-l]" 50 76 parser = OptionParser() 51 parser.add_option("-d", "--htfile", dest="htfile", help="the path to the htfile", metavar="HTFILE") 77 parser.add_option("-t", "--type", dest="type", help="the type of pydir content to be created", metavar="TYPE") 78 parser.add_option("-d", "--dir", dest="dir", help="the root directory for the an asset (to be used when sourcing pydotorg or wiki content)", metavar="DIR") 79 parser.add_option("-p", "--path", dest="path", help="the path to the asset", metavar="PATH") 52 80 parser.add_option("-o", "--outputdir", dest="outputdir", help="directory in which to create the pyramid directory", metavar="OUTPUTDIR") 81 parser.add_option("-l", "--link", action="store_false", help="use a link to an existing ht file", dest="copy", metavar="LINK") 82 parser.add_option("-c", "--copy", action="store_true", help="copy the htfile into the directory",dest="copy", metavar="LINK") 53 83 (options, args) = parser.parse_args() 84 if options.copy is not False: 85 options.copy=True 54 86 main(options,args) 55 87
