* 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")
{ {
@ -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,7 +29,7 @@ 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

@ -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();
@ -51,7 +61,6 @@ 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);
public string WriteToFile(Scene scene, string dir) MemoryStream gzipMSStream = new MemoryStream();
{ GZipStream gzipStream = new GZipStream(gzipMSStream, CompressionMode.Compress);
string targetFileName = dir + "objects.xml"; stream.WriteTo(gzipStream);
gzipMSStream.WriteTo(objectsFileCompressed);
SaveSerialisedToFile(targetFileName, scene); objectsFileCompressed.Flush();
objectsFileCompressed.Close();
return "objects.xml";
}
#endregion #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

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));
@ -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>
@ -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

@ -19,21 +19,20 @@ namespace OpenSim.Region.Modules.SvnSerialiser
{ {
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)
@ -175,7 +176,10 @@ namespace OpenSim.Region.Modules.SvnSerialiser
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();
} }
@ -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
} }
} }