jp: all commands now use the new start method and set need_loop in __init__ when needed

This commit is contained in:
Goffi 2016-02-29 16:52:51 +01:00
commit 169bc43793

View file

@ -36,16 +36,15 @@ __commands__ = ["File"]
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 @@ class Receive(base.CommandAnswering):
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 Receive(base.CommandAnswering):
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 @@ class Upload(base.CommandBase):
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)