diff frontends/src/jp/cmd_profile.py @ 1404:e4e960d285b0

jp (profile): added "profile modify" command
author Goffi <goffi@goffi.org>
date Mon, 06 Apr 2015 17:36:53 +0200
parents f913b09cd9cc
children b7ee113183fc
line wrap: on
line diff
--- a/frontends/src/jp/cmd_profile.py	Mon Apr 06 17:36:21 2015 +0200
+++ b/frontends/src/jp/cmd_profile.py	Mon Apr 06 17:36:53 2015 +0200
@@ -115,8 +115,36 @@
         self.host.bridge.asyncCreateProfile(self.args.profile, self.args.password, callback=self._profile_created, errback=None)
 
 
+class ProfileModify(base.CommandBase):
+    def __init__(self, host):
+        super(ProfileModify, self).__init__(host, 'modify', help=_('Modify an existing profile'))
+
+    def add_parser_options(self):
+        self.parser.add_argument('-w', '--password', type=str, default='', help=_('the password of the profile'))
+        self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile'))
+        self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account'),
+                                 metavar='PASSWORD')
+
+    def _profile_created(self):
+        if self.args.jid:
+            self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile)
+        xmpp_pwd = self.args.password or self.args.xmpp_password
+        if xmpp_pwd:
+            self.host.bridge.setParam("Password", xmpp_pwd, "Connection", profile_key=self.args.profile)
+        self.host.quit()
+
+    def connected(self):
+        super(ProfileModify, self).connected()
+        if self.args.password is not None:
+            self.host.bridge.setParam("Password", self.args.password, "General", profile_key=self.host.profile)
+        if self.args.jid is not None:
+            self.host.bridge.setParam("JabberID", self.args.jid, "Connection", profile_key=self.host.profile)
+        if self.args.xmpp_password is not None:
+            self.host.bridge.setParam("Password", self.args.xmpp_password, "Connection", profile_key=self.host.profile)
+
+
 class Profile(base.CommandBase):
-    subcommands = (ProfileDelete, ProfileInfo, ProfileList, ProfileCreate)
+    subcommands = (ProfileDelete, ProfileInfo, ProfileList, ProfileCreate, ProfileModify)
 
     def __init__(self, host):
         super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('Profile commands'))