From 7f5c1448925a2939b7fe75c6e80304bb20a585a7 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Sat, 20 Aug 2016 00:30:17 +0200 Subject: [PATCH] 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 --- httpupload/httpupload.py | 28 ++++++++++++++++++---------- httpupload/manifest.ini | 5 +++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/httpupload/httpupload.py b/httpupload/httpupload.py index 3f82e34..653f518 100644 --- a/httpupload/httpupload.py +++ b/httpupload/httpupload.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- ## -from gi.repository import GObject, Gtk +from gi.repository import GObject, Gtk, GLib import os +import sys import time from urllib.request import Request, urlopen 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): if response_code == 0: return # Upload was aborted - if response_code >= 200 and response_code < 300: + if 200 <= response_code < 300: log.info("Upload completed successfully") xhtml = None 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), 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(): progress_messages.put(_('Uploading file via HTTP...')) try: headers = {'User-Agent': 'Gajim %s' % gajim.version, 'Content-Type': mime_type} - request = Request(put.getData(), data=data, headers=headers) - request.get_method = lambda: 'PUT' + request = Request(put.getData(), data=data, headers=headers, method='PUT') log.debug("opening urllib upload request...") transfer = urlopen(request, timeout=30) data.close() @@ -369,11 +377,8 @@ class Base(object): except UploadAbortedException: log.info("Upload aborted") except: - 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) - raise # fill error log with useful information + log.error("Exception during upload", exc_info=sys.exc_info()) + GLib.idle_add(on_upload_error) return 0 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 \ 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: progress_window.close_dialog() log.error("upload component vanished, account got disconnected??") diff --git a/httpupload/manifest.ini b/httpupload/manifest.ini index c848a0f..115c8bb 100644 --- a/httpupload/manifest.ini +++ b/httpupload/manifest.ini @@ -1,7 +1,7 @@ [info] 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.
Your server must support XEP-0363: HTTP Upload.
Conversations supported this.
@@ -11,6 +11,7 @@ description: This plugin is designed to send a file to a contact or muc by using authors: Thilo Molitor Anders Sandblad Philipp Hörist + Linus Heckemann 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