comparison 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
comparison
equal deleted inserted replaced
1863:b2ddd7f5dcdf 1864:96ba685162f6
34 34
35 35
36 class Send(base.CommandBase): 36 class Send(base.CommandBase):
37 def __init__(self, host): 37 def __init__(self, host):
38 super(Send, self).__init__(host, 'send', use_progress=True, use_verbose=True, help=_('Send a file to a contact')) 38 super(Send, self).__init__(host, 'send', use_progress=True, use_verbose=True, help=_('Send a file to a contact'))
39 self.need_loop=True
39 40
40 def add_parser_options(self): 41 def add_parser_options(self):
41 self.parser.add_argument("files", type=str, nargs='+', metavar='file', help=_("a list of file")) 42 self.parser.add_argument("files", type=str, nargs='+', metavar='file', help=_("a list of file"))
42 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid")) 43 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("the destination jid"))
43 self.parser.add_argument("-b", "--bz2", action="store_true", help=_("make a bzip2 tarball")) 44 self.parser.add_argument("-b", "--bz2", action="store_true", help=_("make a bzip2 tarball"))
44 45
45 def connected(self): 46 def start(self):
46 """Send files to jabber contact""" 47 """Send files to jabber contact"""
47 self.need_loop=True
48 super(Send, self).connected()
49 self.send_files() 48 self.send_files()
50 49
51 def onProgressStarted(self, metadata): 50 def onProgressStarted(self, metadata):
52 self.disp(_(u'File copy started'),2) 51 self.disp(_(u'File copy started'),2)
53 52
201 self.parser.add_argument("jids", type=base.unicode_decoder, nargs="*", help=_(u'JIDs accepted (accept everything if none is specified)')) 200 self.parser.add_argument("jids", type=base.unicode_decoder, nargs="*", help=_(u'JIDs accepted (accept everything if none is specified)'))
202 self.parser.add_argument("-m", "--multiple", action="store_true", help=_(u"accept multiple files (you'll have to stop manually)")) 201 self.parser.add_argument("-m", "--multiple", action="store_true", help=_(u"accept multiple files (you'll have to stop manually)"))
203 self.parser.add_argument("-f", "--force", action="store_true", help=_(u"force overwritting of existing files (/!\\ name is choosed by sended)")) 202 self.parser.add_argument("-f", "--force", action="store_true", help=_(u"force overwritting of existing files (/!\\ name is choosed by sended)"))
204 self.parser.add_argument("--path", default='.', metavar='DIR', help=_(u"destination path (default: working directory)")) 203 self.parser.add_argument("--path", default='.', metavar='DIR', help=_(u"destination path (default: working directory)"))
205 204
206 def run(self): 205 def start(self):
207 super(Receive, self).run()
208 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] 206 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
209 self.path = os.path.abspath(self.args.path) 207 self.path = os.path.abspath(self.args.path)
210 if not os.path.isdir(self.path): 208 if not os.path.isdir(self.path):
211 self.disp(_(u"Given path is not a directory !", error=True)) 209 self.disp(_(u"Given path is not a directory !", error=True))
212 self.quit(2) 210 self.quit(2)
214 self.host.quit_on_progress_end = False 212 self.host.quit_on_progress_end = False
215 self.disp(_(u"waiting for incoming file request"),2) 213 self.disp(_(u"waiting for incoming file request"),2)
216 214
217 215
218 class Upload(base.CommandBase): 216 class Upload(base.CommandBase):
217
219 def __init__(self, host): 218 def __init__(self, host):
220 super(Upload, self).__init__(host, 'upload', use_progress=True, use_verbose=True, help=_('Upload a file')) 219 super(Upload, self).__init__(host, 'upload', use_progress=True, use_verbose=True, help=_('Upload a file'))
220 self.need_loop=True
221 221
222 def add_parser_options(self): 222 def add_parser_options(self):
223 self.parser.add_argument("file", type=str, help=_("file to upload")) 223 self.parser.add_argument("file", type=str, help=_("file to upload"))
224 self.parser.add_argument("jid", type=base.unicode_decoder, nargs='?', help=_("jid of upload component (nothing to autodetect)")) 224 self.parser.add_argument("jid", type=base.unicode_decoder, nargs='?', help=_("jid of upload component (nothing to autodetect)"))
225 self.parser.add_argument("--ignore-tls-errors", action="store_true", help=_("ignore invalide TLS certificate")) 225 self.parser.add_argument("--ignore-tls-errors", action="store_true", help=_("ignore invalide TLS certificate"))
226 226
227 def connected(self):
228 """Send files to jabber contact"""
229 self.need_loop=True
230 super(Upload, self).connected()
231 self.uploadFile()
232
233 def onProgressStarted(self, metadata): 227 def onProgressStarted(self, metadata):
234 self.disp(_(u'File upload started'),2) 228 self.disp(_(u'File upload started'),2)
235 229
236 def onProgressFinished(self, metadata): 230 def onProgressFinished(self, metadata):
237 self.disp(_(u'File uploaded successfully'),2) 231 self.disp(_(u'File uploaded successfully'),2)
262 256
263 def error(self, failure): 257 def error(self, failure):
264 self.disp(_("Error while trying to upload a file: {reason}").format(reason=failure), error=True) 258 self.disp(_("Error while trying to upload a file: {reason}").format(reason=failure), error=True)
265 self.host.quit(1) 259 self.host.quit(1)
266 260
267 def uploadFile(self): 261 def start(self):
268 file_ = self.args.file 262 file_ = self.args.file
269 if not os.path.exists(file_): 263 if not os.path.exists(file_):
270 self.disp(_(u"file [{}] doesn't exist !").format(file_), error=True) 264 self.disp(_(u"file [{}] doesn't exist !").format(file_), error=True)
271 self.host.quit(1) 265 self.host.quit(1)
272 if os.path.isdir(file_): 266 if os.path.isdir(file_):