Add reload and install plugin functionality to the 'plugin' command

This commit is contained in:
Asmageddon 2012-05-29 17:43:16 +02:00
parent 1df173d684
commit 1f59b4d2ba
1 changed files with 54 additions and 2 deletions

View File

@ -38,6 +38,9 @@ from deluge.ui.console.main import BaseCommand
from deluge.ui.client import client from deluge.ui.client import client
import deluge.ui.console.colors as colors import deluge.ui.console.colors as colors
import deluge.component as component import deluge.component as component
import deluge.configmanager
import re
class Command(BaseCommand): class Command(BaseCommand):
"""Manage plugins with this command""" """Manage plugins with this command"""
@ -50,11 +53,17 @@ class Command(BaseCommand):
help='enables a plugin'), help='enables a plugin'),
make_option('-d', '--disable', dest='disable', make_option('-d', '--disable', dest='disable',
help='disables a plugin'), help='disables a plugin'),
make_option('-r', '--reload', action='store_true', default=False, dest='reload',
help='reload list of available plugins'),
make_option('-i', '--install', dest='plugin_file',
help='install a plugin from an .egg file'),
) )
usage = "Usage: plugin [ -l | --list ]\n"\ usage = "Usage: plugin [ -l | --list ]\n"\
" plugin [ -s | --show ]\n"\ " plugin [ -s | --show ]\n"\
" plugin [ -e | --enable ] <plugin_name>\n"\ " plugin [ -e | --enable ] <plugin-name>\n"\
" plugin [ -d | --disable ] <plugin_name>" " plugin [ -d | --disable ] <plugin-name>\n"\
" plugin [ -i | --install ] <plugin-file>\n"\
" plugin [ -r | --reload]"
def handle(self, *args, **options): def handle(self, *args, **options):
self.console = component.get("ConsoleUI") self.console = component.get("ConsoleUI")
@ -63,6 +72,11 @@ class Command(BaseCommand):
self.console.write(self.usage) self.console.write(self.usage)
return return
if options["reload"]:
client.core.pluginmanager.rescan_plugins()
self.console.write("{!green!}Plugin list successfully reloaded")
return
if options["list"]: if options["list"]:
def on_available_plugins(result): def on_available_plugins(result):
self.console.write("{!info!}Available Plugins:") self.console.write("{!info!}Available Plugins:")
@ -104,3 +118,41 @@ class Command(BaseCommand):
client.core.disable_plugin(plugins[arg.lower()]) client.core.disable_plugin(plugins[arg.lower()])
return client.core.get_enabled_plugins().addCallback(on_enabled_plugins) return client.core.get_enabled_plugins().addCallback(on_enabled_plugins)
if options["plugin_file"]:
filepath = options["plugin_file"]
import os.path
import base64
import shutil
if not os.path.exists(filepath):
self.console.write("{!error!}Invalid path: %s" % filepath)
return
config_dir = deluge.configmanager.get_config_dir()
filename = os.path.split(filepath)[1]
shutil.copyfile(
filepath,
os.path.join(config_dir, "plugins", filename))
client.core.rescan_plugins()
if not client.is_localhost():
# We need to send this plugin to the daemon
filedump = base64.encodestring(open(filepath, "rb").read())
try:
client.core.upload_plugin(filename, filedump)
client.core.rescan_plugins()
except:
self.console.write("{!error!}An error occured, plugin was not installed")
self.console.write("{!green!}Plugin was successfully installed: %s" % filename)
def complete(self, line):
return component.get("ConsoleUI").tab_complete_path(line, ext=".egg", sort="name", dirs_first=-1)