* Formatted ExportSerialiserModule and SvnBackupModule

* Added a form of GZip compression support to object.xml files produced by exportserialiser. Will look towards standard GZip support. File compression seems to be highly worthwhile reducing a 1.5mb sim state to 62kb.
0.6.0-stable
Adam Frisby 2008-04-21 09:12:47 +00:00
parent a7cb2b8c30
commit f741a62d54
7 changed files with 184 additions and 163 deletions

View File

@ -37,10 +37,54 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
public class ExportSerialisationModule : IRegionModule, IRegionSerialiser public class ExportSerialisationModule : IRegionModule, IRegionSerialiser
{ {
private List<Scene> m_regions = new List<Scene>();
private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
private Commander m_commander = new Commander("Export"); private Commander m_commander = new Commander("Export");
private List<Scene> m_regions = new List<Scene>();
private string m_savedir = "exports" + "/"; private string m_savedir = "exports" + "/";
private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>();
#region IRegionModule Members
public void Initialise(Scene scene, IConfigSource source)
{
scene.RegisterModuleCommander("Export", m_commander);
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
scene.RegisterModuleInterface<IRegionSerialiser>(this);
lock (m_regions)
{
m_regions.Add(scene);
}
}
public void PostInitialise()
{
lock (m_serialisers)
{
m_serialisers.Add(new SerialiseTerrain());
m_serialisers.Add(new SerialiseObjects());
}
LoadCommanderCommands();
}
public void Close()
{
m_regions.Clear();
}
public string Name
{
get { return "ExportSerialisationModule"; }
}
public bool IsSharedModule
{
get { return true; }
}
#endregion
#region IRegionSerialiser Members
public List<string> SerialiseRegion(Scene scene, string saveDir) public List<string> SerialiseRegion(Scene scene, string saveDir)
{ {
@ -76,22 +120,9 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
return results; return results;
} }
#endregion
#region IRegionModule Members private void EventManager_OnPluginConsole(string[] args)
public void Initialise(Scene scene, IConfigSource source)
{
scene.RegisterModuleCommander("Export", m_commander);
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
scene.RegisterModuleInterface<IRegionSerialiser>(this);
lock (m_regions)
{
m_regions.Add(scene);
}
}
void EventManager_OnPluginConsole(string[] args)
{ {
if (args[0] == "export") if (args[0] == "export")
{ {
@ -108,7 +139,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
foreach (Scene region in m_regions) foreach (Scene region in m_regions)
{ {
if (region.RegionInfo.RegionName == (string)args[0]) if (region.RegionInfo.RegionName == (string) args[0])
{ {
List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/"); List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/");
} }
@ -133,33 +164,5 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
m_commander.RegisterCommand("save", serialiseSceneCommand); m_commander.RegisterCommand("save", serialiseSceneCommand);
m_commander.RegisterCommand("save-all", serialiseAllScenesCommand); m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
} }
public void PostInitialise()
{
lock (m_serialisers)
{
m_serialisers.Add(new SerialiseTerrain());
m_serialisers.Add(new SerialiseObjects());
}
LoadCommanderCommands();
}
public void Close()
{
m_regions.Clear();
}
public string Name
{
get { return "ExportSerialisationModule"; }
}
public bool IsSharedModule
{
get { return true; }
}
#endregion
} }
} }

View File

@ -29,8 +29,8 @@ using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules.ExportSerialiser namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
interface IFileSerialiser internal interface IFileSerialiser
{ {
string WriteToFile(Scene scene, string dir); string WriteToFile(Scene scene, string dir);
} }
} }

View File

@ -34,4 +34,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
List<string> SerialiseRegion(Scene scene, string saveDir); List<string> SerialiseRegion(Scene scene, string saveDir);
} }
} }

View File

