[Dicson] check for manifest file when installing a plugin. Fixes #5925
This commit is contained in:
parent
463eade6dc
commit
2c95192037
|
@ -1467,12 +1467,15 @@ class WarningDialog(HigDialog):
|
||||||
HIG compliant warning dialog
|
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,
|
HigDialog.__init__(self, None, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK,
|
||||||
pritext, sectext)
|
pritext, sectext)
|
||||||
self.set_modal(False)
|
self.set_modal(False)
|
||||||
if hasattr(gajim.interface, 'roster') and gajim.interface.roster:
|
if transient_for is None and hasattr(gajim.interface, 'roster') and \
|
||||||
self.set_transient_for(gajim.interface.roster.window)
|
gajim.interface.roster:
|
||||||
|
transient_for = gajim.interface.roster.window
|
||||||
|
if transient_for:
|
||||||
|
self.set_transient_for(transient_for)
|
||||||
self.popup()
|
self.popup()
|
||||||
|
|
||||||
class InformationDialog(HigDialog):
|
class InformationDialog(HigDialog):
|
||||||
|
|
|
@ -30,7 +30,7 @@ import pango
|
||||||
import gtk, gobject
|
import gtk, gobject
|
||||||
|
|
||||||
import gtkgui_helpers
|
import gtkgui_helpers
|
||||||
import dialogs
|
from dialogs import WarningDialog, YesNoDialog, ArchiveChooserDialog
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from plugins.helpers import log_calls, log
|
from plugins.helpers import log_calls, log
|
||||||
from common.exceptions import PluginsystemError
|
from common.exceptions import PluginsystemError
|
||||||
|
@ -194,17 +194,26 @@ class PluginsWindow(object):
|
||||||
try:
|
try:
|
||||||
gajim.plugin_manager.remove_plugin(plugin)
|
gajim.plugin_manager.remove_plugin(plugin)
|
||||||
except PluginsystemError, e:
|
except PluginsystemError, e:
|
||||||
dialogs.WarningDialog(_('Unable to properly remove the plugin'),
|
WarningDialog(_('Unable to properly remove the plugin'),
|
||||||
str(e))
|
str(e))
|
||||||
return
|
return
|
||||||
model.remove(iter)
|
model.remove(iter)
|
||||||
|
|
||||||
@log_calls('PluginsWindow')
|
@log_calls('PluginsWindow')
|
||||||
def on_install_plugin_button_clicked(self, widget):
|
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_plugin_exists(zip_filename):
|
||||||
def on_yes(is_checked):
|
def on_yes(is_checked):
|
||||||
plugin = gajim.plugin_manager.install_from_zip(zip_filename,
|
plugin = gajim.plugin_manager.install_from_zip(zip_filename,
|
||||||
True)
|
True)
|
||||||
|
if not plugin:
|
||||||
|
show_warn_dialog()
|
||||||
|
return
|
||||||
model = self.installed_plugins_model
|
model = self.installed_plugins_model
|
||||||
|
|
||||||
for row in xrange(len(model)):
|
for row in xrange(len(model)):
|
||||||
|
@ -216,8 +225,8 @@ class PluginsWindow(object):
|
||||||
sel = self.installed_plugins_treeview.get_selection()
|
sel = self.installed_plugins_treeview.get_selection()
|
||||||
sel.select_iter(iter_)
|
sel.select_iter(iter_)
|
||||||
|
|
||||||
dialogs.YesNoDialog(_('Plugin already exists'),
|
YesNoDialog(_('Plugin already exists'), sectext=_('Overwrite?'),
|
||||||
sectext=_('Overwrite?'), on_response_yes=on_yes)
|
on_response_yes=on_yes)
|
||||||
|
|
||||||
def _try_install(zip_filename):
|
def _try_install(zip_filename):
|
||||||
try:
|
try:
|
||||||
|
@ -228,15 +237,17 @@ class PluginsWindow(object):
|
||||||
_on_plugin_exists(zip_filename)
|
_on_plugin_exists(zip_filename)
|
||||||
return
|
return
|
||||||
|
|
||||||
dialogs.WarningDialog(error_text, '"%s"' % zip_filename)
|
WarningDialog(error_text, '"%s"' % zip_filename)
|
||||||
|
return
|
||||||
|
if not plugin:
|
||||||
|
show_warn_dialog()
|
||||||
return
|
return
|
||||||
|
|
||||||
model = self.installed_plugins_model
|
model = self.installed_plugins_model
|
||||||
iter_ = model.append([plugin, plugin.name, False])
|
iter_ = model.append([plugin, plugin.name, False])
|
||||||
sel = self.installed_plugins_treeview.get_selection()
|
sel = self.installed_plugins_treeview.get_selection()
|
||||||
sel.select_iter(iter_)
|
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):
|
class GajimPluginConfigDialog(gtk.Dialog):
|
||||||
|
|
|
@ -431,6 +431,12 @@ class PluginManager(object):
|
||||||
|
|
||||||
if module is None:
|
if module is None:
|
||||||
continue
|
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')
|
log.debug('Attributes processing started')
|
||||||
for module_attr_name in [attr_name for attr_name in dir(module)
|
for module_attr_name in [attr_name for attr_name in dir(module)
|
||||||
if not (attr_name.startswith('__') or attr_name.endswith('__'))]:
|
if not (attr_name.startswith('__') or attr_name.endswith('__'))]:
|
||||||
|
@ -445,11 +451,7 @@ class PluginManager(object):
|
||||||
module_attr.__path__ = os.path.abspath(
|
module_attr.__path__ = os.path.abspath(
|
||||||
os.path.dirname(file_path))
|
os.path.dirname(file_path))
|
||||||
|
|
||||||
manifest_path = os.path.join(module_attr.__path__,
|
|
||||||
'manifest.ini')
|
|
||||||
# read metadata from manifest.ini
|
# read metadata from manifest.ini
|
||||||
if not os.path.isfile(manifest_path):
|
|
||||||
continue
|
|
||||||
conf.readfp(open(manifest_path, 'r'))
|
conf.readfp(open(manifest_path, 'r'))
|
||||||
for option in fields:
|
for option in fields:
|
||||||
if conf.get('info', option) is '':
|
if conf.get('info', option) is '':
|
||||||
|
@ -484,6 +486,7 @@ class PluginManager(object):
|
||||||
raise PluginsystemError(_('Archive corrupted'))
|
raise PluginsystemError(_('Archive corrupted'))
|
||||||
|
|
||||||
dirs = []
|
dirs = []
|
||||||
|
manifest = None
|
||||||
for filename in zip_file.namelist():
|
for filename in zip_file.namelist():
|
||||||
if filename.startswith('.') or filename.startswith('/') or \
|
if filename.startswith('.') or filename.startswith('/') or \
|
||||||
('/' not in filename):
|
('/' not in filename):
|
||||||
|
@ -491,16 +494,18 @@ class PluginManager(object):
|
||||||
raise PluginsystemError(_('Archive is malformed'))
|
raise PluginsystemError(_('Archive is malformed'))
|
||||||
if filename.endswith('/') and filename.find('/', 0, -1) < 0:
|
if filename.endswith('/') and filename.find('/', 0, -1) < 0:
|
||||||
dirs.append(filename)
|
dirs.append(filename)
|
||||||
|
if 'manifest.ini' in filename.split('/')[1]:
|
||||||
|
manifest = True
|
||||||
|
if not manifest:
|
||||||
|
return
|
||||||
if len(dirs) > 1:
|
if len(dirs) > 1:
|
||||||
# several directories in the root of the archive
|
|
||||||
raise PluginsystemError(_('Archive is malformed'))
|
raise PluginsystemError(_('Archive is malformed'))
|
||||||
|
|
||||||
base_dir, user_dir = gajim.PLUGINS_DIRS
|
base_dir, user_dir = gajim.PLUGINS_DIRS
|
||||||
plugin_dir = os.path.join(user_dir, dirs[0])
|
plugin_dir = os.path.join(user_dir, dirs[0])
|
||||||
|
|
||||||
if os.path.isdir(plugin_dir):
|
if os.path.isdir(plugin_dir):
|
||||||
# Plugin already exists
|
# Plugin dir already exists
|
||||||
if not owerwrite:
|
if not owerwrite:
|
||||||
raise PluginsystemError(_('Plugin already exists'))
|
raise PluginsystemError(_('Plugin already exists'))
|
||||||
self.remove_plugin(self.get_plugin_by_path(plugin_dir))
|
self.remove_plugin(self.get_plugin_by_path(plugin_dir))
|
||||||
|
@ -508,7 +513,10 @@ class PluginManager(object):
|
||||||
zip_file.extractall(user_dir)
|
zip_file.extractall(user_dir)
|
||||||
zip_file.close()
|
zip_file.close()
|
||||||
path = os.path.join(user_dir, dirs[0])
|
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]
|
plugin = self.plugins[-1]
|
||||||
return plugin
|
return plugin
|
||||||
|
|
||||||
|
@ -524,6 +532,7 @@ class PluginManager(object):
|
||||||
# access is denied or other
|
# access is denied or other
|
||||||
raise PluginsystemError(error[1])
|
raise PluginsystemError(error[1])
|
||||||
|
|
||||||
|
if plugin:
|
||||||
if plugin.active:
|
if plugin.active:
|
||||||
self.deactivate_plugin(plugin)
|
self.deactivate_plugin(plugin)
|
||||||
rmtree(plugin.__path__, False, on_error)
|
rmtree(plugin.__path__, False, on_error)
|
||||||
|
|
Loading…
Reference in New Issue