jp: added --connect option
This commit is contained in:
parent
19fac3cd7a
commit
b8edbbab56
1 changed files with 29 additions and 11 deletions
|
|
@ -103,6 +103,8 @@ class JP():
|
||||||
help=_("Separate xmpp messages: send one message per line instead of one message alone."))
|
help=_("Separate xmpp messages: send one message per line instead of one message alone."))
|
||||||
parser.add_option("-n", "--new-line", action="store_true", default=False,
|
parser.add_option("-n", "--new-line", action="store_true", default=False,
|
||||||
help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
|
help=_("Add a new line at the beginning of the input (usefull for ascii art ;))"))
|
||||||
|
parser.add_option("--connect", action="store_true", default=False,
|
||||||
|
help=_("Connect the profile before doing anything else"))
|
||||||
|
|
||||||
(self.options, args) = parser.parse_args()
|
(self.options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
|
@ -124,7 +126,7 @@ class JP():
|
||||||
self.options.progress = False
|
self.options.progress = False
|
||||||
error (_("Option progress is not available, deactivated."))
|
error (_("Option progress is not available, deactivated."))
|
||||||
|
|
||||||
if self.options.progress or self.options.wait_file:
|
if self.options.progress or self.options.wait_file or self.options.connect:
|
||||||
self.start_loop = True #We have to use loop for these options
|
self.start_loop = True #We have to use loop for these options
|
||||||
else:
|
else:
|
||||||
self.start_loop = False
|
self.start_loop = False
|
||||||
|
|
@ -134,16 +136,26 @@ class JP():
|
||||||
|
|
||||||
def check_jabber_status(self):
|
def check_jabber_status(self):
|
||||||
"""Check that jabber status is allright"""
|
"""Check that jabber status is allright"""
|
||||||
|
def cantConnect():
|
||||||
|
error(_(u"Can't connect profile"))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
self.profile = self.bridge.getProfileName(self.options.profile)
|
self.profile = self.bridge.getProfileName(self.options.profile)
|
||||||
if not self.profile:
|
if not self.profile:
|
||||||
error(_("The profile asked doesn't exist"))
|
error(_("The profile asked doesn't exist"))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not self.bridge.isConnected(self.profile):
|
if self.options.connect: #if connection is asked, we connect the profile
|
||||||
|
self.bridge.asyncConnect(self.profile, self.connected, cantConnect)
|
||||||
|
return
|
||||||
|
elif not self.bridge.isConnected(self.profile):
|
||||||
error(_(u"SàT is not conneted, please connect before using jp"))
|
error(_(u"SàT is not conneted, please connect before using jp"))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
self.connected()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def send_stdin(self):
|
def send_stdin(self):
|
||||||
"""Send incomming data on stdin to jabber contact"""
|
"""Send incomming data on stdin to jabber contact"""
|
||||||
|
|
@ -248,6 +260,15 @@ class JP():
|
||||||
def go(self):
|
def go(self):
|
||||||
self.check_options()
|
self.check_options()
|
||||||
self.check_jabber_status()
|
self.check_jabber_status()
|
||||||
|
if self.start_loop:
|
||||||
|
self.loop = gobject.MainLoop()
|
||||||
|
try:
|
||||||
|
self.loop.run()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
info(_("User interruption: good bye"))
|
||||||
|
|
||||||
|
def connected(self):
|
||||||
|
"""This is called when the profile is connected"""
|
||||||
if self.options.wait_file:
|
if self.options.wait_file:
|
||||||
self.wait_file()
|
self.wait_file()
|
||||||
else:
|
else:
|
||||||
|
|
@ -256,15 +277,12 @@ class JP():
|
||||||
else:
|
else:
|
||||||
self.send_files()
|
self.send_files()
|
||||||
|
|
||||||
if self.start_loop:
|
if self.options.progress:
|
||||||
self.loop = gobject.MainLoop()
|
self.pbar = None
|
||||||
if self.options.progress:
|
gobject.timeout_add(10, self.progressCB)
|
||||||
self.pbar = None
|
|
||||||
gobject.timeout_add(10, self.progressCB)
|
if not self.options.progress and not self.options.wait_file:
|
||||||
try:
|
self.loop.quit()
|
||||||
self.loop.run()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
info(_("User interruption: good bye"))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue