Mercurial > libervia-backend
comparison tools/memory.py @ 65:d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
/!\ profiles not managed yet for dbus signals
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 31 Jan 2010 15:57:03 +1100 |
parents | d46f849664aa |
children | 8147b4f40809 |
comparison
equal
deleted
inserted
replaced
64:d46f849664aa | 65:d35c5edab53f |
---|---|
34 SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added | 34 SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added |
35 SAVEFILE_HISTORY="/history" | 35 SAVEFILE_HISTORY="/history" |
36 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) | 36 SAVEFILE_PRIVATE="/private" #file used to store misc values (mainly for plugins) |
37 | 37 |
38 class Param(): | 38 class Param(): |
39 """This class manage parameter with xml""" | 39 """This class manage parameters with xml""" |
40 ### TODO: add desciption in params | 40 ### TODO: add desciption in params |
41 | 41 |
42 #TODO: mettre Watched dans un plugin | 42 #TODO: mettre Watched dans un plugin |
43 default_xml = u""" | 43 default_xml = u""" |
44 <params> | 44 <params> |
503 if self.private.has_key(key): | 503 if self.private.has_key(key): |
504 return self.private[key] | 504 return self.private[key] |
505 return None | 505 return None |
506 | 506 |
507 | 507 |
508 def addContact(self, contact_jid, attributes, groups): | 508 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): |
509 debug("Memory addContact: %s",contact_jid.userhost()) | 509 debug("Memory addContact: %s",contact_jid.userhost()) |
510 profile = self.getProfileName(profile_key) | |
511 if not profile: | |
512 error ('Trying to add a contact to a non-existant profile') | |
513 return | |
510 assert(isinstance(attributes,dict)) | 514 assert(isinstance(attributes,dict)) |
511 assert(isinstance(groups,set)) | 515 assert(isinstance(groups,set)) |
512 self.contacts[contact_jid.userhost()]=[attributes, groups] | 516 if not self.contacts.has_key(profile): |
513 | 517 self.contacts[profile] = {} |
514 def delContact(self, contact_jid): | 518 self.contacts[profile][contact_jid.userhost()]=[attributes, groups] |
519 | |
520 def delContact(self, contact_jid, profile_key='@DEFAULT@'): | |
515 debug("Memory delContact: %s",contact_jid.userhost()) | 521 debug("Memory delContact: %s",contact_jid.userhost()) |
516 if self.contacts.has_key(contact_jid.userhost()): | 522 profile = self.getProfileName(profile_key) |
517 del self.contacts[contact_jid.userhost()] | 523 if not profile: |
518 | 524 error ('Trying to delete a contact for a non-existant profile') |
519 def getContact(self, contact_jid): | 525 return |
520 if self.contacts.has_key(contact_jid.userhost()): | 526 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): |
521 self.contacts[contact_jid.userhost()] | 527 del self.contacts[profile][contact_jid.userhost()] |
528 | |
529 def getContact(self, contact_jid, profile_key='@DEFAULT@'): | |
530 profile = self.getProfileName(profile_key) | |
531 if not profile: | |
532 error('Asking a contact for a non-existant profile') | |
533 return None | |
534 if self.contacts.has_key(profile) and self.contacts[profile].has_key(contact_jid.userhost()): | |
535 self.contacts[profile][contact_jid.userhost()] | |
522 else: | 536 else: |
523 return None | 537 return None |
524 | 538 |
525 def getContacts(self): | 539 def getContacts(self, profile_key='@DEFAULT@'): |
540 """Return list of contacts for given profile | |
541 @param profile_key: profile key | |
542 @return list of [contact, attr, groups]""" | |
526 debug ("Memory getContact OK (%s)", self.contacts) | 543 debug ("Memory getContact OK (%s)", self.contacts) |
544 profile = self.getProfileName(profile_key) | |
545 if not profile: | |
546 error('Asking contacts for a non-existant profile') | |
547 return [] | |
527 ret=[] | 548 ret=[] |
528 for contact in self.contacts: | 549 for contact in self.contacts[profile]: |
529 attr, groups = self.contacts[contact] | 550 attr, groups = self.contacts[profile][contact] |
530 ret.append([contact, attr, groups ]) | 551 ret.append([contact, attr, groups ]) |
531 return ret | 552 return ret |
532 | 553 |
533 def addPresenceStatus(self, contact_jid, show, priority, statuses): | 554 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): |
534 if not self.presenceStatus.has_key(contact_jid.userhost()): | 555 profile = self.getProfileName(profile_key) |
535 self.presenceStatus[contact_jid.userhost()] = {} | 556 if not profile: |
557 error('Trying to add presence status to a non-existant profile') | |
558 return | |
559 if not self.presenceStatus.has_key(profile): | |
560 self.presenceStatus[profile] = {} | |
561 if not self.presenceStatus[profile].has_key(contact_jid.userhost()): | |
562 self.presenceStatus[profile][contact_jid.userhost()] = {} | |
536 resource = jid.parse(contact_jid.full())[2] or '' | 563 resource = jid.parse(contact_jid.full())[2] or '' |
537 self.presenceStatus[contact_jid.userhost()][resource] = (show, priority, statuses) | 564 self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses) |
538 | 565 |
539 def addWaitingSub(self, type, contact_jid): | 566 def addWaitingSub(self, type, contact_jid, profile_key): |
540 """Called when a subcription request is received""" | 567 """Called when a subcription request is received""" |
541 self.subscriptions[contact_jid] = type | 568 profile = self.getProfileName(profile_key) |
542 | 569 assert(profile) |
543 def delWaitingSub(self, contact_jid): | 570 if not self.subscriptions.has_key(profile): |
571 self.subscriptions[profile] = {} | |
572 self.subscriptions[profile][contact_jid] = type | |
573 | |
574 def delWaitingSub(self, contact_jid, profile_key): | |
544 """Called when a subcription request is finished""" | 575 """Called when a subcription request is finished""" |
545 if self.subscriptions.has_key(contact_jid): | 576 profile = self.getProfileName(profile_key) |
546 del self.subscriptions[contact_jid] | 577 assert(profile) |
547 | 578 if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(contact_jid): |
548 def getWaitingSub(self): | 579 del self.subscriptions[profile][contact_jid] |
580 | |
581 def getWaitingSub(self, profile_key='@DEFAULT@'): | |
549 """Called to get a list of currently waiting subscription requests""" | 582 """Called to get a list of currently waiting subscription requests""" |
550 return self.subscriptions | 583 profile = self.getProfileName(profile_key) |
551 | 584 if not profile: |
552 def getPresenceStatus(self): | 585 error('Asking waiting subscriptions for a non-existant profile') |
553 debug ("Memory getPresenceStatus (%s)", self.presenceStatus) | 586 return {} |
554 return self.presenceStatus | 587 if not self.subscriptions.has_key(profile): |
588 return {} | |
589 | |
590 return self.subscriptions[profile] | |
591 | |
592 def getPresenceStatus(self, profile_key='@DEFAULT@'): | |
593 profile = self.getProfileName(profile_key) | |
594 if not profile: | |
595 error('Asking contacts for a non-existant profile') | |
596 return {} | |
597 if not self.presenceStatus.has_key(profile): | |
598 self.presenceStatus[profile] = {} | |
599 debug ("Memory getPresenceStatus (%s)", self.presenceStatus[profile]) | |
600 return self.presenceStatus[profile] | |
555 | 601 |
556 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): | 602 def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): |
557 return self.params.getParamA(name, category, attr, profile_key) | 603 return self.params.getParamA(name, category, attr, profile_key) |
558 | 604 |
559 def getParams(self): | 605 def getParams(self): |