jp (roster): add parameters "--no_from" and "--no_to" to command "roster purge" in order to remove the contacts with no from/to subscription
This commit is contained in:
parent
8a920d41c0
commit
6a680d9ff8
1 changed files with 28 additions and 12 deletions
|
|
@ -35,7 +35,8 @@ class Purge(base.CommandBase):
|
|||
super(Purge, self).__init__(host, 'purge', help=_('Purge the roster from its contacts with no subscription'))
|
||||
|
||||
def add_parser_options(self):
|
||||
pass
|
||||
self.parser.add_argument("--no_from", action="store_true", help=_("Also purge contacts with no 'from' subscription"))
|
||||
self.parser.add_argument("--no_to", action="store_true", help=_("Also purge contacts with no 'to' subscription"))
|
||||
|
||||
def connected(self):
|
||||
self.need_loop = True
|
||||
|
|
@ -46,14 +47,23 @@ class Purge(base.CommandBase):
|
|||
print (_("Error while retrieving the contacts [%s]") % failure)
|
||||
self.host.quit(1)
|
||||
|
||||
def ask_confirmation(self, to_remove):
|
||||
"""Ask the confirmation before removing contacts without subscription.
|
||||
def ask_confirmation(self, none, no_from, no_to):
|
||||
"""Ask the confirmation before removing contacts.
|
||||
|
||||
@param to_remove (list[unicode]): list of contacts
|
||||
@param none (list[unicode]): list of contacts with no subscription
|
||||
@param no_from (list[unicode]): list of contacts with no 'from' subscription
|
||||
@param no_to (list[unicode]): list of contacts with no 'to' subscription
|
||||
@return bool
|
||||
"""
|
||||
print "There's no subscription between profile [%s] and the following contacts:" % self.host.profile
|
||||
print " " + "\n ".join(to_remove)
|
||||
if none:
|
||||
print "There's no subscription between profile [%s] and the following contacts:" % self.host.profile
|
||||
print " " + "\n ".join(none)
|
||||
if no_from:
|
||||
print "There's no 'from' subscription between profile [%s] and the following contacts:" % self.host.profile
|
||||
print " " + "\n ".join(no_from)
|
||||
if no_to:
|
||||
print "There's no 'to' subscription between profile [%s] and the following contacts:" % self.host.profile
|
||||
print " " + "\n ".join(no_to)
|
||||
message = "REMOVE them from profile [%s]'s roster" % self.host.profile
|
||||
while True:
|
||||
res = raw_input("%s (y/N)? " % message)
|
||||
|
|
@ -67,14 +77,20 @@ class Purge(base.CommandBase):
|
|||
|
||||
@param contacts(list[tuple]): list of contacts with their attributes and groups
|
||||
"""
|
||||
to_remove = []
|
||||
none, no_from, no_to = [], [], []
|
||||
for contact, attrs, groups in contacts:
|
||||
if not C.bool(attrs["from"]) and not C.bool(attrs["to"]):
|
||||
to_remove.append(contact)
|
||||
if not to_remove:
|
||||
from_, to = C.bool(attrs["from"]), C.bool(attrs["to"])
|
||||
if not from_:
|
||||
if not to:
|
||||
none.append(contact)
|
||||
elif self.args.no_from:
|
||||
no_from.append(contact)
|
||||
elif not to and self.args.no_to:
|
||||
no_to.append(contact)
|
||||
if not none and not no_from and not no_to:
|
||||
print "Nothing to do - there's a from and/or to subscription(s) between profile [%s] and each of its contacts" % self.host.profile
|
||||
elif self.ask_confirmation(to_remove):
|
||||
for contact in to_remove:
|
||||
elif self.ask_confirmation(none, no_from, no_to):
|
||||
for contact in none + no_from + no_to:
|
||||
self.host.bridge.delContact(contact, profile_key=self.host.profile, callback=lambda dummy: None, errback=lambda failure: None)
|
||||
self.host.quit()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue