changeset 2893:7c8773723200

jp (roster): added resync command to do a full roster resynchronisation
author Goffi <goffi@goffi.org>
date Sun, 07 Apr 2019 18:50:13 +0200
parents 82b781c46841
children c7c52c0dc13a
files sat_frontends/jp/cmd_roster.py
diffstat 1 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_roster.py	Sun Apr 07 18:49:41 2019 +0200
+++ b/sat_frontends/jp/cmd_roster.py	Sun Apr 07 18:50:13 2019 +0200
@@ -19,11 +19,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import base
-from sat_frontends.jp.constants import Const as C
+from collections import OrderedDict
+from functools import partial
 from sat.core.i18n import _
-
+from sat_frontends.jp.constants import Const as C
 from twisted.words.protocols.jabber import jid
-from collections import OrderedDict
 
 __commands__ = ["Roster"]
 
@@ -207,8 +207,32 @@
         self.host.quit()
 
 
+class Resync(base.CommandBase):
+
+    def __init__(self, host):
+        super(Resync, self).__init__(
+            host, 'resync', help=_(u'do a full resynchronisation of roster with server'))
+        self.need_loop = True
+
+    def add_parser_options(self):
+        pass
+
+    def rosterResyncCb(self):
+        self.disp(_(u"Roster resynchronized"))
+        self.host.quit(C.EXIT_OK)
+
+    def start(self):
+        self.host.bridge.rosterResync(profile_key=self.host.profile,
+                                      callback=self.rosterResyncCb,
+                                      errback=partial(
+                                          self.errback,
+                                          msg=_(u"can't resynchronise roster: {}"),
+                                          exit_code=C.EXIT_BRIDGE_ERRBACK,
+                                      ))
+
+
 class Roster(base.CommandBase):
-    subcommands = (Get, Stats, Purge)
+    subcommands = (Get, Stats, Purge, Resync)
 
     def __init__(self, host):
         super(Roster, self).__init__(host, 'roster', use_profile=True, help=_("Manage an entity's roster"))