diff sat/plugins/plugin_misc_upload.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 378188abe941
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_upload.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/plugins/plugin_misc_upload.py	Wed Jun 27 20:14:46 2018 +0200
@@ -20,6 +20,7 @@
 from sat.core.i18n import _, D_
 from sat.core.constants import Const as C
 from sat.core.log import getLogger
+
 log = getLogger(__name__)
 from sat.core import exceptions
 from sat.tools import xml_tools
@@ -35,13 +36,13 @@
     C.PI_TYPE: C.PLUG_TYPE_MISC,
     C.PI_MAIN: "UploadPlugin",
     C.PI_HANDLER: "no",
-    C.PI_DESCRIPTION: _("""File upload management""")
+    C.PI_DESCRIPTION: _("""File upload management"""),
 }
 
 
-UPLOADING = D_(u'Please select a file to upload')
-UPLOADING_TITLE = D_(u'File upload')
-BOOL_OPTIONS = ('ignore_tls_errors',)
+UPLOADING = D_(u"Please select a file to upload")
+UPLOADING_TITLE = D_(u"File upload")
+BOOL_OPTIONS = ("ignore_tls_errors",)
 
 
 class UploadPlugin(object):
@@ -50,10 +51,19 @@
     def __init__(self, host):
         log.info(_("plugin Upload initialization"))
         self.host = host
-        host.bridge.addMethod("fileUpload", ".plugin", in_sign='sssa{ss}s', out_sign='a{ss}', method=self._fileUpload, async=True)
+        host.bridge.addMethod(
+            "fileUpload",
+            ".plugin",
+            in_sign="sssa{ss}s",
+            out_sign="a{ss}",
+            method=self._fileUpload,
+            async=True,
+        )
         self._upload_callbacks = []
 
-    def _fileUpload(self, filepath, filename, upload_jid_s='', options=None, profile=C.PROF_KEY_NONE):
+    def _fileUpload(
+        self, filepath, filename, upload_jid_s="", options=None, profile=C.PROF_KEY_NONE
+    ):
         client = self.host.getClient(profile)
         upload_jid = jid.JID(upload_jid_s) if upload_jid_s else None
         if options is None:
@@ -65,7 +75,9 @@
             except KeyError:
                 pass
 
-        return self.fileUpload(client, filepath, filename or None, upload_jid, options or None)
+        return self.fileUpload(
+            client, filepath, filename or None, upload_jid, options or None
+        )
 
     def fileUpload(self, client, filepath, filename, upload_jid, options):
         """Send a file using best available method
@@ -73,14 +85,19 @@
         parameters are the same as for [upload]
         @return (dict): action dictionary, with progress id in case of success, else xmlui message
         """
+
         def uploadCb(data):
             progress_id, dummy = data
-            return {'progress': progress_id}
+            return {"progress": progress_id}
 
         def uploadEb(fail):
             msg = unicode(fail)
             log.warning(msg)
-            return {'xmlui': xml_tools.note(u"Can't upload file", msg, C.XMLUI_DATA_LVL_WARNING).toXml()}
+            return {
+                "xmlui": xml_tools.note(
+                    u"Can't upload file", msg, C.XMLUI_DATA_LVL_WARNING
+                ).toXml()
+            }
 
         d = self.upload(client, filepath, filename, upload_jid, options)
         d.addCallback(uploadCb)
@@ -111,10 +128,14 @@
             try:
                 upload_jid = yield available_cb(upload_jid, client.profile)
             except exceptions.NotFound:
-                continue # no entity managing this extension found
+                continue  # no entity managing this extension found
 
-            log.info(u"{name} method will be used to upload the file".format(name=method_name))
-            progress_id_d, download_d = yield upload_cb(filepath, filename, upload_jid, options, client.profile)
+            log.info(
+                u"{name} method will be used to upload the file".format(name=method_name)
+            )
+            progress_id_d, download_d = yield upload_cb(
+                filepath, filename, upload_jid, options, client.profile
+            )
             progress_id = yield progress_id_d
             defer.returnValue((progress_id, download_d))
 
@@ -137,7 +158,9 @@
         assert method_name
         for data in self._upload_callbacks:
             if method_name == data[0]:
-                raise exceptions.ConflictError(u'A method with this name is already registered')
+                raise exceptions.ConflictError(
+                    u"A method with this name is already registered"
+                )
         self._upload_callbacks.append((method_name, available_cb, upload_cb, priority))
         self._upload_callbacks.sort(key=lambda data: data[3], reverse=True)