comparison dogdish/dispatcher.py @ 18:6ffbad8cc31f

deal with paths
author jhammel
date Fri, 26 Oct 2012 15:11:06 +0000
parents 427a94428f04
children 608df6b3de80
comparison
equal deleted inserted replaced
17:427a94428f04 18:6ffbad8cc31f
110 110
111 # template for response body 111 # template for response body
112 body = """<?xml version="1.0"?> 112 body = """<?xml version="1.0"?>
113 <updates> 113 <updates>
114 <update type="minor" appVersion="19.0a1" version="19.0a1" extensionVersion="19.0a1" buildID="20121010114416" licenseURL="http://www.mozilla.com/test/sample-eula.html" detailsURL="http://www.mozilla.com/test/sample-details.html"> 114 <update type="minor" appVersion="19.0a1" version="19.0a1" extensionVersion="19.0a1" buildID="20121010114416" licenseURL="http://www.mozilla.com/test/sample-eula.html" detailsURL="http://www.mozilla.com/test/sample-details.html">
115 <patch type="complete" URL="http://update.boot2gecko.org/nightly/%(update)s%(query)s" hashFunction="SHA512" hashValue="%(hash)s" size="%(size)s"/> 115 <patch type="complete" URL="http://update.boot2gecko.org/%(path)s/%(update)s%(query)s" hashFunction="SHA512" hashValue="%(hash)s" size="%(size)s"/>
116 </update> 116 </update>
117 </updates>""" 117 </updates>"""
118 118
119 ### methods for request handler 119 ### methods for request handler
120 120
143 143
144 # template variables 144 # template variables
145 variables = dict(update=current_update.filename, 145 variables = dict(update=current_update.filename,
146 size=current_update.size, 146 size=current_update.size,
147 hash=current_update.hash(), 147 hash=current_update.hash(),
148 path=self.app.path,
148 query=query) 149 query=query)
149 150
150 return Response(content_type='text/xml', 151 return Response(content_type='text/xml',
151 body=body % variables) 152 body=body % variables)
152 153
153 class Dispatcher(object): 154 class Dispatcher(object):
154 """web application""" 155 """web application"""
155 156
156 157
157 ### class level variables 158 ### class level variables
158 defaults = {'directory': here, 159 defaults = {'directory': here,
160 'path': None,
159 'update_class': Update} 161 'update_class': Update}
160 162
161 def __init__(self, **kw): 163 def __init__(self, **kw):
162 164
163 # set defaults 165 # set defaults
164 for key in self.defaults: 166 for key in self.defaults:
165 setattr(self, key, kw.get(key, self.defaults[key])) 167 setattr(self, key, kw.get(key, self.defaults[key]))
166 self.handlers = [ Get ] 168 self.handlers = [ Get ]
169
170 # path
171 if not self.path:
172 self.path = os.path.split(self.directory.strip(os.path.sep))
167 173
168 # cache 174 # cache
169 self.updates = {} 175 self.updates = {}
170 self.current_update = None 176 self.current_update = None
171 177