jp (base, file): use of new progress API. Progress callbacks are managed through CommandBase.onProgress* method instead of host attributes.

This commit is contained in:
Goffi 2015-11-19 18:13:26 +01:00
commit 7c340bb518

View file

@ -36,9 +36,6 @@ __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.host.progress_started = lambda dummy: self.disp(_(u'File copy started'),2)
self.host.progress_success = lambda dummy: self.disp(_(u'File copied successfully'),2)
self.host.progress_failure = lambda dummy: self.disp(_(u'Error while transfering file'),error=True)
def add_parser_options(self):
self.parser.add_argument("files", type=str, nargs = '+', help=_("A list of file"))
@ -51,6 +48,15 @@ class Send(base.CommandBase):
super(Send, self).connected()
self.send_files()
def onProgressStarted(self, metadata):
self.disp(_(u'File copy started'),2)
def onProgressFinished(self, metadata):
self.disp(_(u'File sent successfully'),2)
def onProgressError(self, error_msg):
self.disp(_(u'Error while sending file: {}').format(error_msg),error=True)
def gotId(self, data, file_):
"""Called when a progress id has been received
@ -112,6 +118,25 @@ class Receive(base.CommandAnswering):
self.action_callbacks = {C.META_TYPE_FILE: self.onFileAction,
C.META_TYPE_OVERWRITE: self.onOverwriteAction}
def onProgressStarted(self, metadata):
self.disp(_(u'File copy started'),2)
def onProgressFinished(self, metadata):
self.disp(_(u'File received successfully'),2)
if metadata.get('hash_verified', False):
try:
self.disp(_(u'hash checked: {algo}:{checksum}').format(
algo=metadata['hash_algo'],
checksum=metadata['hash']),
1)
except KeyError:
self.disp(_(u'hash is checked but hash value is missing', 1), error=True)
else:
self.disp(_(u"hash can't be verified"), 1)
def onProgressError(self, error_msg):
self.disp(_(u'Error while receiving file: {}').format(error_msg),error=True)
def getXmluiId(self, action_data):
# FIXME: we temporarily use ElementTree, but a real XMLUI managing module
# should be available in the futur