aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Modules/SvnSerialiser
diff options
context:
space:
mode:
authorDr Scofield2009-02-10 13:10:57 +0000
committerDr Scofield2009-02-10 13:10:57 +0000
commit180be7de07014aa33bc6066f12a0819b731c1c9d (patch)
tree3aa13af3cda4b808fa9453655875327699b61311 /OpenSim/Region/Modules/SvnSerialiser
parentStopgap measure: To use gridlaunch, or GUI, start opensim with (diff)
downloadopensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.zip
opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.gz
opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.bz2
opensim-SC_OLD-180be7de07014aa33bc6066f12a0819b731c1c9d.tar.xz
this is step 2 of 2 of the OpenSim.Region.Environment refactor.
NOTHING has been deleted or moved off to forge at this point. what has happened is that OpenSim.Region.Environment.Modules has been split in two: - OpenSim.Region.CoreModules: all those modules that are either directly or indirectly referenced from other OpenSim packages, or that provide functionality that the OpenSim developer community considers core functionality: CoreModules/Agent/AssetTransaction CoreModules/Agent/Capabilities CoreModules/Agent/TextureDownload CoreModules/Agent/TextureSender CoreModules/Agent/TextureSender/Tests CoreModules/Agent/Xfer CoreModules/Avatar/AvatarFactory CoreModules/Avatar/Chat/ChatModule CoreModules/Avatar/Combat CoreModules/Avatar/Currency/SampleMoney CoreModules/Avatar/Dialog CoreModules/Avatar/Friends CoreModules/Avatar/Gestures CoreModules/Avatar/Groups CoreModules/Avatar/InstantMessage CoreModules/Avatar/Inventory CoreModules/Avatar/Inventory/Archiver CoreModules/Avatar/Inventory/Transfer CoreModules/Avatar/Lure CoreModules/Avatar/ObjectCaps CoreModules/Avatar/Profiles CoreModules/Communications/Local CoreModules/Communications/REST CoreModules/Framework/EventQueue CoreModules/Framework/InterfaceCommander CoreModules/Hypergrid CoreModules/InterGrid CoreModules/Scripting/DynamicTexture CoreModules/Scripting/EMailModules CoreModules/Scripting/HttpRequest CoreModules/Scripting/LoadImageURL CoreModules/Scripting/VectorRender CoreModules/Scripting/WorldComm CoreModules/Scripting/XMLRPC CoreModules/World/Archiver CoreModules/World/Archiver/Tests CoreModules/World/Estate CoreModules/World/Land CoreModules/World/Permissions CoreModules/World/Serialiser CoreModules/World/Sound CoreModules/World/Sun CoreModules/World/Terrain CoreModules/World/Terrain/DefaultEffects CoreModules/World/Terrain/DefaultEffects/bin CoreModules/World/Terrain/DefaultEffects/bin/Debug CoreModules/World/Terrain/Effects CoreModules/World/Terrain/FileLoaders CoreModules/World/Terrain/FloodBrushes CoreModules/World/Terrain/PaintBrushes CoreModules/World/Terrain/Tests CoreModules/World/Vegetation CoreModules/World/Wind CoreModules/World/WorldMap - OpenSim.Region.OptionalModules: all those modules that are not core modules: OptionalModules/Avatar/Chat/IRC-stuff OptionalModules/Avatar/Concierge OptionalModules/Avatar/Voice/AsterixVoice OptionalModules/Avatar/Voice/SIPVoice OptionalModules/ContentManagementSystem OptionalModules/Grid/Interregion OptionalModules/Python OptionalModules/SvnSerialiser OptionalModules/World/NPC OptionalModules/World/TreePopulator
Diffstat (limited to 'OpenSim/Region/Modules/SvnSerialiser')
-rw-r--r--OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs62
-rw-r--r--OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs396
2 files changed, 0 insertions, 458 deletions
diff --git a/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs b/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs
deleted file mode 100644
index 165fcea..0000000
--- a/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,62 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Reflection;
29using System.Runtime.InteropServices;
30
31// General information about an assembly is controlled through the following
32// set of attributes. Change these attribute values to modify the information
33// associated with an assembly.
34[assembly: AssemblyTitle("SvnSerialiser")]
35[assembly: AssemblyDescription("")]
36[assembly: AssemblyConfiguration("")]
37[assembly: AssemblyCompany("")]
38[assembly: AssemblyProduct("SvnSerialiser")]
39[assembly: AssemblyCopyright("Copyright (c) 2008")]
40[assembly: AssemblyTrademark("")]
41[assembly: AssemblyCulture("")]
42
43// Setting ComVisible to false makes the types in this assembly not visible
44// to COM components. If you need to access a type in this assembly from
45// COM, set the ComVisible attribute to true on that type.
46[assembly: ComVisible(false)]
47
48// The following GUID is for the ID of the typelib if this project is exposed to COM
49[assembly: Guid("c0893655-0c18-4dd7-8b5b-5f58ab1ec6c7")]
50
51// Version information for an assembly consists of the following four values:
52//
53// Major Version
54// Minor Version
55// Build Number
56// Revision
57//
58// You can specify all the values or you can default the Build and Revision Numbers
59// by using the '*' as shown below:
60// [assembly: AssemblyVersion("1.0.*")]
61[assembly: AssemblyVersion("1.0.0.0")]
62[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
deleted file mode 100644
index 6e3b620..0000000
--- a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
+++ /dev/null
@@ -1,396 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Timers;
33using log4net;
34using Nini.Config;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Environment.Modules.World.Serialiser;
37using OpenSim.Region.Environment.Modules.World.Terrain;
38using OpenSim.Region.Framework.Scenes;
39using PumaCode.SvnDotNet.AprSharp;
40using PumaCode.SvnDotNet.SubversionSharp;
41using Slash=System.IO.Path;
42
43namespace OpenSim.Region.Modules.SvnSerialiser
44{
45 public class SvnBackupModule : IRegionModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 private readonly List<Scene> m_scenes = new List<Scene>();
49 private readonly Timer m_timer = new Timer();
50
51 private bool m_enabled = false;
52 private bool m_installBackupOnLoad = false;
53 private IRegionSerialiserModule m_serialiser;
54 private bool m_svnAutoSave = false;
55 private SvnClient m_svnClient;
56 private string m_svndir = "SVNmodule" + Slash.DirectorySeparatorChar + "repo";
57 private string m_svnpass = "password";
58
59 private TimeSpan m_svnperiod = new TimeSpan(0, 0, 15, 0, 0);
60 private string m_svnurl = "svn://insert.Your.svn/here/";
61 private string m_svnuser = "username";
62
63 #region SvnModule Core
64
65 /// <summary>
66 /// Exports a specified scene to the SVN repo directory, then commits.
67 /// </summary>
68 /// <param name="scene">The scene to export</param>
69 public void SaveRegion(Scene scene)
70 {
71 List<string> svnfilenames = CreateAndAddExport(scene);
72
73 m_svnClient.Commit3(svnfilenames, true, false);
74 m_log.Info("[SVNBACKUP]: Region backup successful (" + scene.RegionInfo.RegionName + ").");
75 }
76
77 /// <summary>
78 /// Saves all registered scenes to the SVN repo, then commits.
79 /// </summary>
80 public void SaveAllRegions()
81 {
82 List<string> svnfilenames = new List<string>();
83 List<string> regions = new List<string>();
84
85 foreach (Scene scene in m_scenes)
86 {
87 svnfilenames.AddRange(CreateAndAddExport(scene));
88 regions.Add("'" + scene.RegionInfo.RegionName + "' ");
89 }
90
91 m_svnClient.Commit3(svnfilenames, true, false);
92 m_log.Info("[SVNBACKUP]: Server backup successful (" + String.Concat(regions.ToArray()) + ").");
93 }
94
95 private List<string> CreateAndAddExport(Scene scene)
96 {
97 m_log.Info("[SVNBACKUP]: Saving a region to SVN with name " + scene.RegionInfo.RegionName);
98
99 List<string> filenames = m_serialiser.SerialiseRegion(scene, m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID + Slash.DirectorySeparatorChar);
100
101 try
102 {
103 m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID, true, false, false);
104 }
105 catch (SvnException)
106 {
107 }
108
109 List<string> svnfilenames = new List<string>();
110 foreach (string filename in filenames)
111 svnfilenames.Add(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID + Slash.DirectorySeparatorChar + filename);
112 svnfilenames.Add(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID);
113
114 return svnfilenames;
115 }
116
117 public void LoadRegion(Scene scene)
118 {
119 IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>();
120 if (serialiser != null)
121 {
122 serialiser.LoadPrimsFromXml2(
123 scene,
124 m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID
125 + Slash.DirectorySeparatorChar + "objects.xml");
126
127 scene.RequestModuleInterface<ITerrainModule>().LoadFromFile(
128 m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID
129 + Slash.DirectorySeparatorChar + "heightmap.r32");
130
131 m_log.Info("[SVNBACKUP]: Region load successful (" + scene.RegionInfo.RegionName + ").");
132 }
133 else
134 {
135 m_log.ErrorFormat(
136 "[SVNBACKUP]: Region load of {0} failed - no serialisation module available",
137 scene.RegionInfo.RegionName);
138 }
139 }
140
141 private void CheckoutSvn()
142 {
143 m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
144 }
145
146 private void CheckoutSvn(SvnRevision revision)
147 {
148 m_svnClient.Checkout2(m_svnurl, m_svndir, revision, revision, true, false);
149 }
150
151 // private void CheckoutSvnPartial(string subdir)
152 // {
153 // if (!Directory.Exists(m_svndir + Slash.DirectorySeparatorChar + subdir))
154 // Directory.CreateDirectory(m_svndir + Slash.DirectorySeparatorChar + subdir);
155
156 // m_svnClient.Checkout2(m_svnurl + "/" + subdir, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
157 // }
158
159 // private void CheckoutSvnPartial(string subdir, SvnRevision revision)
160 // {
161 // if (!Directory.Exists(m_svndir + Slash.DirectorySeparatorChar + subdir))
162 // Directory.CreateDirectory(m_svndir + Slash.DirectorySeparatorChar + subdir);
163
164 // m_svnClient.Checkout2(m_svnurl + "/" + subdir, m_svndir, revision, revision, true, false);
165 // }
166
167 #endregion
168
169 #region SvnDotNet Callbacks
170
171 private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton,
172 AprString realm, AprString username, bool maySave, AprPool pool)
173 {
174 svnCredentials = SvnAuthCredSimple.Alloc(pool);
175 svnCredentials.Username = new AprString(m_svnuser, pool);
176 svnCredentials.Password = new AprString(m_svnpass, pool);
177 svnCredentials.MaySave = false;
178 return SvnError.NoError;
179 }
180
181 private SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, AprArray commitItems, IntPtr baton, AprPool pool)
182 {
183 if (!commitItems.IsNull)
184 {
185 foreach (SvnClientCommitItem2 item in commitItems)
186 {
187 m_log.Debug("[SVNBACKUP]: ... " + Path.GetFileName(item.Path.ToString()) + " (" + item.Kind.ToString() + ") r" + item.Revision.ToString());
188 }
189 }
190
191 string msg = "Region Backup (" + System.Environment.MachineName + " at " + DateTime.UtcNow + " UTC)";
192
193 m_log.Debug("[SVNBACKUP]: Saved with message: " + msg);
194
195 logMessage = new AprString(msg, pool);
196 tmpFile = new SvnPath(pool);
197
198 return (SvnError.NoError);
199 }
200
201 #endregion
202
203 #region IRegionModule Members
204
205 public void Initialise(Scene scene, IConfigSource source)
206 {
207 try
208 {
209 if (!source.Configs["SVN"].GetBoolean("Enabled", false))
210 return;
211
212 m_enabled = true;
213
214 m_svndir = source.Configs["SVN"].GetString("Directory", m_svndir);
215 m_svnurl = source.Configs["SVN"].GetString("URL", m_svnurl);
216 m_svnuser = source.Configs["SVN"].GetString("Username", m_svnuser);
217 m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass);
218 m_installBackupOnLoad = source.Configs["SVN"].GetBoolean("ImportOnStartup", m_installBackupOnLoad);
219 m_svnAutoSave = source.Configs["SVN"].GetBoolean("Autosave", m_svnAutoSave);
220 m_svnperiod = new TimeSpan(0, source.Configs["SVN"].GetInt("AutosavePeriod", (int) m_svnperiod.TotalMinutes), 0);
221 }
222 catch (Exception)
223 {
224 }
225
226 lock (m_scenes)
227 {
228 m_scenes.Add(scene);
229 }
230 //Only register it once, to prevent command being executed x*region times
231 if (m_scenes.Count == 1)
232 {
233 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
234 }
235 }
236
237 public void PostInitialise()
238 {
239 if (m_enabled == false)
240 return;
241
242 if (m_svnAutoSave)
243 {
244 m_timer.Interval = m_svnperiod.TotalMilliseconds;
245 m_timer.Elapsed += m_timer_Elapsed;
246 m_timer.AutoReset = true;
247 m_timer.Start();
248 }
249
250 m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
251 SetupSvnProvider();
252
253 m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
254 CreateSvnDirectory();
255 CheckoutSvn();
256 SetupSerialiser();
257
258 if (m_installBackupOnLoad)
259 {
260 m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
261 foreach (Scene scene in m_scenes)
262 {
263 LoadRegion(scene);
264 }
265 }
266 }
267
268 public void Close()
269 {
270 }
271
272 public string Name
273 {
274 get { return "SvnBackupModule"; }
275 }
276
277 public bool IsSharedModule
278 {
279 get { return true; }
280 }
281
282 #endregion
283
284 private void EventManager_OnPluginConsole(string[] args)
285 {
286 if (args[0] == "svn" && args[1] == "save")
287 {
288 SaveAllRegions();
289 }
290 if (args.Length == 2)
291 {
292 if (args[0] == "svn" && args[1] == "load")
293 {
294 LoadAllScenes();
295 }
296 }
297 if (args.Length == 3)
298 {
299 if (args[0] == "svn" && args[1] == "load")
300 {
301 LoadAllScenes(Int32.Parse(args[2]));
302 }
303 }
304 if (args.Length == 3)
305 {
306 if (args[0] == "svn" && args[1] == "load-region")
307 {
308 LoadScene(args[2]);
309 }
310 }
311 if (args.Length == 4)
312 {
313 if (args[0] == "svn" && args[1] == "load-region")
314 {
315 LoadScene(args[2], Int32.Parse(args[3]));
316 }
317 }
318 }
319
320 public void LoadScene(string name)
321 {
322 CheckoutSvn();
323
324 foreach (Scene scene in m_scenes)
325 {
326 if (scene.RegionInfo.RegionName.ToLower().Equals(name.ToLower()))
327 {
328 LoadRegion(scene);
329 return;
330 }
331 }
332 m_log.Warn("[SVNBACKUP]: No region loaded - unable to find matching name.");
333 }
334
335 public void LoadScene(string name, int revision)
336 {
337 CheckoutSvn(new SvnRevision(revision));
338
339 foreach (Scene scene in m_scenes)
340 {
341 if (scene.RegionInfo.RegionName.ToLower().Equals(name.ToLower()))
342 {
343 LoadRegion(scene);
344 return;
345 }
346 }
347 m_log.Warn("[SVNBACKUP]: No region loaded - unable to find matching name.");
348 }
349
350 public void LoadAllScenes()
351 {
352 CheckoutSvn();
353
354 foreach (Scene scene in m_scenes)
355 {
356 LoadRegion(scene);
357 }
358 }
359
360 public void LoadAllScenes(int revision)
361 {
362 CheckoutSvn(new SvnRevision(revision));
363
364 foreach (Scene scene in m_scenes)
365 {
366 LoadRegion(scene);
367 }
368 }
369
370 private void m_timer_Elapsed(object sender, ElapsedEventArgs e)
371 {
372 SaveAllRegions();
373 }
374
375 private void SetupSerialiser()
376 {
377 if (m_scenes.Count > 0)
378 m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiserModule>();
379 }
380
381 private void SetupSvnProvider()
382 {
383 m_svnClient = new SvnClient();
384 m_svnClient.AddUsernameProvider();
385 m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2);
386 m_svnClient.OpenAuth();
387 m_svnClient.Context.LogMsgFunc2 = new SvnDelegate(new SvnClient.GetCommitLog2(GetCommitLogCallback));
388 }
389
390 private void CreateSvnDirectory()
391 {
392 if (!Directory.Exists(m_svndir))
393 Directory.CreateDirectory(m_svndir);
394 }
395 }
396}