From 40828910e7892c7f7a875b2cdca019c8e1d22f5c Mon Sep 17 00:00:00 2001 From: BlueWall Date: Tue, 24 Apr 2012 02:27:23 -0400 Subject: [PATCH] Plugin manager generic result for use by command line or rest interface --- .../Integration/IntegrationServerHandler.cs | 10 +-- .../IntegrationService/IntegrationService.cs | 65 ++++++++++--------- .../IntegrationService/IntegrationUtils.cs | 5 ++ .../IntegrationService/PluginManager.cs | 33 ++++++---- 4 files changed, 65 insertions(+), 48 deletions(-) diff --git a/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs b/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs index 45dcad7115..320b5030c6 100644 --- a/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs +++ b/OpenSim/Server/Handlers/Integration/IntegrationServerHandler.cs @@ -81,7 +81,7 @@ namespace OpenSim.Server.Handlers.Integration { case "list_plugins": return HandleListPlugins(request); - + case "list_available": return HandleListAvailablePlugins(request); @@ -96,7 +96,7 @@ namespace OpenSim.Server.Handlers.Integration case "disable_plugin": return HandleDisblePlugin(request); - + case "plugin_info": return HandlePluginInfo(request); @@ -114,7 +114,7 @@ namespace OpenSim.Server.Handlers.Integration case "disable_repo": return HandleDisableRepository(request); - + default: m_log.DebugFormat( "[INTEGRATION HANDLER]: unknown method {0} request {1}", @@ -123,8 +123,8 @@ namespace OpenSim.Server.Handlers.Integration ); return FailureResult ("IntegrationHandler: Unrecognized method requested!"); } - } - catch (Exception e) + } + catch (Exception e) { m_log.DebugFormat("[INTEGRATION HANDLER]: Exception {0}", e); } diff --git a/OpenSim/Services/IntegrationService/IntegrationService.cs b/OpenSim/Services/IntegrationService/IntegrationService.cs index e3e23cf7d9..97286595c5 100644 --- a/OpenSim/Services/IntegrationService/IntegrationService.cs +++ b/OpenSim/Services/IntegrationService/IntegrationService.cs @@ -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 result = new Dictionary(); + m_PluginManager.ListInstalledAddins(out result); + + ArrayList s = new ArrayList(); + s.AddRange(result.Keys); + s.Sort(); + + foreach (string k in s) + { + Dictionary plugin = (Dictionary)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 result = new Dictionary(); + m_PluginManager.ListInstalledAddins(out result); + string json = LitJson.JsonMapper.ToJson(result); + return Ux.DocToBytes(json); } public byte[] HandleWebPluginInfo (OSDMap request) diff --git a/OpenSim/Services/IntegrationService/IntegrationUtils.cs b/OpenSim/Services/IntegrationService/IntegrationUtils.cs index 32f2cf2ee5..1b0ce33d1d 100644 --- a/OpenSim/Services/IntegrationService/IntegrationUtils.cs +++ b/OpenSim/Services/IntegrationService/IntegrationUtils.cs @@ -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 diff --git a/OpenSim/Services/IntegrationService/PluginManager.cs b/OpenSim/Services/IntegrationService/PluginManager.cs index 9a10180a67..4b18ea514a 100644 --- a/OpenSim/Services/IntegrationService/PluginManager.cs +++ b/OpenSim/Services/IntegrationService/PluginManager.cs @@ -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,12 +64,12 @@ 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"; } - + AddinRepositoryEntry aentry = available[n]; Package p = Package.FromRepository(aentry); @@ -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 result) { - Addin[] addins = GetSortedAddinList("IntegrationPlugin"); + Dictionary res = new Dictionary(); - 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 r = new Dictionary(); + 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) { @@ -367,7 +376,7 @@ namespace OpenSim.Services.IntegrationService } // 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() { ArrayList list = new ArrayList();