[plugin_installer] Add more useful logging output

This commit is contained in:
Philipp Hörist
2017-02-24 20:02:16 +01:00
parent 14083c5b30
commit 61a244d292

View File

@@ -37,7 +37,6 @@ import urllib.error
from urllib.request import urlopen from urllib.request import urlopen
from common import gajim from common import gajim
from plugins import GajimPlugin from plugins import GajimPlugin
from plugins.helpers import log_calls, log
from htmltextview import HtmlTextView from htmltextview import HtmlTextView
from dialogs import WarningDialog, HigDialog, YesNoDialog from dialogs import WarningDialog, HigDialog, YesNoDialog
from plugins.gui import GajimPluginConfigDialog from plugins.gui import GajimPluginConfigDialog
@@ -77,8 +76,6 @@ def convert_version_to_list(version_str):
return l return l
class PluginInstaller(GajimPlugin): class PluginInstaller(GajimPlugin):
@log_calls('PluginInstallerPlugin')
def init(self): def init(self):
self.description = _('Install and Upgrade Plugins') self.description = _('Install and Upgrade Plugins')
self.config_dialog = PluginInstallerPluginConfigDialog(self) self.config_dialog = PluginInstallerPluginConfigDialog(self)
@@ -92,14 +89,12 @@ class PluginInstaller(GajimPlugin):
self.def_icon = icon.render_icon(Gtk.STOCK_PREFERENCES, self.def_icon = icon.render_icon(Gtk.STOCK_PREFERENCES,
Gtk.IconSize.MENU) Gtk.IconSize.MENU)
@log_calls('PluginInstallerPlugin')
def activate(self): def activate(self):
if self.config['check_update']: if self.config['check_update']:
self.timeout_id = GLib.timeout_add_seconds(30, self.check_update) self.timeout_id = GLib.timeout_add_seconds(30, self.check_update)
if 'plugins' in gajim.interface.instances: if 'plugins' in gajim.interface.instances:
self.on_activate(gajim.interface.instances['plugins']) self.on_activate(gajim.interface.instances['plugins'])
@log_calls('PluginInstallerPlugin')
def warn_update(self, plugins): def warn_update(self, plugins):
def open_update(dummy): def open_update(dummy):
get_action('plugins').activate() get_action('plugins').activate()
@@ -111,16 +106,17 @@ class PluginInstaller(GajimPlugin):
' your installer plugins. Do you want to update those plugins:' ' your installer plugins. Do you want to update those plugins:'
'\n%s') % plugins_str, on_response_yes=open_update) '\n%s') % plugins_str, on_response_yes=open_update)
else: else:
log.info('No updates found')
if hasattr(self, 'thread'): if hasattr(self, 'thread'):
del self.thread del self.thread
def check_update(self): def check_update(self):
if hasattr(self, 'thread'): if hasattr(self, 'thread'):
return return
log.info('Checking for Updates...')
self.start_download(check_update=True) self.start_download(check_update=True)
self.timeout_id = 0 self.timeout_id = 0
@log_calls('PluginInstallerPlugin')
def deactivate(self): def deactivate(self):
if hasattr(self, 'available_page'): if hasattr(self, 'available_page'):
self.notebook.remove_page(self.notebook.page_num(self.paned)) self.notebook.remove_page(self.notebook.page_num(self.paned))
@@ -247,8 +243,12 @@ class PluginInstaller(GajimPlugin):
_('An error occurred when downloading\n\n' _('An error occurred when downloading\n\n'
'<tt>[%s]</tt>' % (str(text))), self.window) '<tt>[%s]</tt>' % (str(text))), self.window)
def start_download(self, secure=True, remote_dirs=None, def start_download(self, secure=True, remote_dirs=False,
upgrading=False, check_update=False): upgrading=False, check_update=False):
log.info('Start Download...')
log.debug(
'secure: %s, remote_dirs: %s, upgrading: %s, check_update: %s',
secure, remote_dirs, upgrading, check_update)
self.thread = DownloadAsync( self.thread = DownloadAsync(
self, secure=secure, remote_dirs=remote_dirs, self, secure=secure, remote_dirs=remote_dirs,
upgrading=upgrading, check_update=check_update) upgrading=upgrading, check_update=check_update)
@@ -268,6 +268,7 @@ class PluginInstaller(GajimPlugin):
if plugin: if plugin:
if plugin.active: if plugin.active:
is_active = True is_active = True
log.info('Deactivate Plugin: %s', plugin)
gajim.plugin_manager.deactivate_plugin(plugin) gajim.plugin_manager.deactivate_plugin(plugin)
gajim.plugin_manager.plugins.remove(plugin) gajim.plugin_manager.plugins.remove(plugin)
@@ -277,18 +278,22 @@ class PluginInstaller(GajimPlugin):
model.remove(model.get_iter((row, 0))) model.remove(model.get_iter((row, 0)))
break break
log.info('Load Plugin from: %s', plugin_dir)
plugins = gajim.plugin_manager.scan_dir_for_plugins( plugins = gajim.plugin_manager.scan_dir_for_plugins(
plugin_dir, package=True) plugin_dir, package=True)
if not plugins: if not plugins:
log.warn('Loading Plugin failed')
continue continue
gajim.plugin_manager.add_plugin(plugins[0]) gajim.plugin_manager.add_plugin(plugins[0])
plugin = gajim.plugin_manager.plugins[-1] plugin = gajim.plugin_manager.plugins[-1]
log.info('Loading successful')
for row in range(len(self.available_plugins_model)): for row in range(len(self.available_plugins_model)):
if plugin.name == self.available_plugins_model[row][Column.NAME]: if plugin.name == self.available_plugins_model[row][Column.NAME]:
self.available_plugins_model[row][Column.LOCAL_VERSION] = \ self.available_plugins_model[row][Column.LOCAL_VERSION] = \
plugin.version plugin.version
self.available_plugins_model[row][Column.UPGRADE] = False self.available_plugins_model[row][Column.UPGRADE] = False
if is_active: if is_active:
log.info('Activate Plugin: %s', plugin)
gajim.plugin_manager.activate_plugin(plugin) gajim.plugin_manager.activate_plugin(plugin)
# get plugin icon # get plugin icon
icon_file = os.path.join(plugin.__path__, os.path.split( icon_file = os.path.join(plugin.__path__, os.path.split(
@@ -351,8 +356,7 @@ class PluginInstaller(GajimPlugin):
class DownloadAsync(threading.Thread): class DownloadAsync(threading.Thread):
def __init__(self, plugin, secure=True, remote_dirs=None, def __init__(self, plugin, secure, remote_dirs, upgrading, check_update):
upgrading=False, check_update=False):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.plugin = plugin self.plugin = plugin
self.window = plugin.window self.window = plugin.window
@@ -412,7 +416,7 @@ class DownloadAsync(threading.Thread):
return plugins return plugins
def download_url(self, url): def download_url(self, url):
log.debug('Fetching {}'.format(url)) log.info('Fetching %s', url)
ssl_args = {} ssl_args = {}
if self.secure: if self.secure:
ssl_args['context'] = ssl.create_default_context( ssl_args['context'] = ssl.create_default_context(
@@ -426,7 +430,7 @@ class DownloadAsync(threading.Thread):
'OP_NO_TLSv1', 'OP_NO_TLSv1_1', 'OP_NO_TLSv1', 'OP_NO_TLSv1_1',
'OP_NO_COMPRESSION', 'OP_NO_COMPRESSION',
): ):
log.info('Installer SSL: +%s' % flag) log.debug('SSL Options: +%s' % flag)
ssl_args['context'].options |= getattr(ssl, flag) ssl_args['context'].options |= getattr(ssl, flag)
request = urlopen(url, **ssl_args) request = urlopen(url, **ssl_args)
@@ -456,6 +460,7 @@ class DownloadAsync(threading.Thread):
GLib.idle_add(self.progressbar.show) GLib.idle_add(self.progressbar.show)
self.pulse = GLib.timeout_add(150, self.progressbar_pulse) self.pulse = GLib.timeout_add(150, self.progressbar_pulse)
if not self.remote_dirs: if not self.remote_dirs:
log.info('Downloading Pluginlist...')
buf = self.download_url(MANIFEST_IMAGE_URL) buf = self.download_url(MANIFEST_IMAGE_URL)
zip_file = zipfile.ZipFile(buf) zip_file = zipfile.ZipFile(buf)
manifest_list = zip_file.namelist() manifest_list = zip_file.namelist()
@@ -515,6 +520,7 @@ class DownloadAsync(threading.Thread):
def download_plugin(self): def download_plugin(self):
for remote_dir in self.remote_dirs: for remote_dir in self.remote_dirs:
filename = remote_dir + '.zip' filename = remote_dir + '.zip'
log.info('Download: %s', filename)
base_dir, user_dir = gajim.PLUGINS_DIRS base_dir, user_dir = gajim.PLUGINS_DIRS
if not os.path.isdir(user_dir): if not os.path.isdir(user_dir):
os.mkdir(user_dir) os.mkdir(user_dir)