def test_create(self): # Creating the Plugin, setting its version to None and then creating it # again should just change the plugin_version to 0 foo = InstalledPlugin.create(self.store, u'foo') foo.plugin_version = None foo = InstalledPlugin.create(self.store, u'foo') self.assertEqual(foo.plugin_version, 0) self.assertRaises(PluginError, InstalledPlugin.create, self.store, u'foo')
def test_create(self): # Creating the Plugin, setting its version to None and then creating it # again should just change the plugin_version to 0 foo = InstalledPlugin.create(self.store, u'foo') foo.plugin_version = None foo = InstalledPlugin.create(self.store, u'foo') self.assertEquals(foo.plugin_version, 0) self.assertRaises(PluginError, InstalledPlugin.create, self.store, u'foo')
def install_plugin(self, store, plugin_name): """Install and enable a plugin @important: Calling this makes a plugin installed, but, it's your responsability to activate it! :param plugin: the :class:`IPlugin` implementation of the plugin """ # Try to get the plugin first. If it was't registered yet, # PluginError will be raised. plugin = self.get_plugin(plugin_name) if plugin_name in self.installed_plugins_names: raise PluginError("Plugin %s is already enabled." % (plugin_name, )) dependencies = self._plugin_descriptions[plugin_name].dependencies for dependency in dependencies: if not self.is_installed(dependency): self.install_plugin(store, dependency) InstalledPlugin.create(store, plugin_name) # FIXME: We should not be doing this commit here, but by not doing so, # ``` # migration = plugin.get_migration() # ``` # Would not find any plugin (as it uses the default store), to allow # `plugin.get_migration()` to accept a custom store, we would have to # change all the plugins `get_migration` method. # # An alternate solution to this would be to manually set the correct # plugin for `migration`: # # migration._plugin = store.find(InstalledPlugin, # plugin_name=plugin_name).one() # # Along with passing the store to `migration.apply_all_patches()` # # But it will be dirty and will probably be removed once the definitive # solution (change `plugin.get_migration()`) is implemented store.commit(close=False) migration = plugin.get_migration() if migration: try: migration.apply_all_patches() except SQLError as e: # This means a lock could not be obtained. Warn user about this # and let stoq restart, that the schema will be upgraded # correctly error('Não foi possível terminar a instalação do plugin. ' 'Por favor reinicie todas as instancias do Stoq que ' 'estiver executando (%s)' % (e, ))
def install_plugin(self, store, plugin_name): """Install and enable a plugin @important: Calling this makes a plugin installed, but, it's your responsability to activate it! :param plugin: the :class:`IPlugin` implementation of the plugin """ # Try to get the plugin first. If it was't registered yet, # PluginError will be raised. plugin = self.get_plugin(plugin_name) if plugin_name in self.installed_plugins_names: raise PluginError("Plugin %s is already enabled." % (plugin_name, )) dependencies = self._plugin_descriptions[plugin_name].dependencies for dependency in dependencies: if not self.is_installed(dependency): self.install_plugin(store, dependency) InstalledPlugin.create(store, plugin_name) # FIXME: We should not be doing this commit here, but by not doing so, # ``` # migration = plugin.get_migration() # ``` # Would not find any plugin (as it uses the default store), to allow # `plugin.get_migration()` to accept a custom store, we would have to # change all the plugins `get_migration` method. # # An alternate solution to this would be to manually set the correct # plugin for `migration`: # # migration._plugin = store.find(InstalledPlugin, # plugin_name=plugin_name).one() # # Along with passing the store to `migration.apply_all_patches()` # # But it will be dirty and will probably be removed once the definitive # solution (change `plugin.get_migration()`) is implemented store.commit(close=False) migration = plugin.get_migration() if migration: try: migration.apply_all_patches() except SQLError as e: # This means a lock could not be obtained. Warn user about this # and let stoq restart, that the schema will be upgraded # correctly error('Não foi possível terminar a instalação do plugin. ' 'Por favor reinicie todas as instancias do Stoq que ' 'estiver executando (%s)' % (e, ))