diff 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
line wrap: on
line diff
--- a/frontends/src/jp/cmd_file.py	Thu Nov 19 18:13:26 2015 +0100
+++ b/frontends/src/jp/cmd_file.py	Thu Nov 19 18:13:26 2015 +0100
@@ -36,9 +36,6 @@
 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 @@
         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 @@
         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