implement installing plugins via the webui

This commit is contained in:
Damien Churchill 2009-12-10 15:40:37 +00:00
parent 104852d47e
commit a126081d2c
4 changed files with 121 additions and 6 deletions

View File

@ -32,6 +32,80 @@ Copyright:
*/ */
Ext.namespace('Ext.deluge.preferences'); Ext.namespace('Ext.deluge.preferences');
Ext.deluge.preferences.InstallPlugin = Ext.extend(Ext.Window, {
height: 115,
width: 350,
bodyStyle: 'padding: 10px 5px;',
buttonAlign: 'center',
closeAction: 'hide',
iconCls: 'x-deluge-add-file',
layout: 'fit',
modal: true,
plain: true,
title: _('Install Plugin'),
initComponent: function() {
Ext.deluge.add.FileWindow.superclass.initComponent.call(this);
this.addButton(_('Install'), this.onInstall, this);
this.form = this.add({
xtype: 'form',
baseCls: 'x-plain',
labelWidth: 55,
autoHeight: true,
fileUpload: true,
items: [{
xtype: 'fileuploadfield',
id: 'pluginEgg',
emptyText: _('Select an egg'),
fieldLabel: _('Plugin Egg'),
name: 'file',
buttonCfg: {
text: _('Browse') + '...'
}
}]
});
},
onInstall: function(field, e) {
this.form.getForm().submit({
url: '/upload',
waitMsg: _('Uploading your plugin...'),
success: this.onUploadSuccess,
scope: this
});
},
onUploadPlugin: function(info, obj, response, request) {
this.fireEvent('pluginadded');
},
onUploadSuccess: function(fp, upload) {
this.hide();
if (upload.result.success) {
var filename = this.form.getForm().findField('pluginEgg').value;
var path = upload.result.files[0]
this.form.getForm().findField('pluginEgg').setValue('');
Deluge.Client.web.upload_plugin(filename, path, {
success: this.onUploadPlugin,
scope: this,
filename: filename
});
}
}
});
Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, { Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
constructor: function(config) { constructor: function(config) {
config = Ext.apply({ config = Ext.apply({
@ -213,6 +287,14 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
delete info; delete info;
}, },
onInstallPlugin: function() {
if (!this.installWindow) {
this.installWindow = new Ext.deluge.preferences.InstallPlugin();
this.installWindow.on('pluginadded', this.onPluginInstall, this);
}
this.installWindow.show();
},
onPluginEnabled: function(pluginName) { onPluginEnabled: function(pluginName) {
var index = this.grid.getStore().find('plugin', pluginName); var index = this.grid.getStore().find('plugin', pluginName);
var plugin = this.grid.getStore().getAt(index); var plugin = this.grid.getStore().getAt(index);
@ -227,6 +309,10 @@ Ext.deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
plugin.commit(); plugin.commit();
}, },
onPluginInstall: function() {
this.updatePlugins();
},
onPluginSelect: function(selmodel, rowIndex, r) { onPluginSelect: function(selmodel, rowIndex, r) {
Deluge.Client.web.get_plugin_info(r.get('plugin'), { Deluge.Client.web.get_plugin_info(r.get('plugin'), {
success: this.onGotPluginInfo, success: this.onGotPluginInfo,

File diff suppressed because one or more lines are too long

View File

@ -36,7 +36,7 @@
import os import os
import time import time
import base64 import base64
import urllib import shutil
import logging import logging
import hashlib import hashlib
import tempfile import tempfile
@ -829,6 +829,32 @@ class WebApi(JSONComponent):
def get_plugin_resources(self, name): def get_plugin_resources(self, name):
return component.get("Web.PluginManager").get_plugin_resources(name) return component.get("Web.PluginManager").get_plugin_resources(name)
@export
def upload_plugin(self, filename, path):
main_deferred = Deferred()
shutil.copyfile(path, os.path.join(get_config_dir(), "plugins", filename))
component.get("Web.PluginManager").scan_for_plugins()
if client.is_localhost():
client.core.rescan_plugins()
return True
plugin_data = base64.encodestring(open(path, "rb").read())
def on_upload_complete(*args):
client.core.rescan_plugins()
component.get("Web.PluginManager").scan_for_plugins()
main_deferred.callback(True)
def on_upload_error(*args):
main_deferred.callback(False)
d = client.core.upload_plugin(filename, plugin_data)
d.addCallback(on_upload_complete)
d.addErrback(on_upload_error)
return main_deferred
@export @export
def register_event_listener(self, event): def register_event_listener(self, event):
""" """

View File

@ -159,7 +159,10 @@ class Upload(resource.Resource):
if "file" not in request.args: if "file" not in request.args:
request.setResponseCode(http.OK) request.setResponseCode(http.OK)
return "" return common.json.dumps({
'success': True,
'files': []
})
tempdir = os.path.join(tempfile.gettempdir(), "delugeweb") tempdir = os.path.join(tempfile.gettempdir(), "delugeweb")
if not os.path.isdir(tempdir): if not os.path.isdir(tempdir):