Allow "show object", "show part", "dump object" and "delete object" to accept a local ID as well as a UUID.

This means that the sub-commands are now id rather than uuid, e.g. show object id
0.7.4-extended
Justin Clark-Casey (justincc) 2012-10-24 04:10:22 +01:00
parent 35ab31fb5f
commit 614e5b52b8
4 changed files with 153 additions and 45 deletions

View File

@ -37,6 +37,8 @@ namespace OpenSim.Framework.Console
public class ConsoleUtil public class ConsoleUtil
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public const int LocalIdNotFound = 0;
/// <summary> /// <summary>
/// Used by modules to display stock co-ordinate help, though possibly this should be under some general section /// Used by modules to display stock co-ordinate help, though possibly this should be under some general section
@ -68,19 +70,71 @@ namespace OpenSim.Framework.Console
/// Will complain to the console if parsing fails. /// Will complain to the console if parsing fails.
/// </remarks> /// </remarks>
/// <returns></returns> /// <returns></returns>
/// <param name='console'></param> /// <param name='console'>If null then no complaint is printed.</param>
/// <param name='rawUuid'></param> /// <param name='rawUuid'></param>
/// <param name='uuid'></param> /// <param name='uuid'></param>
public static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid) public static bool TryParseConsoleUuid(ICommandConsole console, string rawUuid, out UUID uuid)
{ {
if (!UUID.TryParse(rawUuid, out uuid)) if (!UUID.TryParse(rawUuid, out uuid))
{ {
console.OutputFormat("{0} is not a valid uuid", rawUuid); if (console != null)
console.OutputFormat("{0} is not a valid uuid", rawUuid);
return false; return false;
} }
return true; return true;
} }
public static bool TryParseConsoleLocalId(ICommandConsole console, string rawLocalId, out uint localId)
{
if (!uint.TryParse(rawLocalId, out localId))
{
if (console != null)
console.OutputFormat("{0} is not a valid local id", localId);
return false;
}
if (localId == 0)
{
if (console != null)
console.OutputFormat("{0} is not a valid local id - it must be greater than 0", localId);
return false;
}
return true;
}
/// <summary>
/// Tries to parse the input as either a UUID or a local ID.
/// </summary>
/// <returns>true if parsing succeeded, false otherwise.</returns>
/// <param name='console'></param>
/// <param name='rawId'></param>
/// <param name='uuid'></param>
/// <param name='localId'>
/// Will be set to ConsoleUtil.LocalIdNotFound if parsing result was a UUID or no parse succeeded.
/// </param>
public static bool TryParseConsoleId(ICommandConsole console, string rawId, out UUID uuid, out uint localId)
{
if (TryParseConsoleUuid(null, rawId, out uuid))
{
localId = LocalIdNotFound;
return true;
}
if (TryParseConsoleLocalId(null, rawId, out localId))
{
return true;
}
if (console != null)
console.OutputFormat("{0} is not a valid UUID or local id", rawId);
return false;
}
/// <summary> /// <summary>
/// Convert a minimum vector input from the console to an OpenMetaverse.Vector3 /// Convert a minimum vector input from the console to an OpenMetaverse.Vector3

View File

