# HG changeset patch # User souliane # Date 1452714702 -3600 # Node ID f1f4775f8cc0d4c75cde24e95527ace2c72e24ed # Parent c5d58387d031c1b8ee0ec064fdd49c97d058cfeb jp (roster): add command "roster get" with parameters "--subscriptions", "--name" and "--groups" diff -r c5d58387d031 -r f1f4775f8cc0 frontends/src/jp/cmd_roster.py --- a/frontends/src/jp/cmd_roster.py Wed Jan 13 19:46:43 2016 +0100 +++ b/frontends/src/jp/cmd_roster.py Wed Jan 13 20:51:42 2016 +0100 @@ -157,8 +157,54 @@ 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"))