code style reformatting using black

This commit is contained in:
Goffi 2018-06-27 20:14:46 +02:00
commit 744cb0c503

View file

@ -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 @@ PLUGIN_INFO = {
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 @@ class UploadPlugin(object):
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 @@ class UploadPlugin(object):
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 @@ class UploadPlugin(object):
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 @@ class UploadPlugin(object):
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 @@ class UploadPlugin(object):
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)