comparison frontends/src/jp/jp @ 393:393b35aa86d2

jp: added --connect option
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2011 00:29:04 +0200
parents c34fd9d6242e
children b2caa2615c4c
comparison
equal deleted inserted replaced
392:20f11097d99b 393:393b35aa86d2
101 help=_("Show progress bar")) 101 help=_("Show progress bar"))
102 parser.add_option("-s", "--separate", action="store_true", default=False, 102 parser.add_option("-s", "--separate", action="store_true", default=False,
103 help=_("Separate xmpp messages: send one message per line instead of one message alone.")) 103 help=_("Separate xmpp messages: send one message per line instead of one message alone."))
104 parser.add_option("-n", "--new-line", action="store_true", default=False, 104 parser.add_option("-n", "--new-line", action="store_true", default=False,
105 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))")) 105 help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
106 parser.add_option("--connect", action="store_true", default=False,
107 help=_("Connect the profile before doing anything else"))
106 108
107 (self.options, args) = parser.parse_args() 109 (self.options, args) = parser.parse_args()
108 110
109 if len(args) < 1 and not self.options.wait_file: 111 if len(args) < 1 and not self.options.wait_file:
110 parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8')) 112 parser.error(_("You must specify the destination JID (Jabber ID)").encode('utf-8'))
122 124
123 if not pbar_available and self.options.progress: 125 if not pbar_available and self.options.progress:
124 self.options.progress = False 126 self.options.progress = False
125 error (_("Option progress is not available, deactivated.")) 127 error (_("Option progress is not available, deactivated."))
126 128
127 if self.options.progress or self.options.wait_file: 129 if self.options.progress or self.options.wait_file or self.options.connect:
128 self.start_loop = True #We have to use loop for these options 130 self.start_loop = True #We have to use loop for these options
129 else: 131 else:
130 self.start_loop = False 132 self.start_loop = False
131 133
132 134
133 return args 135 return args
134 136
135 def check_jabber_status(self): 137 def check_jabber_status(self):
136 """Check that jabber status is allright""" 138 """Check that jabber status is allright"""
139 def cantConnect():
140 error(_(u"Can't connect profile"))
141 exit(1)
142
137 143
138 self.profile = self.bridge.getProfileName(self.options.profile) 144 self.profile = self.bridge.getProfileName(self.options.profile)
139 if not self.profile: 145 if not self.profile:
140 error(_("The profile asked doesn't exist")) 146 error(_("The profile asked doesn't exist"))
141 exit(1) 147 exit(1)
142 148
143 if not self.bridge.isConnected(self.profile): 149 if self.options.connect: #if connection is asked, we connect the profile
150 self.bridge.asyncConnect(self.profile, self.connected, cantConnect)
151 return
152 elif not self.bridge.isConnected(self.profile):
144 error(_(u"SàT is not conneted, please connect before using jp")) 153 error(_(u"SàT is not conneted, please connect before using jp"))
145 exit(1) 154 exit(1)
155
156 self.connected()
157
146 158
147 159
148 def send_stdin(self): 160 def send_stdin(self):
149 """Send incomming data on stdin to jabber contact""" 161 """Send incomming data on stdin to jabber contact"""
150 header = "\n" if self.options.new_line else "" 162 header = "\n" if self.options.new_line else ""
246 return True 258 return True
247 259
248 def go(self): 260 def go(self):
249 self.check_options() 261 self.check_options()
250 self.check_jabber_status() 262 self.check_jabber_status()
263 if self.start_loop:
264 self.loop = gobject.MainLoop()
265 try:
266 self.loop.run()
267 except KeyboardInterrupt:
268 info(_("User interruption: good bye"))
269
270 def connected(self):
271 """This is called when the profile is connected"""
251 if self.options.wait_file: 272 if self.options.wait_file:
252 self.wait_file() 273 self.wait_file()
253 else: 274 else:
254 if not self.files: #we send message only if there are no files to send 275 if not self.files: #we send message only if there are no files to send
255 self.send_stdin() 276 self.send_stdin()
256 else: 277 else:
257 self.send_files() 278 self.send_files()
258 279
259 if self.start_loop: 280 if self.options.progress:
260 self.loop = gobject.MainLoop() 281 self.pbar = None
261 if self.options.progress: 282 gobject.timeout_add(10, self.progressCB)
262 self.pbar = None 283
263 gobject.timeout_add(10, self.progressCB) 284 if not self.options.progress and not self.options.wait_file:
264 try: 285 self.loop.quit()
265 self.loop.run()
266 except KeyboardInterrupt:
267 info(_("User interruption: good bye"))
268 286
269 287
270 if __name__ == "__main__": 288 if __name__ == "__main__":
271 jp = JP() 289 jp = JP()
272 jp.go() 290 jp.go()