plugin installation handles dependencies

This commit is contained in:
Kevin Dangoor 2010-03-30 15:55:34 -04:00
Родитель 1744ca11a0
Коммит 2dcce432bf
2 изменённых файлов: 63 добавлений и 12 удалений

Просмотреть файл

@ -285,10 +285,25 @@ def save_to_gallery(user, location):
plugin.version = metadata['version']
plugin.package_info = metadata
def install_plugin_from_gallery(user, plugin_name):
plugin = GalleryPlugin.get_plugin(plugin_name)
if not plugin:
raise PluginError('Cannot find plugin "%s" in the gallery' % (plugin_name))
def _collect_dependencies(main_plugin):
result = dict()
def add_deps(plugin):
deps = plugin.package_info.get("dependencies")
if not deps:
return
for dep in deps:
if dep in result:
continue
dep_plugin = GalleryPlugin.get_plugin(dep)
if not dep_plugin:
raise PluginError("Cannot find dependency '%s' for plugin '%s'"
% (dep, plugin.name))
result[dep] = dep_plugin
add_deps(dep_plugin)
add_deps(main_plugin)
return result
def _perform_installation(user, plugin):
version = plugin.version
gallery_root = config.c.gallery_root
plugin_dir = gallery_root / plugin.name
@ -308,7 +323,20 @@ def install_plugin_from_gallery(user, plugin_name):
destination.rmtree()
location.copytree(destination)
else:
destination = project.location / "plugins" / location.basename()
destination = project.location / "plugins" / (plugin.name + ".js")
if destination.exists():
destination.unlink()
location.copy(destination)
def install_plugin_from_gallery(user, plugin_name):
plugin = GalleryPlugin.get_plugin(plugin_name)
if not plugin:
raise PluginError('Cannot find plugin "%s" in the gallery' % (plugin_name))
deps = _collect_dependencies(plugin)
_perform_installation(user, plugin)
for dep in deps.values():
_perform_installation(user, dep)

Просмотреть файл

@ -385,6 +385,31 @@ def test_save_single_file_plugin_to_gallery():
version_file = sfp3_dir / "2.3.2.js"
assert version_file.exists()
assert not version_file.isdir()
def test_install_plugin_with_dependencies():
_init_data()
plugins.save_to_gallery(macgyver, plugindir / "plugin1")
try:
plugins.install_plugin_from_gallery(macgyver, "plugin1")
assert False, "Expected exception because of non-existent dependency"
except PluginError:
pass
def test_install_plugin_with_dependencies():
_init_data()
plugins.save_to_gallery(macgyver, plugindir / "plugin1")
plugins.save_to_gallery(macgyver, plugindir / "plugin2")
plugins.install_plugin_from_gallery(macgyver, "plugin1")
project = get_project(macgyver, macgyver, "BespinSettings")
plugin1_dir = project.location / "plugins/plugin1"
assert plugin1_dir.exists()
assert plugin1_dir.isdir()
plugin2_dir = project.location / "plugins/plugin2"
assert plugin2_dir.exists()
assert plugin2_dir.isdir()
# WEB TESTS
@ -441,7 +466,6 @@ def test_plugin_upload_wont_work_for_someone_elses_plugin():
def test_plugin_gallery_list():
_init_data()
gallery_root = config.c.gallery_root
plugins.save_to_gallery(macgyver, plugindir / "plugin1")
response = app.get("/plugin/gallery/")
@ -451,14 +475,13 @@ def test_plugin_gallery_list():
def test_plugin_install_from_gallery():
_init_data()
gallery_root = config.c.gallery_root
plugins.save_to_gallery(macgyver, plugindir / "plugin1")
plugins.save_to_gallery(macgyver, plugindir / "singlefileplugin3.js")
response = app.post("/plugin/install/plugin1")
response = app.post("/plugin/install/singlefileplugin3")
assert response.body == "OK"
project = get_project(macgyver, macgyver, "BespinSettings")
plugin1_dir = project.location / "plugins/plugin1"
assert plugin1_dir.exists()
assert plugin1_dir.isdir()
sfp3_dir = project.location / "plugins/singlefileplugin3.js"
assert sfp3_dir.exists()
assert not sfp3_dir.isdir()