@ -27,20 +27,30 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules.ExportSerialiser namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
class SerialiseObjects : IFileSerialiser internal class SerialiseObjects : IFileSerialiser
{ {
#region IFileSerialiser Members #region IFileSerialiser Members
public string WriteToFile(Scene scene, string dir)
{
string targetFileName = dir + "objects.xml";
SaveSerialisedToFile(targetFileName, scene);
return "objects.xml";
}
#endregion
public void SaveSerialisedToFile(string fileName, Scene scene) public void SaveSerialisedToFile(string fileName, Scene scene)
{ {
int primCount = 0;
string xmlstream = "<scene>"; string xmlstream = "<scene>";
List<EntityBase> EntityList = scene.GetEntities(); List<EntityBase> EntityList = scene.GetEntities();
@ -50,8 +60,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
EntityXml.Add(((SceneObjectGroup)ent).ToXmlString2()); EntityXml.Add(((SceneObjectGroup) ent).ToXmlString2());
primCount++;
} }
} }
EntityXml.Sort(); EntityXml.Sort();
@ -69,26 +78,24 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
formatter.Formatting = Formatting.Indented; formatter.Formatting = Formatting.Indented;
doc.WriteContentTo(formatter); doc.WriteContentTo(formatter);
formatter.Flush(); formatter.Flush();
StreamReader reader = new StreamReader(stream);
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
FileStream objectsFile = new FileStream(fileName, FileMode.Create); FileStream objectsFile = new FileStream(fileName, FileMode.Create);
stream.WriteTo(objectsFile); stream.WriteTo(objectsFile);
objectsFile.Flush(); objectsFile.Flush();
objectsFile.Close(); objectsFile.Close();
#region GZip Compressed Version
FileStream objectsFileCompressed = new FileStream(fileName + ".gzs", FileMode.Create);
MemoryStream gzipMSStream = new MemoryStream();
GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
stream.WriteTo(gzipStream);
gzipMSStream.WriteTo(objectsFileCompressed);
objectsFileCompressed.Flush();
objectsFileCompressed.Close();
#endregion
} }
public string WriteToFile(Scene scene, string dir)
{
string targetFileName = dir + "objects.xml";
SaveSerialisedToFile(targetFileName, scene);
return "objects.xml";
}
#endregion
} }
} }

View File

@ -31,7 +31,7 @@ using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Region.Environment.Modules.ExportSerialiser namespace OpenSim.Region.Environment.Modules.ExportSerialiser
{ {
class SerialiseTerrain : IFileSerialiser internal class SerialiseTerrain : IFileSerialiser
{ {
#region IFileSerialiser Members #region IFileSerialiser Members
@ -50,4 +50,4 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser
#endregion #endregion
} }
} }

View File

@ -42,11 +42,11 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
public class Command : ICommand public class Command : ICommand
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private List<CommandArgument> m_args = new List<CommandArgument>();
private Action<object[]> m_command; private Action<object[]> m_command;
private string m_name;
private string m_help; private string m_help;
private List<CommandArgument> m_args = new List<CommandArgument>(); private string m_name;
public Command(string name, Action<Object[]> command, string help) public Command(string name, Action<Object[]> command, string help)
{ {
@ -55,6 +55,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
m_help = help; m_help = help;
} }
#region ICommand Members
public void AddArgument(string name, string helptext, string type) public void AddArgument(string name, string helptext, string type)
{ {
m_args.Add(new CommandArgument(name, helptext, type)); m_args.Add(new CommandArgument(name, helptext, type));
@ -143,8 +145,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
catch (FormatException) catch (FormatException)
{ {
m_log.Error("Argument number " + (i + 1) + m_log.Error("Argument number " + (i + 1) +
" (" + m_args[i].Name + ") must be a valid " + " (" + m_args[i].Name + ") must be a valid " +
m_args[i].ArgumentType.ToLower() + "."); m_args[i].ArgumentType.ToLower() + ".");
} }
cleanArgs[i] = m_args[i].ArgumentValue; cleanArgs[i] = m_args[i].ArgumentValue;
@ -153,6 +155,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
m_command.Invoke(cleanArgs); m_command.Invoke(cleanArgs);
} }
#endregion
} }
/// <summary> /// <summary>
@ -160,8 +164,8 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
/// </summary> /// </summary>
public class CommandArgument public class CommandArgument
{ {
private string m_name;
private string m_help; private string m_help;
private string m_name;
private string m_type; private string m_type;
private Object m_val; private Object m_val;
@ -208,29 +212,13 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
m_name = name; m_name = name;
} }
#region ICommander Members
public void RegisterCommand(string commandName, ICommand command) public void RegisterCommand(string commandName, ICommand command)
{ {
m_commands[commandName] = command; m_commands[commandName] = command;
} }
void ShowConsoleHelp()
{
m_log.Info("===" + m_name + "===");
foreach (ICommand com in m_commands.Values)
{
m_log.Info("* " + com.Name + " - " + com.Help);
}
}
string EscapeRuntimeAPICommand(string command)
{
command = command.Replace('-', '_');
StringBuilder tmp = new StringBuilder(command);
tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
return tmp.ToString();
}
/// <summary> /// <summary>
/// Generates a runtime C# class which can be compiled and inserted via reflection to enable modules to register new script commands /// Generates a runtime C# class which can be compiled and inserted via reflection to enable modules to register new script commands
/// </summary> /// </summary>
@ -253,7 +241,7 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
{ {
classSrc += "\t\targs[" + i.ToString() + "] = " + Util.Md5Hash(arg.Key) + " " + ";\n"; classSrc += "\t\targs[" + i.ToString() + "] = " + Util.Md5Hash(arg.Key) + " " + ";\n";
i++; i++;
} }
classSrc += "\t\tGetCommander(\"" + m_name + "\").Run(\"" + com.Name + "\", args);\n"; classSrc += "\t\tGetCommander(\"" + m_name + "\").Run(\"" + com.Name + "\", args);\n";
classSrc += "\t}\n"; classSrc += "\t}\n";
} }
@ -296,5 +284,25 @@ namespace OpenSim.Region.Environment.Modules.ModuleFramework
ShowConsoleHelp(); ShowConsoleHelp();
} }
} }
#endregion
private void ShowConsoleHelp()
{
m_log.Info("===" + m_name + "===");
foreach (ICommand com in m_commands.Values)
{
m_log.Info("* " + com.Name + " - " + com.Help);
}
}
private string EscapeRuntimeAPICommand(string command)
{
command = command.Replace('-', '_');
StringBuilder tmp = new StringBuilder(command);
tmp[0] = tmp[0].ToString().ToUpper().ToCharArray()[0];
return tmp.ToString();
}
} }
} }

