Changeset 123
- Timestamp:
- 02/12/06 20:10:55 (3 years ago)
- Files:
-
- branches/timhtcopy/pyramid/build.py (modified) (4 diffs)
- branches/timhtcopy/pyramid/flatteners.py (modified) (3 diffs)
- branches/timhtcopy/pyramid/yamlRegistry.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/timhtcopy/pyramid/build.py
r114 r123 27 27 28 28 29 def build(data,out,verbose=False,resourcedirs=[],rebuilddirs=None,partialbuild=False ):29 def build(data,out,verbose=False,resourcedirs=[],rebuilddirs=None,partialbuild=False,constants=None): 30 30 31 31 DATADIR = os.path.abspath(data) … … 69 69 # set root 70 70 ctx.root = basedir 71 # set constants 72 ctx.constants = constants 71 73 72 74 for root, dirs, files in os.walk('.'): … … 141 143 else: 142 144 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) 144 159 145 160 … … 151 166 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print status messages to stdout") 152 167 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") 153 169 (options, args) = parser.parse_args() 154 170 main(options,args) branches/timhtcopy/pyramid/flatteners.py
r114 r123 81 81 return T.xml(fp.read()) 82 82 83 84 def 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 83 100 class HtmlFlattener(components.Adapter): 84 101 def flatten(self, ctx, dir): … … 87 104 class HtFileFlattener(components.Adapter): 88 105 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) 94 108 message = rfc822.Message(fp) 95 109 data = dict(message) … … 102 116 class HtFileDataFlattener(components.Adapter): 103 117 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) 105 120 data = dict(message) 106 121 # add lower case keys branches/timhtcopy/pyramid/yamlRegistry.py
r120 r123 17 17 def __repr__(self): 18 18 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) 20 23 return s.getvalue() 21 24 … … 46 49 def __repr__(self): 47 50 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) 49 55 return s.getvalue() 50 56 … … 74 80 75 81 class html(str): 76 ''' a rest filefor converting to html82 ''' a html block for converting to html 77 83 ''' 78 84 pass 79 85 80 86 class htmlfile(str): 81 ''' a restfile for converting to html87 ''' a html file for converting to html 82 88 ''' 83 89 pass 84 90 85 91 class htfile(str): 86 ''' a rest file for converting to html92 ''' a ht file for converting to html 87 93 ''' 88 94 pass 89 95 90 96 class htfiledata: 91 ''' a rest file for converting to ht file datafile and key97 ''' a ht file for converting to ht file datafile and key 92 98 ''' 93 99 def __init__(self,node): … … 159 165 def __repr__(self): 160 166 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) 162 171 return s.getvalue() 163 172
