# HG changeset patch # User Jeff Hammel # Date 1350496598 25200 # Node ID 71f9f68986b5a5ec88f275a620424e64cb9aed33 # Parent 234c2427e52b0d88741e93deb9874060b82808c6 directory scanning + caching diff -r 234c2427e52b -r 71f9f68986b5 dogdish/dispatcher.py --- a/dogdish/dispatcher.py Wed Oct 17 10:29:33 2012 -0700 +++ b/dogdish/dispatcher.py Wed Oct 17 10:56:38 2012 -0700 @@ -98,6 +98,7 @@ self.handlers = [ Get ] self.updates = {} self.current_update = None + self.current_stamp = '0000-00-00_000000' # scan directory self.scan() @@ -117,14 +118,26 @@ def scan(self): """scan the directory for updates""" + prefix = 'b2g_update_' + suffix = '.mar' contents = [i for i in os.listdir(self.directory) - if i.startswith('b2g_update_') and i.endswith('.mar')] + if i.startswith(prefix) and i.endswith(suffix)] contents = set(contents) new = contents.difference(self.updates.keys()) if not new: # directory contents unchanged from cached values return + for update in new: + stamp = update[len(prefix):-len(suffix)] + application_ini = 'application_%s.ini' % stamp + application_ini = os.path.join(self.directory, application_ini) + assert os.path.exists(application_ini) + self.updates[update] = Application(application_ini) + if stamp > self.current_stamp: + self.current_update = update + self.current_stamp = stamp + def main(args=sys.argv[1:]): """CLI entry point"""