comparison sat/plugins/plugin_misc_upload.py @ 2863:a97a5c73594d

plugin upload: fixed inversion of title and message body + better error message on failed upload
author Goffi <goffi@goffi.org>
date Wed, 20 Mar 2019 09:08:47 +0100
parents 003b8b4b56a7
children 3cac3d050046
comparison
equal deleted inserted replaced
2862:b2e898384c25 2863:a97a5c73594d
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 from sat.core import exceptions 25 from sat.core import exceptions
26 from sat.tools import xml_tools 26 from sat.tools import xml_tools
27 from twisted.internet import defer 27 from twisted.internet import defer
28 from twisted.words.protocols.jabber import jid 28 from twisted.words.protocols.jabber import jid
29 from twisted.words.protocols.jabber import error as jabber_error
29 import os 30 import os
30 import os.path 31 import os.path
31 32
32 33
33 PLUGIN_INFO = { 34 PLUGIN_INFO = {
89 def uploadCb(data): 90 def uploadCb(data):
90 progress_id, __ = data 91 progress_id, __ = data
91 return {"progress": progress_id} 92 return {"progress": progress_id}
92 93
93 def uploadEb(fail): 94 def uploadEb(fail):
94 msg = unicode(fail) 95 if (isinstance(fail.value, jabber_error.StanzaError)
96 and fail.value.condition == 'not-acceptable'):
97 reason = fail.value.text
98 else:
99 reason = unicode(fail.value)
100 msg = D_(u"Can't upload file: {reason}").format(reason=reason)
95 log.warning(msg) 101 log.warning(msg)
96 return { 102 return {
97 "xmlui": xml_tools.note( 103 "xmlui": xml_tools.note(
98 u"Can't upload file", msg, C.XMLUI_DATA_LVL_WARNING 104 msg, D_(u"Can't upload file"), C.XMLUI_DATA_LVL_WARNING
99 ).toXml() 105 ).toXml()
100 } 106 }
101 107
102 d = self.upload(client, filepath, filename, upload_jid, options) 108 d = self.upload(client, filepath, filename, upload_jid, options)
103 d.addCallback(uploadCb) 109 d.addCallback(uploadCb)