View File

@ -18,22 +18,21 @@ namespace OpenSim.Region.Modules.SvnSerialiser
public class SvnBackupModule : IRegionModule public class SvnBackupModule : IRegionModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private SvnClient m_svnClient;
private bool m_enabled = false; private bool m_enabled = false;
private bool m_installBackupOnLoad = false; private bool m_installBackupOnLoad = false;
private string m_svnurl = "svn://insert.your.svn/here/"; private List<Scene> m_scenes = new List<Scene>();
private string m_svnuser = "username"; private IRegionSerialiser m_serialiser;
private string m_svnpass = "password"; private bool m_svnAutoSave = false;
private SvnClient m_svnClient;
private string m_svndir = "SVNmodule\\repo"; private string m_svndir = "SVNmodule\\repo";
private string m_svnpass = "password";
private TimeSpan m_svnperiod = new TimeSpan(0, 0, 15, 0, 0); private TimeSpan m_svnperiod = new TimeSpan(0, 0, 15, 0, 0);
private bool m_svnAutoSave = false; private string m_svnurl = "svn://insert.your.svn/here/";
private string m_svnuser = "username";
private Timer m_timer = new Timer(); private Timer m_timer = new Timer();
private IRegionSerialiser m_serialiser;
private List<Scene> m_scenes = new List<Scene>();
#region SvnModule Core #region SvnModule Core
/// <summary> /// <summary>
@ -76,7 +75,9 @@ namespace OpenSim.Region.Modules.SvnSerialiser
{ {
m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString(), true, false, false); m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString(), true, false, false);
} }
catch (SvnException) { } catch (SvnException)
{
}
List<string> svnfilenames = new List<string>(); List<string> svnfilenames = new List<string>();
foreach (string filename in filenames) foreach (string filename in filenames)
@ -88,10 +89,10 @@ namespace OpenSim.Region.Modules.SvnSerialiser
public void LoadRegion(Scene scene) public void LoadRegion(Scene scene)
{ {
scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() + scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
Slash.DirectorySeparatorChar + "objects.xml"); Slash.DirectorySeparatorChar + "objects.xml");
scene.RequestModuleInterface<ITerrainModule>().LoadFromFile(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() + scene.RequestModuleInterface<ITerrainModule>().LoadFromFile(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
Slash.DirectorySeparatorChar + "heightmap.r32"); Slash.DirectorySeparatorChar + "heightmap.r32");
m_log.Info("[SVNBACKUP]: Region load successful (" + scene.RegionInfo.RegionName + ")."); m_log.Info("[SVNBACKUP]: Region load successful (" + scene.RegionInfo.RegionName + ").");
} }
@ -126,7 +127,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
#region SvnDotNet Callbacks #region SvnDotNet Callbacks
private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton, private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton,
AprString realm, AprString username, bool maySave, AprPool pool) AprString realm, AprString username, bool maySave, AprPool pool)
{ {
svnCredentials = SvnAuthCredSimple.Alloc(pool); svnCredentials = SvnAuthCredSimple.Alloc(pool);
svnCredentials.Username = new AprString(m_svnuser, pool); svnCredentials.Username = new AprString(m_svnuser, pool);
@ -140,7 +141,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
if (!commitItems.IsNull) if (!commitItems.IsNull)
{ {
foreach (SvnClientCommitItem2 item in commitItems) foreach (SvnClientCommitItem2 item in commitItems)
{ {
m_log.Debug("[SVNBACKUP]: ... " + Path.GetFileName(item.Path.ToString()) + " (" + item.Kind.ToString() + ") r" + item.Revision.ToString()); m_log.Debug("[SVNBACKUP]: ... " + Path.GetFileName(item.Path.ToString()) + " (" + item.Kind.ToString() + ") r" + item.Revision.ToString());
} }
} }
@ -174,8 +175,11 @@ namespace OpenSim.Region.Modules.SvnSerialiser
m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass); m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass);
m_installBackupOnLoad = source.Configs["SVN"].GetBoolean("ImportOnStartup", m_installBackupOnLoad); m_installBackupOnLoad = source.Configs["SVN"].GetBoolean("ImportOnStartup", m_installBackupOnLoad);
m_svnAutoSave = source.Configs["SVN"].GetBoolean("Autosave", m_svnAutoSave); m_svnAutoSave = source.Configs["SVN"].GetBoolean("Autosave", m_svnAutoSave);
m_svnperiod = new TimeSpan(0, source.Configs["SVN"].GetInt("AutosavePeriod", (int)m_svnperiod.TotalMinutes), 0); m_svnperiod = new TimeSpan(0, source.Configs["SVN"].GetInt("AutosavePeriod", (int) m_svnperiod.TotalMinutes), 0);
} catch(Exception) { } }
catch (Exception)
{
}
lock (m_scenes) lock (m_scenes)
{ {
@ -185,7 +189,54 @@ namespace OpenSim.Region.Modules.SvnSerialiser
scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
} }
void EventManager_OnPluginConsole(string[] args) public void PostInitialise()
{
if (m_enabled == false)
return;
if (m_svnAutoSave == true)
{
m_timer.Interval = m_svnperiod.TotalMilliseconds;
m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
m_timer.AutoReset = true;
m_timer.Start();
}
m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
SetupSvnProvider();
m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
CreateSvnDirectory();
CheckoutSvn();
SetupSerialiser();
if (m_installBackupOnLoad)
{
m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
foreach (Scene scene in m_scenes)
{
LoadRegion(scene);
}
}
}
public void Close()
{
}
public string Name
{
get { return "SvnBackupModule"; }
}
public bool IsSharedModule
{
get { return true; }
}
#endregion
private void EventManager_OnPluginConsole(string[] args)
{ {
if (args[0] == "svn" && args[1] == "save") if (args[0] == "svn" && args[1] == "save")
{ {
@ -272,38 +323,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
} }
} }
public void PostInitialise() private void m_timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (m_enabled == false)
return;
if (m_svnAutoSave == true)
{
m_timer.Interval = m_svnperiod.TotalMilliseconds;
m_timer.Elapsed += new ElapsedEventHandler(m_timer_Elapsed);
m_timer.AutoReset = true;
m_timer.Start();
}
m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
SetupSvnProvider();
m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
CreateSvnDirectory();
CheckoutSvn();
SetupSerialiser();
if (m_installBackupOnLoad)
{
m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
foreach (Scene scene in m_scenes)
{
LoadRegion(scene);
}
}
}
void m_timer_Elapsed(object sender, ElapsedEventArgs e)
{ {
SaveAllRegions(); SaveAllRegions();
} }
@ -320,7 +340,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
m_svnClient.AddUsernameProvider(); m_svnClient.AddUsernameProvider();
m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2); m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2);
m_svnClient.OpenAuth(); m_svnClient.OpenAuth();
m_svnClient.Context.LogMsgFunc2 = new SvnDelegate(new SvnClient.GetCommitLog2(GetCommitLogCallback)); m_svnClient.Context.LogMsgFunc2 = new SvnDelegate(new SvnClient.GetCommitLog2(GetCommitLogCallback));
} }
private void CreateSvnDirectory() private void CreateSvnDirectory()
@ -328,22 +348,5 @@ namespace OpenSim.Region.Modules.SvnSerialiser
if (!Directory.Exists(m_svndir)) if (!Directory.Exists(m_svndir))
Directory.CreateDirectory(m_svndir); Directory.CreateDirectory(m_svndir);
} }
public void Close()
{
}
public string Name
{
get { return "SvnBackupModule"; }
}
public bool IsSharedModule
{
get { return true; }
}
#endregion
} }
} }