Plugin manager generic result for use by command line or rest interface

integration
BlueWall 2012-04-24 02:27:23 -04:00
parent 3c03418e06
commit 40828910e7
4 changed files with 65 additions and 48 deletions

View File

@ -81,7 +81,7 @@ namespace OpenSim.Server.Handlers.Integration
{ {
case "list_plugins": case "list_plugins":
return HandleListPlugins(request); return HandleListPlugins(request);
case "list_available": case "list_available":
return HandleListAvailablePlugins(request); return HandleListAvailablePlugins(request);
@ -96,7 +96,7 @@ namespace OpenSim.Server.Handlers.Integration
case "disable_plugin": case "disable_plugin":
return HandleDisblePlugin(request); return HandleDisblePlugin(request);
case "plugin_info": case "plugin_info":
return HandlePluginInfo(request); return HandlePluginInfo(request);
@ -114,7 +114,7 @@ namespace OpenSim.Server.Handlers.Integration
case "disable_repo": case "disable_repo":
return HandleDisableRepository(request); return HandleDisableRepository(request);
default: default:
m_log.DebugFormat( m_log.DebugFormat(
"[INTEGRATION HANDLER]: unknown method {0} request {1}", "[INTEGRATION HANDLER]: unknown method {0} request {1}",
@ -123,8 +123,8 @@ namespace OpenSim.Server.Handlers.Integration
); );
return FailureResult ("IntegrationHandler: Unrecognized method requested!"); return FailureResult ("IntegrationHandler: Unrecognized method requested!");
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.DebugFormat("[INTEGRATION HANDLER]: Exception {0}", e); m_log.DebugFormat("[INTEGRATION HANDLER]: Exception {0}", e);
} }

View File

