jp (roster): add command "roster get" with parameters "--subscriptions", "--name" and "--groups"
This commit is contained in:
parent
988990f6f5
commit
8471941dc7
1 changed files with 47 additions and 1 deletions
|
|
@ -157,8 +157,54 @@ class Stats(base.CommandBase):
|
|||
self.host.quit()
|
||||
|
||||
|
||||
class Get(base.CommandBase):
|
||||
|
||||
def __init__(self, host):
|
||||
super(Get, self).__init__(host, 'get', help=_('Retrieve the roster contacts'))
|
||||
|
||||
def add_parser_options(self):
|
||||
self.parser.add_argument("--subscriptions", action="store_true", help=_("Show the contacts' subscriptions"))
|
||||
self.parser.add_argument("--groups", action="store_true", help=_("Show the contacts' groups"))
|
||||
self.parser.add_argument("--name", action="store_true", help=_("Show the contacts' names"))
|
||||
|
||||
def connected(self):
|
||||
self.need_loop = True
|
||||
super(Get, self).connected()
|
||||
self.host.bridge.getContacts(profile_key=self.host.profile, callback=self.gotContacts, errback=self.error)
|
||||
|
||||
def error(self, failure):
|
||||
print (_("Error while retrieving the contacts [%s]") % failure)
|
||||
self.host.quit(1)
|
||||
|
||||
def gotContacts(self, contacts):
|
||||
"""Process the list of contacts.
|
||||
|
||||
@param contacts(list[tuple]): list of contacts with their attributes and groups
|
||||
"""
|
||||
field_count = 1 # only display the contact by default
|
||||
if self.args.subscriptions:
|
||||
field_count += 3 # ask, from, to
|
||||
if self.args.name:
|
||||
field_count += 1
|
||||
if self.args.groups:
|
||||
field_count += 1
|
||||
for contact, attrs, groups in contacts:
|
||||
args = [contact]
|
||||
if self.args.subscriptions:
|
||||
args.append("ask" if C.bool(attrs["ask"]) else "")
|
||||
args.append("from" if C.bool(attrs["from"]) else "")
|
||||
args.append("to" if C.bool(attrs["to"]) else "")
|
||||
if self.args.name:
|
||||
args.append(unicode(attrs.get("name", "")))
|
||||
if self.args.groups:
|
||||
# FIXME: pipe character could also be in a group name
|
||||
args.append(u"|".join(groups) if groups else "")
|
||||
print u";".join(["{}"] * field_count).format(*args).encode("utf-8")
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class Roster(base.CommandBase):
|
||||
subcommands = (Purge, Stats)
|
||||
subcommands = (Get, Stats, Purge)
|
||||
|
||||
def __init__(self, host):
|
||||
super(Roster, self).__init__(host, 'roster', use_profile=True, help=_("Manage an entity's roster"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue