Changeset 123

Show
Ignore:
Timestamp:
02/12/06 20:10:55 (3 years ago)
Author:
tim
Message:

added capability of passing in a pydotorg path and using remote ht files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/timhtcopy/pyramid/build.py

    r114 r123  
    2727 
    2828 
    29 def build(data,out,verbose=False,resourcedirs=[],rebuilddirs=None,partialbuild=False): 
     29def build(data,out,verbose=False,resourcedirs=[],rebuilddirs=None,partialbuild=False,constants=None): 
    3030 
    3131    DATADIR = os.path.abspath(data) 
     
    6969    # set root 
    7070    ctx.root = basedir 
     71    # set constants 
     72    ctx.constants = constants 
    7173     
    7274    for root, dirs, files in os.walk('.'): 
     
    141143    else: 
    142144        rebuilddirs = None     
    143     build(options.data,options.out,verbose=options.verbose,resourcedirs=resourcedirs,rebuilddirs=rebuilddirs) 
     145 
     146    if options.constants: 
     147        constants = {} 
     148        assignments = options.constants.strip().split(',') 
     149        if assignments == ['']: 
     150            constants == None 
     151        else: 
     152            for assignment in assignments: 
     153                key, value = assignment.split('=') 
     154                constants[key]=value 
     155    else: 
     156        constants = None     
     157 
     158    build(options.data,options.out,verbose=options.verbose,resourcedirs=resourcedirs,rebuilddirs=rebuilddirs,constants=constants) 
    144159 
    145160 
     
    151166    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print status messages to stdout")     
    152167    parser.add_option("-R", "--rebuilddirs",dest="rebuilddirs",help="only rebuild below these comma separated directories",metavar="REBUILDDIRS") 
     168    parser.add_option("-c", "--constants", dest="constants", help="pass in the names constants (e.g. PDO=/root/pdo,PSF=/psf", metavar="CONSTANTS") 
    153169    (options, args) = parser.parse_args() 
    154170    main(options,args) 
  • branches/timhtcopy/pyramid/flatteners.py

    r114 r123  
    8181        return T.xml(fp.read()) 
    8282 
     83 
     84def getHtfilePointer(ctx,dir,filename): 
     85    if filename[0] == '%': 
     86        filename = filename%ctx.constants 
     87    # if path is not absolute then add current dir else use abspath 
     88    if filename[0] == '/': 
     89        htfile = filename 
     90    else: 
     91        htfile = os.path.join(dir,filename) 
     92    # Try to open file, if fail show error message 
     93    try: 
     94        fp = open(htfile) 
     95    except IOError: 
     96        print 'IOError whilst trying to open "htfile" %s'%(htfile) 
     97    return fp 
     98 
     99 
    83100class HtmlFlattener(components.Adapter): 
    84101    def flatten(self, ctx, dir): 
     
    87104class HtFileFlattener(components.Adapter): 
    88105    def flatten(self, ctx, dir): 
    89         try: 
    90             htfile = os.path.join(dir,self.original) 
    91             fp = open(htfile) 
    92         except IOError: 
    93             print 'IOError whilst trying to open "htfile" %s'%(htfile) 
     106        # expand any string substitutions 
     107        fp = getHtfilePointer(ctx,dir,self.original) 
    94108        message = rfc822.Message(fp) 
    95109        data = dict(message) 
     
    102116class HtFileDataFlattener(components.Adapter): 
    103117    def flatten(self, ctx, dir): 
    104         message = rfc822.Message(open(os.path.join(dir,self.original.file))) 
     118        fp = getHtfilePointer(ctx,dir,self.original.file) 
     119        message = rfc822.Message(fp) 
    105120        data = dict(message) 
    106121        # add lower case keys 
  • branches/timhtcopy/pyramid/yamlRegistry.py

    r120 r123  
    1717    def __repr__(self): 
    1818        s = StringIO() 
    19         pprint({'template':self.template,'globals':self.globals,'locals':self.locals},s,4,10) 
     19        try: 
     20            pprint({'template':self.template,'globals':self.globals,'locals':self.locals},s,4,10) 
     21        except TypeError: 
     22            pprint({'template':self.template,'globals':self.globals,'locals':self.locals},s) 
    2023        return s.getvalue() 
    2124 
     
    4649    def __repr__(self): 
    4750        s = StringIO() 
    48         pprint({'file':self.file},s,4,10) 
     51        try: 
     52            pprint({'file':self.file},s,4,10) 
     53        except TypeError: 
     54            pprint({'file':self.file},s) 
    4955        return s.getvalue() 
    5056     
     
    7480 
    7581class html(str): 
    76     ''' a rest file for converting to html 
     82    ''' a html block for converting to html 
    7783    ''' 
    7884    pass 
    7985 
    8086class htmlfile(str): 
    81     ''' a rest file for converting to html 
     87    ''' a html file for converting to html 
    8288    ''' 
    8389    pass 
    8490 
    8591class htfile(str): 
    86     ''' a rest file for converting to html 
     92    ''' a ht file for converting to html 
    8793    ''' 
    8894    pass 
    8995 
    9096class htfiledata: 
    91     ''' a rest file for converting to ht file datafile and key 
     97    ''' a ht file for converting to ht file datafile and key 
    9298    ''' 
    9399    def __init__(self,node): 
     
    159165    def __repr__(self): 
    160166        s = StringIO() 
    161         pprint({'template':self.template,'file':self.file,'name':self.name},s,4,10) 
     167        try: 
     168            pprint({'template':self.template,'file':self.file,'name':self.name},s,4,10) 
     169        except TypeError: 
     170            pprint({'template':self.template,'file':self.file,'name':self.name},s) 
    162171        return s.getvalue() 
    163172