changeset 110:cb904fa7de3c

jp: profile management (new option: --profile)
author Goffi <goffi@goffi.org>
date Tue, 29 Jun 2010 15:45:11 +0800
parents 18b0cf49a6f1
children 6c927140ba82
files frontends/jp/jp
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/jp/jp	Tue Jun 29 15:19:59 2010 +0800
+++ b/frontends/jp/jp	Tue Jun 29 15:45:11 2010 +0800
@@ -82,6 +82,8 @@
         """)
         parser = OptionParser(usage=usage,version=about)
 
+        parser.add_option("-p", "--profile", action="store", type="string", default='@DEFAULT@',
+                    help=_("Use PROFILE profile key"))
         parser.add_option("-b", "--bz2", action="store_true", default=False,
                     help=_("Make a bzip2 tarball"))
         parser.add_option("-w", "--wait-file", action="store_true", default=False,
@@ -90,7 +92,7 @@
                     help=_("Accept multiple files (you'll have to stop manually)"))
         parser.add_option("-f", "--force", action="store_true", default=False,
                     help=_("Force overwritting of existing files"))
-        parser.add_option("-p", "--progress", action="store_true", default=False,
+        parser.add_option("-g", "--progress", action="store_true", default=False,
                     help=_("Show progress bar"))
         parser.add_option("-s", "--separate", action="store_true", default=False,
                     help=_("Separate xmpp messages: send one message per line instead of one message alone."))
@@ -127,8 +129,14 @@
 
     def check_jabber_status(self):
         """Check that jabber status is allright"""
-        if not self.bridge.isConnected():
-            error(_("SAT is not conneted, please connect before using jp"))
+        
+        self.profile = self.bridge.getProfileName(self.options.profile)
+        if not self.profile:
+            error(_("The profile asked doesn't exist"))
+            exit(1)
+
+        if not self.bridge.isConnected(self.profile):
+            error(_(u"SàT is not conneted, please connect before using jp"))
             exit(1)
 
 
@@ -138,14 +146,14 @@
 
         if self.options.separate:  #we send stdin in several messages
             if header:
-                self.bridge.sendMessage(self.dest_jid, header)
+                self.bridge.sendMessage(self.dest_jid, header, profile_key=self.profile)
             while (True):
                 line = sys.stdin.readline()
                 if not line:
                     break
-                self.bridge.sendMessage(self.dest_jid, line.replace("\n",""))
+                self.bridge.sendMessage(self.dest_jid, line.replace("\n",""), profile_key=self.profile)
         else:
-            self.bridge.sendMessage(self.dest_jid, header + "".join(sys.stdin.readlines()))
+            self.bridge.sendMessage(self.dest_jid, header + "".join(sys.stdin.readlines()), profile_key=self.profile)
 
     def send_files(self):
         """Send files to jabber contact"""
@@ -174,11 +182,11 @@
             bz2.close()
             info(_("OK !"))
             path = abspath(tmpfile)
-            self.transfert_id = self.bridge.sendFile(self.dest_jid, path)
+            self.transfert_id = self.bridge.sendFile(self.dest_jid, path, profile_key=self.profile)
         else:
             for file in self.files:
                 path = abspath(file)
-                self.transfert_id = self.bridge.sendFile(self.dest_jid, path) #FIXME: show progress only for last transfert_id
+                self.transfert_id = self.bridge.sendFile(self.dest_jid, path, profile_key=self.profile) #FIXME: show progress only for last transfert_id
 
         #TODO: manage ProgressBar