comparison dogdish/dispatcher.py @ 13:71f9f68986b5

directory scanning + caching
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 17 Oct 2012 10:56:38 -0700
parents 234c2427e52b
children cffb6f681b59
comparison
equal deleted inserted replaced
12:234c2427e52b 13:71f9f68986b5
96 for key in self.defaults: 96 for key in self.defaults:
97 setattr(self, key, kw.get(key, self.defaults[key])) 97 setattr(self, key, kw.get(key, self.defaults[key]))
98 self.handlers = [ Get ] 98 self.handlers = [ Get ]
99 self.updates = {} 99 self.updates = {}
100 self.current_update = None 100 self.current_update = None
101 self.current_stamp = '0000-00-00_000000'
101 102
102 # scan directory 103 # scan directory
103 self.scan() 104 self.scan()
104 105
105 def __call__(self, environ, start_response): 106 def __call__(self, environ, start_response):
115 res = handler() 116 res = handler()
116 return res(environ, start_response) 117 return res(environ, start_response)
117 118
118 def scan(self): 119 def scan(self):
119 """scan the directory for updates""" 120 """scan the directory for updates"""
121 prefix = 'b2g_update_'
122 suffix = '.mar'
120 contents = [i for i in os.listdir(self.directory) 123 contents = [i for i in os.listdir(self.directory)
121 if i.startswith('b2g_update_') and i.endswith('.mar')] 124 if i.startswith(prefix) and i.endswith(suffix)]
122 contents = set(contents) 125 contents = set(contents)
123 new = contents.difference(self.updates.keys()) 126 new = contents.difference(self.updates.keys())
124 if not new: 127 if not new:
125 # directory contents unchanged from cached values 128 # directory contents unchanged from cached values
126 return 129 return
130
131 for update in new:
132 stamp = update[len(prefix):-len(suffix)]
133 application_ini = 'application_%s.ini' % stamp
134 application_ini = os.path.join(self.directory, application_ini)
135 assert os.path.exists(application_ini)
136 self.updates[update] = Application(application_ini)
137 if stamp > self.current_stamp:
138 self.current_update = update
139 self.current_stamp = stamp
127 140
128 def main(args=sys.argv[1:]): 141 def main(args=sys.argv[1:]):
129 """CLI entry point""" 142 """CLI entry point"""
130 143
131 # imports for CLI 144 # imports for CLI