changeset 2bf18a964b3d in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=2bf18a964b3d description: [Dicson] check for manifest file when installing a plugin. Fixes #5925
diffstat:
src/dialogs.py | 9 ++++++--- src/plugins/gui.py | 25 ++++++++++++++++++------- src/plugins/pluginmanager.py | 37 +++++++++++++++++++++++-------------- 3 files changed, 47 insertions(+), 24 deletions(-)
diffs (184 lines):
diff -r dd8080184b40 -r 2bf18a964b3d src/dialogs.py --- a/src/dialogs.py Sun Sep 19 22:14:43 2010 +0200 +++ b/src/dialogs.py Mon Sep 20 07:08:47 2010 +0200 @@ -1467,12 +1467,15 @@ HIG compliant warning dialog """
- def __init__(self, pritext, sectext=''): + def __init__(self, pritext, sectext='', transient_for=None): HigDialog.__init__(self, None, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, pritext, sectext) self.set_modal(False) - if hasattr(gajim.interface, 'roster') and gajim.interface.roster: - self.set_transient_for(gajim.interface.roster.window) + if transient_for is None and hasattr(gajim.interface, 'roster') and \ + gajim.interface.roster: + transient_for = gajim.interface.roster.window + if transient_for: + self.set_transient_for(transient_for) self.popup()
class InformationDialog(HigDialog): diff -r dd8080184b40 -r 2bf18a964b3d src/plugins/gui.py --- a/src/plugins/gui.py Sun Sep 19 22:14:43 2010 +0200 +++ b/src/plugins/gui.py Mon Sep 20 07:08:47 2010 +0200 @@ -30,7 +30,7 @@ import gtk, gobject
import gtkgui_helpers -import dialogs +from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog from common import gajim from plugins.helpers import log_calls, log from common.exceptions import PluginsystemError @@ -194,17 +194,26 @@ try: gajim.plugin_manager.remove_plugin(plugin) except PluginsystemError, e: - dialogs.WarningDialog(_('Unable to properly remove the plugin'), + WarningDialog(_('Unable to properly remove the plugin'), str(e)) return model.remove(iter)
@log_calls('PluginsWindow') def on_install_plugin_button_clicked(self, widget): + def show_warn_dialog(): + text = _('Archive is malformed') + dialog = WarningDialog(text, '', transient_for=self.window) + dialog.set_modal(False) + dialog.popup() + def _on_plugin_exists(zip_filename): def on_yes(is_checked): plugin = gajim.plugin_manager.install_from_zip(zip_filename, True) + if not plugin: + show_warn_dialog() + return model = self.installed_plugins_model
for row in xrange(len(model)): @@ -216,8 +225,8 @@ sel = self.installed_plugins_treeview.get_selection() sel.select_iter(iter_)
- dialogs.YesNoDialog(_('Plugin already exists'), - sectext=_('Overwrite?'), on_response_yes=on_yes) + YesNoDialog(_('Plugin already exists'), sectext=_('Overwrite?'), + on_response_yes=on_yes)
def _try_install(zip_filename): try: @@ -228,15 +237,17 @@ _on_plugin_exists(zip_filename) return
- dialogs.WarningDialog(error_text, '"%s"' % zip_filename) + WarningDialog(error_text, '"%s"' % zip_filename) return - + if not plugin: + show_warn_dialog() + return model = self.installed_plugins_model iter_ = model.append([plugin, plugin.name, False]) sel = self.installed_plugins_treeview.get_selection() sel.select_iter(iter_)
- self.dialog = dialogs.ArchiveChooserDialog(on_response_ok=_try_install) + self.dialog = ArchiveChooserDialog(on_response_ok=_try_install)
class GajimPluginConfigDialog(gtk.Dialog): diff -r dd8080184b40 -r 2bf18a964b3d src/plugins/pluginmanager.py --- a/src/plugins/pluginmanager.py Sun Sep 19 22:14:43 2010 +0200 +++ b/src/plugins/pluginmanager.py Mon Sep 20 07:08:47 2010 +0200 @@ -431,6 +431,12 @@
if module is None: continue + + manifest_path = os.path.join(os.path.dirname(file_path), + 'manifest.ini') + if scan_dirs and (not os.path.isfile(manifest_path)): + continue + log.debug('Attributes processing started') for module_attr_name in [attr_name for attr_name in dir(module) if not (attr_name.startswith('__') or attr_name.endswith('__'))]: @@ -445,11 +451,7 @@ module_attr.__path__ = os.path.abspath( os.path.dirname(file_path))
- manifest_path = os.path.join(module_attr.__path__, - 'manifest.ini') # read metadata from manifest.ini - if not os.path.isfile(manifest_path): - continue conf.readfp(open(manifest_path, 'r')) for option in fields: if conf.get('info', option) is '': @@ -484,6 +486,7 @@ raise PluginsystemError(_('Archive corrupted'))
dirs = [] + manifest = None for filename in zip_file.namelist(): if filename.startswith('.') or filename.startswith('/') or \ ('/' not in filename): @@ -491,16 +494,18 @@ raise PluginsystemError(_('Archive is malformed')) if filename.endswith('/') and filename.find('/', 0, -1) < 0: dirs.append(filename) - + if 'manifest.ini' in filename.split('/')[1]: + manifest = True + if not manifest: + return if len(dirs) > 1: - # several directories in the root of the archive raise PluginsystemError(_('Archive is malformed'))
base_dir, user_dir = gajim.PLUGINS_DIRS plugin_dir = os.path.join(user_dir, dirs[0])
if os.path.isdir(plugin_dir): - # Plugin already exists + # Plugin dir already exists if not owerwrite: raise PluginsystemError(_('Plugin already exists')) self.remove_plugin(self.get_plugin_by_path(plugin_dir)) @@ -508,7 +513,10 @@ zip_file.extractall(user_dir) zip_file.close() path = os.path.join(user_dir, dirs[0]) - self.add_plugin(self.scan_dir_for_plugins(plugin_dir, False)[0]) + plugins = self.scan_dir_for_plugins(plugin_dir, False) + if not plugins: + return + self.add_plugin(plugins[0]) plugin = self.plugins[-1] return plugin
@@ -524,12 +532,13 @@ # access is denied or other raise PluginsystemError(error[1])
- if plugin.active: - self.deactivate_plugin(plugin) - rmtree(plugin.__path__, False, on_error) - self.plugins.remove(plugin) - if self._plugin_has_entry_in_global_config(plugin): - self._remove_plugin_entry_in_global_config(plugin) + if plugin: + if plugin.active: + self.deactivate_plugin(plugin) + rmtree(plugin.__path__, False, on_error) + self.plugins.remove(plugin) + if self._plugin_has_entry_in_global_config(plugin): + self._remove_plugin_entry_in_global_config(plugin)
def get_plugin_by_path(self, plugin_dir): for plugin in self.plugins: