Changeset 45

Show
Ignore:
Timestamp:
09/24/07 13:42:43 (1 year ago)
Author:
devja..@anarkystic.com
Message:

fetch people on tag added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • photobooth/photobooth.py

    r44 r45  
    3636    delay = 5.0 
    3737    remote = None 
    38  
     38    bucket = None 
     39    people = None 
     40     
    3941    def __init__(self, remote): 
    4042        self.bucket = [] 
     43        self.people = {} 
    4144        self.remote = remote 
    4245        #self.bucket = [{"id": "1417", "name": "Andy Smit"}] 
     
    4952    def test(self): 
    5053        e = TagAddedEvent('046792D9') 
    51         self.addToBucket(e) 
    52         import pprint 
    5354        d = self.getCurrentTags() 
     55        d.addCallback(lambda x: pprint.pprint(x) and x or x) 
     56        d.addCallbacks(lambda x: self.addToBucket(e)) 
     57        d.addCallbacks(lambda x: self.getCurrentTags()) 
    5458        d.addCallback(lambda x: pprint.pprint(x) and x or x) 
    5559 
     
    6165        if not self.bucket: 
    6266            self.startCountdown() 
     67        if evt.data in self.bucket: 
     68            return 
     69 
     70        d = self._tagToPerson(evt.data) 
     71        def _cachePerson(person): 
     72            pprint.pprint(person) 
     73            self.people[evt.data] = person 
     74            return person 
     75 
     76        d.addCallback(_cachePerson) 
     77        d.addCallback(self.makeContacts) 
     78        if not self.bucket: 
     79            d.addCallback(lambda x: self.startCountdown()) 
    6380        self.bucket.append(evt.data) 
    64         self.makeContacts() 
     81        return d 
    6582 
    6683    def startCountdown(self): 
     
    7390        print "clearing bucket" 
    7491        self.bucket = [] 
     92        self.people = {} 
    7593        #self.bucket = [{"id": "1417", "name": "Andy Smit"}] 
    7694 
    77     def makeContacts(self): 
     95    def makeContacts(self, person): 
    7896        pass 
    7997 
    8098     
    81  
    8299    def getCurrentTags(self): 
     100        people = [self.people[tag] for tag in self.bucket if tag in self.people] 
     101        return defer.succeed(people) 
    83102        d = self._tagsToPeople() 
    84103         
     
    97116        return d 
    98117 
    99     def _tagsToPeople(self): 
    100         l = [] 
    101         for tag in self.bucket: 
    102             l.append(self._getPersonByTag(tag).addCallback( 
    103                 self._fillContacts)) 
    104         d = defer.gatherResults(l) 
    105         return d 
    106  
    107         #return defer.succeed([{"id": "1417", "name": "Andy Smith"}, {"id": "4171", "name": "Koe"}]) 
     118    def _tagToPerson(self, tag): 
     119        d = self._getPersonByTag(tag) 
     120        d.addCallback(self._fillContacts) 
    108121        return d 
    109122