Changeset 40
- Timestamp:
- 09/23/07 11:30:00 (1 year ago)
- Files:
-
- photobooth/photobooth.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
photobooth/photobooth.py
r39 r40 22 22 23 23 24 from fizzjik.config import ConfigurableService 24 from fizzjik.config import ConfigurableService, if_config 25 25 from fizzjik.interfaces import IController, implements 26 26 from fizzjik.rfid import TagAddedEvent, TagPresentEvent, TagRemovedEvent 27 from fizzjik.remote import anymeta 27 28 28 29 class PhotoboothController(ConfigurableService): … … 31 32 delay = 5.0 32 33 33 def __init__(self ):34 def __init__(self, remote): 34 35 self.bucket = [] 35 self.bucket = [{"id": "1417", "name": "Andy Smit"}] 36 self.remote = remote 37 #self.bucket = [{"id": "1417", "name": "Andy Smit"}] 38 39 @if_config('enabled') 40 def startService(self): 41 ConfigurableService.startService(self) 42 self.test() 43 44 def test(self): 45 e = TagAddedEvent('046792D9') 46 self.addToBucket(e) 47 import pprint 48 d = self.getCurrentTags() 49 d.addCallback(lambda x: pprint.pprint(x) and x or x) 36 50 37 51 def registerObservers(self, hub): … … 43 57 self.startCountdown() 44 58 self.bucket.append(evt.data) 59 self.makeContacts() 45 60 46 def startCoun down(self):61 def startCountdown(self): 47 62 print "counting down" 48 63 if self.countdown and not self.countdown.called: … … 54 69 self.bucket = [{"id": "1417", "name": "Andy Smit"}] 55 70 56 def getCurrentTags(self): 57 return defer.succeed(dict(tags=self.bucket)) 58 71 def makeContacts(self): 72 pass 59 73 60 74 61 75 76 def getCurrentTags(self): 77 d = self._tagsToPeople() 78 79 def _addContacts(rv): 80 for p in rv: 81 p['contacts'] = [{"id": "test", "name": p['name'] + "TEST"}, 82 {"id": "test2", "name": p['name'] + "TEST2"} 83 ] 84 return rv 85 d.addCallback(_addContacts) 86 return d 87 return defer.succeed(dict(tags=self.bucket)) 88 89 def _tagsToPeople(self): 90 l = [] 91 #for tag in self.bucket: 92 # l.append(self._getPersonByTag(tag)) 93 #d = defer.gatherResults(l) 94 95 return defer.succeed([{"id": "1417", "name": "Andy Smith"}, {"id": "4171", "name": "Koe"}]) 96 return d 97 98 def _getPersonByTag(self, tag): 99 d = self.remote.identity.search.uri(uri='urn:rfid:%s'%(tag)) 100 d.addCallback(lambda x: x[0]) 101 return d 102 62 103 63 104 from twisted.web2 import iweb, http, resource, stream … … 67 108 self.controller = controller 68 109 self.child_current_tags = WebCurrentTags(self.controller) 110 self.child_current_contacts = WebCurrentContacts(self.controller) 69 111 70 112 … … 85 127 return http.Response(stream=s) 86 128 129 class WebCurrentContacts(resource.Resource): 130 def __init__(self, controller): 131 self.controller = controller 132 133 def render(self, ctx): 134 req = iweb.IRequest(ctx) 135 s = stream.ProducerStream() 136 137 d = self.controller.getCurrentContacts() 138 #return http.Response(stream="OK") 139 d.addCallback(simplejson.dumps) 140 d.addCallback(s.write) 141 d.addCallback(s.finish) 142 143 return http.Response(stream=s) 87 144 88 145 … … 120 177 json.setServiceParent(hub) 121 178 122 controller = PhotoboothController( )179 controller = PhotoboothController(JSONService) 123 180 controller.setServiceParent(hub) 124 181