@ -29,6 +29,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Linq;
using OpenSim.Server.Base; using OpenSim.Server.Base;
using OpenSim.Services.Interfaces; using OpenSim.Services.Interfaces;
using OpenSim.Framework; using OpenSim.Framework;
@ -130,12 +131,15 @@ namespace OpenSim.Services.IntegrationService
#region console handlers #region console handlers
// Handle our console commands // Handle our console commands
//
// Install plugin from registered repository
private void HandleConsoleInstallPlugin(string module, string[] cmd) private void HandleConsoleInstallPlugin(string module, string[] cmd)
{ {
MainConsole.Instance.Output(m_PluginManager.InstallPlugin(cmd)); MainConsole.Instance.Output(m_PluginManager.InstallPlugin(cmd));
return; return;
} }
// Remove installed plugin
private void HandleConsoleUnInstallPlugin(string module, string[] cmd) private void HandleConsoleUnInstallPlugin(string module, string[] cmd)
{ {
if (cmd.Length == 2) if (cmd.Length == 2)
@ -145,18 +149,36 @@ namespace OpenSim.Services.IntegrationService
return; return;
} }
// Check installed plugins **not working
private void HandleConsoleCheckInstalledPlugin(string module, string[] cmd) private void HandleConsoleCheckInstalledPlugin(string module, string[] cmd)
{ {
MainConsole.Instance.Output(m_PluginManager.CheckInstalled()); MainConsole.Instance.Output(m_PluginManager.CheckInstalled());
return; return;
} }
// List installed plugins
private void HandleConsoleListInstalledPlugin(string module, string[] cmd) private void HandleConsoleListInstalledPlugin(string module, string[] cmd)
{ {
m_PluginManager.ListInstalledAddins(); Dictionary<string, object> result = new Dictionary<string, object>();
m_PluginManager.ListInstalledAddins(out result);
ArrayList s = new ArrayList();
s.AddRange(result.Keys);
s.Sort();
foreach (string k in s)
{
Dictionary<string, object> plugin = (Dictionary<string, object>)result[k];
bool enabled = (bool)plugin["enabled"];
MainConsole.Instance.OutputFormat("{0}) {1} {2} rev. {3}",
k,
enabled == true ? "[ ]" : "[X]",
plugin["name"], plugin["version"]);
}
return; return;
} }
// List available plugins on registered repositories
private void HandleConsoleListAvailablePlugin(string module, string[] cmd) private void HandleConsoleListAvailablePlugin(string module, string[] cmd)
{ {
ArrayList list = m_PluginManager.ListAvailable(); ArrayList list = m_PluginManager.ListAvailable();
@ -166,18 +188,21 @@ namespace OpenSim.Services.IntegrationService
return; return;
} }
// List available updates **not ready
private void HandleConsoleListUpdates(string module, string[] cmd) private void HandleConsoleListUpdates(string module, string[] cmd)
{ {
m_PluginManager.ListUpdates(); m_PluginManager.ListUpdates();
return; return;
} }
// Update plugin **not ready
private void HandleConsoleUpdatePlugin(string module, string[] cmd) private void HandleConsoleUpdatePlugin(string module, string[] cmd)
{ {
MainConsole.Instance.Output(m_PluginManager.Update()); MainConsole.Instance.Output(m_PluginManager.Update());
return; return;
} }
// Register repository
private void HandleConsoleAddRepo(string module, string[] cmd) private void HandleConsoleAddRepo(string module, string[] cmd)
{ {
if ( cmd.Length == 3) if ( cmd.Length == 3)
@ -187,12 +212,14 @@ namespace OpenSim.Services.IntegrationService
return; return;
} }
// Get repository status **not working
private void HandleConsoleGetRepo(string module, string[] cmd) private void HandleConsoleGetRepo(string module, string[] cmd)
{ {
m_PluginManager.GetRepository(); m_PluginManager.GetRepository();
return; return;
} }
// Remove registered repository
private void HandleConsoleRemoveRepo(string module, string[] cmd) private void HandleConsoleRemoveRepo(string module, string[] cmd)
{ {
if (cmd.Length == 3) if (cmd.Length == 3)
@ -200,7 +227,7 @@ namespace OpenSim.Services.IntegrationService
return; return;
} }
// Enable repo // Enable repository
private void HandleConsoleEnableRepo(string module, string[] cmd) private void HandleConsoleEnableRepo(string module, string[] cmd)
{ {
m_PluginManager.EnableRepository(cmd); m_PluginManager.EnableRepository(cmd);
@ -249,33 +276,6 @@ namespace OpenSim.Services.IntegrationService
} }
#endregion #endregion
// #region web handlers
// public byte[] HandleWebListPlugins(OSDMap request)
// {
// return Ux.FailureResult("Not Implemented");
// }
//
// public byte[] HandleWebPluginInfo(OSDMap request)
// {
// return Ux.FailureResult("Not Implemented");
// }
//
// public byte[] HandleWebListAvailablePlugins(OSDMap request)
// {
// return Ux.FailureResult("Not Implemented");
// }
//
// public byte[] HandleWebInstallPlugin(OSDMap request)
// {
// return Ux.FailureResult("Not Implemented");
// }
//
// public byte[] HandleWebUnInstallPlugin(OSDMap request)
// {
// return Ux.FailureResult("Not Implemented");
// }
// #endregion
#region IIntegrationService implementation #region IIntegrationService implementation
public byte[] HandleWebListRepositories (OSDMap request) public byte[] HandleWebListRepositories (OSDMap request)
{ {
@ -302,9 +302,12 @@ namespace OpenSim.Services.IntegrationService
return Ux.FailureResult("Not Implemented"); return Ux.FailureResult("Not Implemented");
} }
public byte[] HandleWebListPlugins (OSDMap request) public byte[] HandleWebListPlugins(OSDMap request)
{ {
return Ux.FailureResult("Not Implemented"); Dictionary<string, object> result = new Dictionary<string, object>();
m_PluginManager.ListInstalledAddins(out result);
string json = LitJson.JsonMapper.ToJson(result);
return Ux.DocToBytes(json);
} }
public byte[] HandleWebPluginInfo (OSDMap request) public byte[] HandleWebPluginInfo (OSDMap request)

View File

