comparison frontends/jp/jp @ 110:cb904fa7de3c

jp: profile management (new option: --profile)
author Goffi <goffi@goffi.org>
date Tue, 29 Jun 2010 15:45:11 +0800
parents 8f2ed279784b
children a216dfbb0d50
comparison
equal deleted inserted replaced
109:18b0cf49a6f1 110:cb904fa7de3c
80 80
81 %prog --help for options list 81 %prog --help for options list
82 """) 82 """)
83 parser = OptionParser(usage=usage,version=about) 83 parser = OptionParser(usage=usage,version=about)
84 84
85 parser.add_option("-p", "--profile", action="store", type="string", default='@DEFAULT@',
86 help=_("Use PROFILE profile key"))
85 parser.add_option("-b", "--bz2", action="store_true", default=False, 87 parser.add_option("-b", "--bz2", action="store_true", default=False,
86 help=_("Make a bzip2 tarball")) 88 help=_("Make a bzip2 tarball"))
87 parser.add_option("-w", "--wait-file", action="store_true", default=False, 89 parser.add_option("-w", "--wait-file", action="store_true", default=False,
88 help=_("Wait for a file to be sent by a contact")) 90 help=_("Wait for a file to be sent by a contact"))
89 parser.add_option("-m", "--multiple", action="store_true", default=False, 91 parser.add_option("-m", "--multiple", action="store_true", default=False,
90 help=_("Accept multiple files (you'll have to stop manually)")) 92 help=_("Accept multiple files (you'll have to stop manually)"))
91 parser.add_option("-f", "--force", action="store_true", default=False, 93 parser.add_option("-f", "--force", action="store_true", default=False,
92 help=_("Force overwritting of existing files")) 94 help=_("Force overwritting of existing files"))
93 parser.add_option("-p", "--progress", action="store_true", default=False, 95 parser.add_option("-g", "--progress", action="store_true", default=False,
94 help=_("Show progress bar")) 96 help=_("Show progress bar"))
95 parser.add_option("-s", "--separate", action="store_true", default=False, 97 parser.add_option("-s", "--separate", action="store_true", default=False,
96 help=_("Separate xmpp messages: send one message per line instead of one message alone.")) 98 help=_("Separate xmpp messages: send one message per line instead of one message alone."))
97 parser.add_option("-n", "--new-line", action="store_true", default=False, 99 parser.add_option("-n", "--new-line", action="store_true", default=False,
98 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))")) 100 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
125 127
126 return args 128 return args
127 129
128 def check_jabber_status(self): 130 def check_jabber_status(self):
129 """Check that jabber status is allright""" 131 """Check that jabber status is allright"""
130 if not self.bridge.isConnected(): 132
131 error(_("SAT is not conneted, please connect before using jp")) 133 self.profile = self.bridge.getProfileName(self.options.profile)
134 if not self.profile:
135 error(_("The profile asked doesn't exist"))
136 exit(1)
137
138 if not self.bridge.isConnected(self.profile):
139 error(_(u"SàT is not conneted, please connect before using jp"))
132 exit(1) 140 exit(1)
133 141
134 142
135 def send_stdin(self): 143 def send_stdin(self):
136 """Send incomming data on stdin to jabber contact""" 144 """Send incomming data on stdin to jabber contact"""
137 header = "\n" if self.options.new_line else "" 145 header = "\n" if self.options.new_line else ""
138 146
139 if self.options.separate: #we send stdin in several messages 147 if self.options.separate: #we send stdin in several messages
140 if header: 148 if header:
141 self.bridge.sendMessage(self.dest_jid, header) 149 self.bridge.sendMessage(self.dest_jid, header, profile_key=self.profile)
142 while (True): 150 while (True):
143 line = sys.stdin.readline() 151 line = sys.stdin.readline()
144 if not line: 152 if not line:
145 break 153 break
146 self.bridge.sendMessage(self.dest_jid, line.replace("\n","")) 154 self.bridge.sendMessage(self.dest_jid, line.replace("\n",""), profile_key=self.profile)
147 else: 155 else:
148 self.bridge.sendMessage(self.dest_jid, header + "".join(sys.stdin.readlines())) 156 self.bridge.sendMessage(self.dest_jid, header + "".join(sys.stdin.readlines()), profile_key=self.profile)
149 157
150 def send_files(self): 158 def send_files(self):
151 """Send files to jabber contact""" 159 """Send files to jabber contact"""
152 160
153 for file in self.files: 161 for file in self.files:
172 info(_("Adding %s"), file) 180 info(_("Adding %s"), file)
173 bz2.add(file) 181 bz2.add(file)
174 bz2.close() 182 bz2.close()
175 info(_("OK !")) 183 info(_("OK !"))
176 path = abspath(tmpfile) 184 path = abspath(tmpfile)
177 self.transfert_id = self.bridge.sendFile(self.dest_jid, path) 185 self.transfert_id = self.bridge.sendFile(self.dest_jid, path, profile_key=self.profile)
178 else: 186 else:
179 for file in self.files: 187 for file in self.files:
180 path = abspath(file) 188 path = abspath(file)
181 self.transfert_id = self.bridge.sendFile(self.dest_jid, path) #FIXME: show progress only for last transfert_id 189 self.transfert_id = self.bridge.sendFile(self.dest_jid, path, profile_key=self.profile) #FIXME: show progress only for last transfert_id
182 190
183 #TODO: manage ProgressBar 191 #TODO: manage ProgressBar
184 192
185 def askConfirmation(self, type, id, data): 193 def askConfirmation(self, type, id, data):
186 """CB used for file transfert, accept files depending on parameters""" 194 """CB used for file transfert, accept files depending on parameters"""