@ -99,9 +99,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
HandleDeleteObject); HandleDeleteObject);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", false, "delete object uuid", "Objects", false, "delete object id",
"delete object uuid <UUID>", "delete object id <UUID-or-localID>",
"Delete a scene object by uuid", "Delete a scene object by uuid or localID",
HandleDeleteObject); HandleDeleteObject);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
@ -131,12 +131,12 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", "Objects",
false, false,
"show object uuid", "show object id",
"show object uuid [--full] <UUID>", "show object id [--full] <UUID-or-localID>",
"Show details of a scene object with the given UUID", "Show details of a scene object with the given UUID or localID",
"The --full option will print out information on all the parts of the object.\n" "The --full option will print out information on all the parts of the object.\n"
+ "For yet more detailed part information, use the \"show part\" commands.", + "For yet more detailed part information, use the \"show part\" commands.",
HandleShowObjectByUuid); HandleShowObjectById);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", "Objects",
@ -163,9 +163,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", "Objects",
false, false,
"show part uuid", "show part id",
"show part uuid <UUID>", "show part id <UUID-or-localID>",
"Show details of a scene object parts with the given UUID", HandleShowPartByUuid); "Show details of a scene object part with the given UUID or localID", HandleShowPartById);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", "Objects",
@ -173,7 +173,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
"show part name", "show part name",
"show part name [--regex] <name>", "show part name [--regex] <name>",
"Show details of scene object parts with the given name.", "Show details of scene object parts with the given name.",
"If --regex is specified then the name is treatead as a regular expression", "If --regex is specified then the name is treated as a regular expression",
HandleShowPartByName); HandleShowPartByName);
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
@ -188,12 +188,13 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
m_console.Commands.AddCommand( m_console.Commands.AddCommand(
"Objects", "Objects",
false, false,
"dump object uuid", "dump object id",
"dump object uuid <UUID>", "dump object id <UUID-or-localID>",
"Dump the formatted serialization of the given object to the file <UUID>.xml", "Dump the formatted serialization of the given object to the file <UUID>.xml",
"e.g. dump object uuid c1ed6809-cc24-4061-a4c2-93082a2d1f1d will dump serialization to c1ed6809-cc24-4061-a4c2-93082a2d1f1d.xml\n" "e.g. dump object uuid c1ed6809-cc24-4061-a4c2-93082a2d1f1d will dump serialization to c1ed6809-cc24-4061-a4c2-93082a2d1f1d.xml\n"
+ "To locate the UUID in the first place, you need to use the other show object commands", + "To locate the UUID or localID in the first place, you need to use the other show object commands.\n"
HandleDumpObjectByUuid); + "If a local ID is given then the filename used is still that for the UUID",
HandleDumpObjectById);
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -248,7 +249,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
m_console.OutputFormat(sb.ToString()); m_console.OutputFormat(sb.ToString());
} }
private void HandleShowObjectByUuid(string module, string[] cmdparams) private void HandleShowObjectById(string module, string[] cmdparams)
{ {
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return; return;
@ -264,14 +265,17 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
return; return;
} }
UUID objectUuid; UUID uuid;
if (!UUID.TryParse(mainParams[3], out objectUuid)) uint localId;
{ if (!ConsoleUtil.TryParseConsoleId(m_console, mainParams[3], out uuid, out localId))
m_console.OutputFormat("{0} is not a valid uuid", mainParams[3]);
return; return;
}
SceneObjectGroup so = m_scene.GetSceneObjectGroup(objectUuid); SceneObjectGroup so;
if (localId != ConsoleUtil.LocalIdNotFound)
so = m_scene.GetSceneObjectGroup(localId);
else
so = m_scene.GetSceneObjectGroup(uuid);
if (so == null) if (so == null)
{ {
@ -348,7 +352,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
OutputSogsToConsole(searchPredicate, showFull); OutputSogsToConsole(searchPredicate, showFull);
} }
private void HandleShowPartByUuid(string module, string[] cmdparams) private void HandleShowPartById(string module, string[] cmdparams)
{ {
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return; return;
@ -361,18 +365,20 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
if (mainParams.Count < 4) if (mainParams.Count < 4)
{ {
m_console.OutputFormat("Usage: show part uuid [--full] <uuid>"); m_console.OutputFormat("Usage: show part id [--full] <UUID-or-localID>");
return; return;
} }
UUID objectUuid; UUID objectUuid;
if (!UUID.TryParse(mainParams[3], out objectUuid)) uint localId;
{ if (!ConsoleUtil.TryParseConsoleId(m_console, mainParams[3], out objectUuid, out localId))
m_console.OutputFormat("{0} is not a valid uuid", mainParams[3]);
return; return;
}
SceneObjectPart sop = m_scene.GetSceneObjectPart(objectUuid); SceneObjectPart sop;
if (localId == ConsoleUtil.LocalIdNotFound)
sop = m_scene.GetSceneObjectPart(objectUuid);
else
sop = m_scene.GetSceneObjectPart(localId);
if (sop == null) if (sop == null)
{ {
@ -460,22 +466,27 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
OutputSopsToConsole(searchPredicate, true); OutputSopsToConsole(searchPredicate, true);
} }
private void HandleDumpObjectByUuid(string module, string[] cmdparams) private void HandleDumpObjectById(string module, string[] cmdparams)
{ {
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene)) if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
return; return;
if (cmdparams.Length < 4) if (cmdparams.Length < 4)
{ {
m_console.OutputFormat("Usage: dump object uuid <uuid>"); m_console.OutputFormat("Usage: dump object id <UUID-or-localID>");
return; return;
} }
UUID objectUuid; UUID objectUuid;
if (!ConsoleUtil.TryParseConsoleUuid(m_console, cmdparams[3], out objectUuid)) uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, cmdparams[3], out objectUuid, out localId))
return; return;
SceneObjectGroup so = m_scene.GetSceneObjectGroup(objectUuid); SceneObjectGroup so;
if (localId == ConsoleUtil.LocalIdNotFound)
so = m_scene.GetSceneObjectGroup(objectUuid);
else
so = m_scene.GetSceneObjectGroup(localId);
if (so == null) if (so == null)
{ {
@ -483,6 +494,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
return; return;
} }
// In case we found it via local ID.
objectUuid = so.UUID;
string fileName = string.Format("{0}.xml", objectUuid); string fileName = string.Format("{0}.xml", objectUuid);
if (File.Exists(fileName)) if (File.Exists(fileName))
@ -664,19 +678,24 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
break; break;
case "uuid": case "id":
if (!UUID.TryParse(o, out match)) UUID uuid;
uint localId;
if (!ConsoleUtil.TryParseConsoleId(m_console, o, out uuid, out localId))
return; return;
requireConfirmation = false; requireConfirmation = false;
deletes = new List<SceneObjectGroup>(); deletes = new List<SceneObjectGroup>();
m_scene.ForEachSOG(delegate (SceneObjectGroup g) SceneObjectGroup so;
{ if (localId == ConsoleUtil.LocalIdNotFound)
if (g.UUID == match && !g.IsAttachment) so = m_scene.GetSceneObjectGroup(uuid);
deletes.Add(g); else
}); so = m_scene.GetSceneObjectGroup(localId);
if (!so.IsAttachment)
deletes.Add(so);
// if (deletes.Count == 0) // if (deletes.Count == 0)
// m_console.OutputFormat("No objects were found with uuid {0}", match); // m_console.OutputFormat("No objects were found with uuid {0}", match);

