Changeset 127

Show
Ignore:
Timestamp:
02/18/06 16:20:21 (3 years ago)
Author:
tim
Message:

added mkpydir which should work with rest files and htfiles and wikiurls

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/timhtcopy/pyramid/mkpydir

    r126 r127  
    11#!/usr/bin/python 
    2 from pyramid import ht2pydir 
    3 ht2pydir.parseOptions() 
     2from pyramid import mkpydir 
     3mkpydir.parseOptions() 
  • branches/timhtcopy/pyramid/mkpydir.py

    r126 r127  
    11import os 
    22from optparse import OptionParser 
     3import shutil  
    34 
    4 ht_index_yml = """--- !fragment 
     5index_yml = """--- !fragment 
    56template: index.html 
    67# The data to pass to the template 
    78local: 
    8   title: !htfiledata 
    9     file: %(PDO)s%(HTFILE)s 
    10     key: title 
     9  title: %(TITLE)s 
    1110  content: !fragment content.yml 
    1211""" 
    1312 
    14 ht_content_yml = """--- !fragment 
     13httitle = """!htfiledata 
     14    file: %(PATH)s 
     15    key: title 
     16""" 
     17 
     18content_yml = """--- !fragment 
    1519# Type of template to use 
    1620template: content.html 
     
    2024  content: 
    2125    breadcrumb: !breadcrumb nav.yml nav 
    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 
     26    text: !%(TYPE)s %(PATH)s 
    4427""" 
    4528 
     
    4932</n:invisible> 
    5033""" 
    51 def mkpydir(type,dir,path,outputdir): 
     34 
     35def writeIndexYml(out,title): 
     36    iyml = file(os.path.join(out,'index.yml'),'w') 
     37    iyml.write(index_yml % {'TITLE':title} ) 
     38    iyml.close() 
     39 
     40def writeContentYml(out,path,directive): 
     41    cyml = file(os.path.join(out,'content.yml'),'w') 
     42    cyml.write(content_yml % {'TYPE': directive,'PATH': path} ) 
     43    cyml.close() 
     44 
     45     
     46def mkpydir(directive,prefix,path,outputdir,copy,title): 
    5247    OUTPUTDIR = os.path.abspath(outputdir) 
    5348    os.mkdir(OUTPUTDIR) 
    5449     
    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': 
     50    if directive == 'htfile': 
    6451         
     52        if copy is True: 
     53            htfile = 'content.ht' 
     54            title = httitle % {'PATH': htfile} 
     55            writeIndexYml(OUTPUTDIR,title) 
     56            writeContentYml(OUTPUTDIR,htfile,directive) 
     57            copyfrom = '%s%s'%(prefix,path) 
     58            copyto = os.path.join(OUTPUTDIR,'content.ht') 
     59            shutil.copyfile(copyfrom,copyto) 
     60        else: 
     61            htfile = '%s%s' % ('%(PDO)s',path) 
     62            title = httitle % {'PATH': htfile} 
     63            writeIndexYml(OUTPUTDIR,title) 
     64            writeContentYml(OUTPUTDIR,htfile,directive) 
     65    elif directive == 'wikiurl': 
     66        wikiurl= '%s%s' % (prefix,path) 
     67        writeIndexYml(OUTPUTDIR,title) 
     68        writeContentYml(OUTPUTDIR,wikiurl,directive) 
     69    elif directive == 'restfile': 
     70        if copy is True: 
     71            restfile = 'content.rst' 
     72            writeIndexYml(OUTPUTDIR,title) 
     73            writeContentYml(OUTPUTDIR,restfile,directive) 
     74            copyfrom = '%s%s'%(prefix,path) 
     75            copyto = os.path.join(OUTPUTDIR,restfile) 
     76            shutil.copyfile(copyfrom,copyto) 
     77        else: 
     78            restfile = '%s%s' % ('%(PDO)s',path) 
     79            writeIndexYml(OUTPUTDIR,title) 
     80            writeContentYml(OUTPUTDIR,restfile,directive) 
    6581 
    6682    chtml = file(os.path.join(OUTPUTDIR,'content.html'),'w') 
     
    6985     
    7086def main(options,args): 
     87    if os.path.isdir(options.outputdir) and options.replace is True: 
     88        shutil.rmtree(options.outputdir) 
    7189         
    72     mkpydir(options.type,options,dir,options.path,options.outputdir,options.copy
     90    mkpydir(options.type,options.dir,options.path,options.outputdir,options.copy,options.title
    7391 
    7492def parseOptions(): 
    75     usage = "usage: mkpydir -t <type (wikiurl|htfile|html)> [-d <prefixdirforsourcefile>] -p <pathtosourcefile> -o <outputdir> [-l]" 
    76     parser = OptionParser(
     93    usage = "usage: mkpydir -t <type (wikiurl|htfile|html|rest)> [-d <prefixdirforsourcefile>] -p <pathtosourcefile> -o <outputdir> [-l] [-R]" 
     94    parser = OptionParser(usage
    7795    parser.add_option("-t", "--type", dest="type", help="the type of pydir content to be created", metavar="TYPE") 
    7896    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") 
    7997    parser.add_option("-p", "--path", dest="path", help="the path to the asset", metavar="PATH") 
    8098    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") 
     99    parser.add_option("-T", "--title", dest="title", help="the page title", metavar="TITLE") 
     100    parser.add_option("-R", "--replace", action="store_true", dest="replace", help="if the directory exists, replace it with the new one", metavar="REPLACE") 
     101    parser.add_option("-l", "--link", action="store_false", help="use a link to an existing ht file", dest="copy", metavar="COPY",default=True) 
     102    parser.add_option("-c", "--copy", action="store_true", help="copy the htfile into the directory",dest="copy", metavar="COPY",default=True) 
    83103    (options, args) = parser.parse_args() 
     104    # further checking of options  
    84105    if options.copy is not False: 
    85106        options.copy=True 
     107    if options.type not in ['wikiurl','htfile','html','restfile']: 
     108        raise KeyError 
    86109    main(options,args) 
    87110 
  • branches/timhtcopy/setup.py

    r114 r127  
    22from distutils.core import setup 
    33setup(name='pyramid', 
    4       version='0.3', 
     4      version='0.4', 
    55      description='Pydotorg Website Build System', 
    66      author='Tim Parkin', 
     
    88      url='http://pyramid.pollenation.net', 
    99      packages=['pyramid'], 
    10       scripts=['pyramid/instantwebserver','pyramid/pyramid'], 
     10      scripts=['pyramid/instantwebserver','pyramid/pyramid','pyramid/mkpydir'], 
    1111      )