diff frontends/src/jp/cmd_file.py @ 1864:96ba685162f6

jp: all commands now use the new start method and set need_loop in __init__ when needed
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 16:52:51 +0100
parents a19161bb3ff7
children 68944e270c40
line wrap: on
line diff
--- a/frontends/src/jp/cmd_file.py	Mon Feb 29 16:52:51 2016 +0100
+++ b/frontends/src/jp/cmd_file.py	Mon Feb 29 16:52:51 2016 +0100
@@ -36,16 +36,15 @@
 class Send(base.CommandBase):
     def __init__(self, host):
         super(Send, self).__init__(host, 'send', use_progress=True, use_verbose=True, help=_('Send a file to a contact'))
+        self.need_loop=True
 
     def add_parser_options(self):
         self.parser.add_argument("files", type=str, nargs='+', metavar='file', help=_("a list of file"))
         self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid"))
         self.parser.add_argument("-b", "--bz2", action="store_true", help=_("make a bzip2 tarball"))
 
-    def connected(self):
+    def start(self):
         """Send files to jabber contact"""
-        self.need_loop=True
-        super(Send, self).connected()
         self.send_files()
 
     def onProgressStarted(self, metadata):
@@ -203,8 +202,7 @@
         self.parser.add_argument("-f", "--force", action="store_true", help=_(u"force overwritting of existing files (/!\\ name is choosed by sended)"))
         self.parser.add_argument("--path", default='.', metavar='DIR', help=_(u"destination path (default: working directory)"))
 
-    def run(self):
-        super(Receive, self).run()
+    def start(self):
         self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
         self.path = os.path.abspath(self.args.path)
         if not os.path.isdir(self.path):
@@ -216,20 +214,16 @@
 
 
 class Upload(base.CommandBase):
+
     def __init__(self, host):
         super(Upload, self).__init__(host, 'upload', use_progress=True, use_verbose=True, help=_('Upload a file'))
+        self.need_loop=True
 
     def add_parser_options(self):
         self.parser.add_argument("file", type=str, help=_("file to upload"))
         self.parser.add_argument("jid", type=base.unicode_decoder, nargs='?',  help=_("jid of upload component (nothing to autodetect)"))
         self.parser.add_argument("--ignore-tls-errors", action="store_true", help=_("ignore invalide TLS certificate"))
 
-    def connected(self):
-        """Send files to jabber contact"""
-        self.need_loop=True
-        super(Upload, self).connected()
-        self.uploadFile()
-
     def onProgressStarted(self, metadata):
         self.disp(_(u'File upload started'),2)
 
@@ -264,7 +258,7 @@
         self.disp(_("Error while trying to upload a file: {reason}").format(reason=failure), error=True)
         self.host.quit(1)
 
-    def uploadFile(self):
+    def start(self):
         file_ = self.args.file
         if not os.path.exists(file_):
             self.disp(_(u"file [{}] doesn't exist !").format(file_), error=True)