View File

@ -4627,12 +4627,23 @@ namespace OpenSim.Region.Framework.Scenes
/// Get a group via its UUID /// Get a group via its UUID
/// </summary> /// </summary>
/// <param name="fullID"></param> /// <param name="fullID"></param>
/// <returns>null if no group with that name exists</returns> /// <returns>null if no group with that id exists</returns>
public SceneObjectGroup GetSceneObjectGroup(UUID fullID) public SceneObjectGroup GetSceneObjectGroup(UUID fullID)
{ {
return m_sceneGraph.GetSceneObjectGroup(fullID); return m_sceneGraph.GetSceneObjectGroup(fullID);
} }
/// <summary>
/// Get a group via its local ID
/// </summary>
/// <remarks>This will only return a group if the local ID matches a root part</remarks>
/// <param name="localID"></param>
/// <returns>null if no group with that id exists</returns>
public SceneObjectGroup GetSceneObjectGroup(uint localID)
{
return m_sceneGraph.GetSceneObjectGroup(localID);
}
/// <summary> /// <summary>
/// Get a group by name from the scene (will return the first /// Get a group by name from the scene (will return the first
/// found, if there are more than one prim with the same name) /// found, if there are more than one prim with the same name)

View File

@ -985,6 +985,30 @@ namespace OpenSim.Region.Framework.Scenes
return null; return null;
} }
/// <summary>
/// Get a group in the scene
/// </summary>
/// <remarks>
/// This will only return a group if the local ID matches the root part, not other parts.
/// </remarks>
/// <param name="localID">Local id of the root part of the group</param>
/// <returns>null if no such group was found</returns>
protected internal SceneObjectGroup GetSceneObjectGroup(uint localID)
{
lock (SceneObjectGroupsByLocalPartID)
{
if (SceneObjectGroupsByLocalPartID.ContainsKey(localID))
{
SceneObjectGroup so = SceneObjectGroupsByLocalPartID[localID];
if (so.LocalId == localID)
return so;
}
}
return null;
}
/// <summary> /// <summary>
/// Get a group by name from the scene (will return the first /// Get a group by name from the scene (will return the first
/// found, if there are more than one prim with the same name) /// found, if there are more than one prim with the same name)