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

@ -29,6 +29,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using OpenSim.Server.Base;
using OpenSim.Services.Interfaces;
using OpenSim.Framework;
@ -130,12 +131,15 @@ namespace OpenSim.Services.IntegrationService
#region console handlers
// Handle our console commands
//
// Install plugin from registered repository
private void HandleConsoleInstallPlugin(string module, string[] cmd)
{
MainConsole.Instance.Output(m_PluginManager.InstallPlugin(cmd));
return;
}
// Remove installed plugin
private void HandleConsoleUnInstallPlugin(string module, string[] cmd)
{
if (cmd.Length == 2)
@ -145,18 +149,36 @@ namespace OpenSim.Services.IntegrationService
return;
}
// Check installed plugins **not working
private void HandleConsoleCheckInstalledPlugin(string module, string[] cmd)
{
MainConsole.Instance.Output(m_PluginManager.CheckInstalled());
return;
}
// List installed plugins
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;
}
// List available plugins on registered repositories
private void HandleConsoleListAvailablePlugin(string module, string[] cmd)
{
ArrayList list = m_PluginManager.ListAvailable();
@ -166,18 +188,21 @@ namespace OpenSim.Services.IntegrationService
return;
}
// List available updates **not ready
private void HandleConsoleListUpdates(string module, string[] cmd)
{
m_PluginManager.ListUpdates();
return;
}
// Update plugin **not ready
private void HandleConsoleUpdatePlugin(string module, string[] cmd)
{
MainConsole.Instance.Output(m_PluginManager.Update());
return;
}
// Register repository
private void HandleConsoleAddRepo(string module, string[] cmd)
{
if ( cmd.Length == 3)
@ -187,12 +212,14 @@ namespace OpenSim.Services.IntegrationService
return;
}
// Get repository status **not working
private void HandleConsoleGetRepo(string module, string[] cmd)
{
m_PluginManager.GetRepository();
return;
}
// Remove registered repository
private void HandleConsoleRemoveRepo(string module, string[] cmd)
{
if (cmd.Length == 3)
@ -200,7 +227,7 @@ namespace OpenSim.Services.IntegrationService
return;
}
// Enable repo
// Enable repository
private void HandleConsoleEnableRepo(string module, string[] cmd)
{
m_PluginManager.EnableRepository(cmd);
@ -249,33 +276,6 @@ namespace OpenSim.Services.IntegrationService
}
#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
public byte[] HandleWebListRepositories (OSDMap request)
{
@ -302,9 +302,12 @@ namespace OpenSim.Services.IntegrationService
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)

View File

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

View File

@ -35,7 +35,6 @@ using Mono.Addins;
using Mono.Addins.Setup;
using Mono.Addins.Description;
using OpenSim.Framework;
using Ux = OpenSim.Services.IntegrationService.IUtils;
namespace OpenSim.Services.IntegrationService
@ -65,7 +64,7 @@ namespace OpenSim.Services.IntegrationService
AddinRepositoryEntry[] available = GetSortedAvailbleAddins();
int n = Convert.ToInt16(args[1]);
if (n > (available.Length -1))
if (n > (available.Length - 1))
{
MainConsole.Instance.Output("Selection out of range");
return "Error";
@ -78,9 +77,13 @@ namespace OpenSim.Services.IntegrationService
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);
Addin addin = m_Registry.GetAddin(aentry.Addin.Id);
m_Registry.DisableAddin(addin.Id);
addin.Enabled = false;
return "Install";
}
else
@ -116,20 +119,26 @@ namespace OpenSim.Services.IntegrationService
}
// 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;
foreach (Addin addin in addins)
{
MainConsole.Instance.OutputFormat("{0}) {1} {2} rev. {3}", count.ToString(),
addin.Enabled == false ? "[X]" : "[ ]",
addin.Name, addin.Version );
Dictionary<string, object> r = new Dictionary<string, object>();
r["enabled"] = addin.Enabled == true ? true : false;
r["name"] = addin.LocalId;
r["version"] = addin.Version;
res.Add(count.ToString(), r);
count++;
}
result = res;
return;
}
@ -158,7 +167,7 @@ namespace OpenSim.Services.IntegrationService
Repositories.UpdateAllRepositories (ps);
Console.WriteLine ("Available add-in updates:");
bool found = false;
AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates ();
AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates();
foreach (AddinRepositoryEntry entry in entries)
{