httpupload: Improve error handling
- An error during the upload now no longer hangs everything (GUI changes placed in main thread) - Some formatting changes - Update version in manifest (I think a new minor version is in order for GTK3 support!) - Add self to authors in manifest (shameless plugs, whoop whoop) - Remove claim of supporting older versions of gajim
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##
|
##
|
||||||
|
|
||||||
from gi.repository import GObject, Gtk
|
from gi.repository import GObject, Gtk, GLib
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
import mimetypes # better use the magic packet, but that's not a standard lib
|
import mimetypes # better use the magic packet, but that's not a standard lib
|
||||||
@@ -322,7 +323,7 @@ class Base(object):
|
|||||||
def upload_complete(response_code):
|
def upload_complete(response_code):
|
||||||
if response_code == 0:
|
if response_code == 0:
|
||||||
return # Upload was aborted
|
return # Upload was aborted
|
||||||
if response_code >= 200 and response_code < 300:
|
if 200 <= response_code < 300:
|
||||||
log.info("Upload completed successfully")
|
log.info("Upload completed successfully")
|
||||||
xhtml = None
|
xhtml = None
|
||||||
is_image = mime_type.split('/', 1)[0] == 'image'
|
is_image = mime_type.split('/', 1)[0] == 'image'
|
||||||
@@ -354,13 +355,20 @@ class Base(object):
|
|||||||
_('Got unexpected http response code from server: ') + str(response_code),
|
_('Got unexpected http response code from server: ') + str(response_code),
|
||||||
transient_for=self.chat_control.parent_win.window)
|
transient_for=self.chat_control.parent_win.window)
|
||||||
|
|
||||||
|
def on_upload_error():
|
||||||
|
progress_window.close_dialog()
|
||||||
|
ErrorDialog(_('Could not upload file'),
|
||||||
|
_('Got unexpected exception while uploading file'
|
||||||
|
' (see error log for more information)'),
|
||||||
|
transient_for=self.chat_control.parent_win.window)
|
||||||
|
return 0
|
||||||
|
|
||||||
def uploader():
|
def uploader():
|
||||||
progress_messages.put(_('Uploading file via HTTP...'))
|
progress_messages.put(_('Uploading file via HTTP...'))
|
||||||
try:
|
try:
|
||||||
headers = {'User-Agent': 'Gajim %s' % gajim.version,
|
headers = {'User-Agent': 'Gajim %s' % gajim.version,
|
||||||
'Content-Type': mime_type}
|
'Content-Type': mime_type}
|
||||||
request = Request(put.getData(), data=data, headers=headers)
|
request = Request(put.getData(), data=data, headers=headers, method='PUT')
|
||||||
request.get_method = lambda: 'PUT'
|
|
||||||
log.debug("opening urllib upload request...")
|
log.debug("opening urllib upload request...")
|
||||||
transfer = urlopen(request, timeout=30)
|
transfer = urlopen(request, timeout=30)
|
||||||
data.close()
|
data.close()
|
||||||
@@ -369,11 +377,8 @@ class Base(object):
|
|||||||
except UploadAbortedException:
|
except UploadAbortedException:
|
||||||
log.info("Upload aborted")
|
log.info("Upload aborted")
|
||||||
except:
|
except:
|
||||||
progress_window.close_dialog()
|
log.error("Exception during upload", exc_info=sys.exc_info())
|
||||||
ErrorDialog(_('Could not upload file'),
|
GLib.idle_add(on_upload_error)
|
||||||
_('Got unexpected exception while uploading file (see error log for more information)'),
|
|
||||||
transient_for=self.chat_control.parent_win.window)
|
|
||||||
raise # fill error log with useful information
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
log.info("Uploading file to '%s'..." % str(put.getData()))
|
log.info("Uploading file to '%s'..." % str(put.getData()))
|
||||||
@@ -383,7 +388,10 @@ class Base(object):
|
|||||||
|
|
||||||
is_supported = gajim.get_jid_from_account(self.chat_control.account) in jid_to_servers and \
|
is_supported = gajim.get_jid_from_account(self.chat_control.account) in jid_to_servers and \
|
||||||
gajim.connections[self.chat_control.account].connection != None
|
gajim.connections[self.chat_control.account].connection != None
|
||||||
log.info("jid_to_servers of %s: %s ; connection: %s" % (gajim.get_jid_from_account(self.chat_control.account), str(jid_to_servers[gajim.get_jid_from_account(self.chat_control.account)]), str(gajim.connections[self.chat_control.account].connection)))
|
log.info("jid_to_servers of %s: %s ; connection: %s",
|
||||||
|
gajim.get_jid_from_account(self.chat_control.account),
|
||||||
|
str(jid_to_servers[gajim.get_jid_from_account(self.chat_control.account)]),
|
||||||
|
str(gajim.connections[self.chat_control.account].connection))
|
||||||
if not is_supported:
|
if not is_supported:
|
||||||
progress_window.close_dialog()
|
progress_window.close_dialog()
|
||||||
log.error("upload component vanished, account got disconnected??")
|
log.error("upload component vanished, account got disconnected??")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[info]
|
[info]
|
||||||
name: HttpUpload
|
name: HttpUpload
|
||||||
short_name: httpupload
|
short_name: httpupload
|
||||||
version: 0.4.0
|
version: 0.5.0
|
||||||
description: This plugin is designed to send a file to a contact or muc by using httpupload.<br/>
|
description: This plugin is designed to send a file to a contact or muc by using httpupload.<br/>
|
||||||
Your server must support <a href="http://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP Upload</a>.<br/>
|
Your server must support <a href="http://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP Upload</a>.<br/>
|
||||||
Conversations supported this.<br/>
|
Conversations supported this.<br/>
|
||||||
@@ -11,6 +11,7 @@ description: This plugin is designed to send a file to a contact or muc by using
|
|||||||
authors: Thilo Molitor <thilo@eightysoft.de>
|
authors: Thilo Molitor <thilo@eightysoft.de>
|
||||||
Anders Sandblad <runeson@gmail.com>
|
Anders Sandblad <runeson@gmail.com>
|
||||||
Philipp Hörist <philipp@hoerist.com>
|
Philipp Hörist <philipp@hoerist.com>
|
||||||
|
Linus Heckemann <linus@sphalerite.org>
|
||||||
homepage: https://trac-plugins.gajim.org/wiki/HttpUploadPlugin
|
homepage: https://trac-plugins.gajim.org/wiki/HttpUploadPlugin
|
||||||
min_gajim_version: 0.16.5
|
min_gajim_version: 0.16.10
|
||||||
max_gajim_version: 0.16.10.1
|
max_gajim_version: 0.16.10.1
|
||||||
|
|||||||
Reference in New Issue
Block a user