@ -101,6 +101,11 @@ namespace OpenSim.Services.IntegrationService
{ {
return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(doc)); return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(doc));
} }
public static byte[] DocToBytes(string json)
{
return Encoding.UTF8.GetBytes(json);
}
#endregion web utils #endregion web utils
#region config utils #region config utils

View File

@ -35,7 +35,6 @@ using Mono.Addins;
using Mono.Addins.Setup; using Mono.Addins.Setup;
using Mono.Addins.Description; using Mono.Addins.Description;
using OpenSim.Framework; using OpenSim.Framework;
using Ux = OpenSim.Services.IntegrationService.IUtils; using Ux = OpenSim.Services.IntegrationService.IUtils;
namespace OpenSim.Services.IntegrationService namespace OpenSim.Services.IntegrationService
@ -65,12 +64,12 @@ namespace OpenSim.Services.IntegrationService
AddinRepositoryEntry[] available = GetSortedAvailbleAddins(); AddinRepositoryEntry[] available = GetSortedAvailbleAddins();
int n = Convert.ToInt16(args[1]); int n = Convert.ToInt16(args[1]);
if (n > (available.Length -1)) if (n > (available.Length - 1))
{ {
MainConsole.Instance.Output("Selection out of range"); MainConsole.Instance.Output("Selection out of range");
return "Error"; return "Error";
} }
AddinRepositoryEntry aentry = available[n]; AddinRepositoryEntry aentry = available[n];
Package p = Package.FromRepository(aentry); Package p = Package.FromRepository(aentry);
@ -78,9 +77,13 @@ namespace OpenSim.Services.IntegrationService
ResolveDependencies(ps, pack, out toUninstall, out unresolved); ResolveDependencies(ps, pack, out toUninstall, out unresolved);
if(Install(ps, pack) == true) // Attempt to install the plugin disabled
if (Install(ps, pack) == true)
{ {
m_Registry.Update(ps); m_Registry.Update(ps);
Addin addin = m_Registry.GetAddin(aentry.Addin.Id);
m_Registry.DisableAddin(addin.Id);
addin.Enabled = false;
return "Install"; return "Install";
} }
else else
@ -116,20 +119,26 @@ namespace OpenSim.Services.IntegrationService
} }
// List instaled addins // List instaled addins
public void ListInstalledAddins() public void ListInstalledAddins(out Dictionary<string, object> result)
{ {
Addin[] addins = GetSortedAddinList("IntegrationPlugin"); Dictionary<string, object> res = new Dictionary<string, object>();
MainConsole.Instance.Output("Installed Plugins"); Addin[] addins = GetSortedAddinList("IntegrationPlugin");
int count = 0; int count = 0;
foreach (Addin addin in addins) foreach (Addin addin in addins)
{ {
MainConsole.Instance.OutputFormat("{0}) {1} {2} rev. {3}", count.ToString(), Dictionary<string, object> r = new Dictionary<string, object>();
addin.Enabled == false ? "[X]" : "[ ]", r["enabled"] = addin.Enabled == true ? true : false;
addin.Name, addin.Version ); r["name"] = addin.LocalId;
r["version"] = addin.Version;
res.Add(count.ToString(), r);
count++; count++;
} }
result = res;
return; return;
} }
@ -158,7 +167,7 @@ namespace OpenSim.Services.IntegrationService
Repositories.UpdateAllRepositories (ps); Repositories.UpdateAllRepositories (ps);
Console.WriteLine ("Available add-in updates:"); Console.WriteLine ("Available add-in updates:");
bool found = false; bool found = false;
AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates (); AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates();
foreach (AddinRepositoryEntry entry in entries) foreach (AddinRepositoryEntry entry in entries)
{ {
@ -367,7 +376,7 @@ namespace OpenSim.Services.IntegrationService
} }
// These will let us deal with numbered lists instead // These will let us deal with numbered lists instead
// of needing to type in the full ids // of needing to type in the full ids
private AddinRepositoryEntry[] GetSortedAvailbleAddins() private AddinRepositoryEntry[] GetSortedAvailbleAddins()
{ {
ArrayList list = new ArrayList(); ArrayList list = new ArrayList();