comparison frontends/src/jp/cmd_file.py @ 1627:5a641e7b858a

jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.
author Goffi <goffi@goffi.org>
date Thu, 19 Nov 2015 18:13:26 +0100
parents a17a91531fbe
children 17f9b911899a
comparison
equal deleted inserted replaced
1626:63cef4dbf2a4 1627:5a641e7b858a
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.host.progress_started = lambda dummy: self.disp(_(u'File copy started'),2)
40 self.host.progress_success = lambda dummy: self.disp(_(u'File copied successfully'),2)
41 self.host.progress_failure = lambda dummy: self.disp(_(u'Error while transfering file'),error=True)
42 39
43 def add_parser_options(self): 40 def add_parser_options(self):
44 self.parser.add_argument("files", type=str, nargs = '+', help=_("A list of file")) 41 self.parser.add_argument("files", type=str, nargs = '+', help=_("A list of file"))
45 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("The destination jid")) 42 self.parser.add_argument("jid", type=base.unicode_decoder, help=_("The destination jid"))
46 self.parser.add_argument("-b", "--bz2", action="store_true", help=_("Make a bzip2 tarball")) 43 self.parser.add_argument("-b", "--bz2", action="store_true", help=_("Make a bzip2 tarball"))
48 def connected(self): 45 def connected(self):
49 """Send files to jabber contact""" 46 """Send files to jabber contact"""
50 self.need_loop=True 47 self.need_loop=True
51 super(Send, self).connected() 48 super(Send, self).connected()
52 self.send_files() 49 self.send_files()
50
51 def onProgressStarted(self, metadata):
52 self.disp(_(u'File copy started'),2)
53
54 def onProgressFinished(self, metadata):
55 self.disp(_(u'File sent successfully'),2)
56
57 def onProgressError(self, error_msg):
58 self.disp(_(u'Error while sending file: {}').format(error_msg),error=True)
53 59
54 def gotId(self, data, file_): 60 def gotId(self, data, file_):
55 """Called when a progress id has been received 61 """Called when a progress id has been received
56 62
57 @param pid(unicode): progress id 63 @param pid(unicode): progress id
110 super(Receive, self).__init__(host, 'receive', use_progress=True, use_verbose=True, help=_('Wait for a file to be sent by a contact')) 116 super(Receive, self).__init__(host, 'receive', use_progress=True, use_verbose=True, help=_('Wait for a file to be sent by a contact'))
111 self._overwrite_refused = False # True when one overwrite as already been refused 117 self._overwrite_refused = False # True when one overwrite as already been refused
112 self.action_callbacks = {C.META_TYPE_FILE: self.onFileAction, 118 self.action_callbacks = {C.META_TYPE_FILE: self.onFileAction,
113 C.META_TYPE_OVERWRITE: self.onOverwriteAction} 119 C.META_TYPE_OVERWRITE: self.onOverwriteAction}
114 120
121 def onProgressStarted(self, metadata):
122 self.disp(_(u'File copy started'),2)
123
124 def onProgressFinished(self, metadata):
125 self.disp(_(u'File received successfully'),2)
126 if metadata.get('hash_verified', False):
127 try:
128 self.disp(_(u'hash checked: {algo}:{checksum}').format(
129 algo=metadata['hash_algo'],
130 checksum=metadata['hash']),
131 1)
132 except KeyError:
133 self.disp(_(u'hash is checked but hash value is missing', 1), error=True)
134 else:
135 self.disp(_(u"hash can't be verified"), 1)
136
137 def onProgressError(self, error_msg):
138 self.disp(_(u'Error while receiving file: {}').format(error_msg),error=True)
139
115 def getXmluiId(self, action_data): 140 def getXmluiId(self, action_data):
116 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module 141 # FIXME: we temporarily use ElementTree, but a real XMLUI managing module
117 # should be available in the futur 142 # should be available in the futur
118 # TODO: XMLUI module 143 # TODO: XMLUI module
119 try: 144 try: