diff options
author | Jeff Ames | 2008-04-17 12:16:19 +0000 |
---|---|---|
committer | Jeff Ames | 2008-04-17 12:16:19 +0000 |
commit | fe3265f4913d4d40be6e4bd2473cbcb3c6f01feb (patch) | |
tree | 6f2b593b4f3c887bd981dfd3f68a539b8e3fc804 /OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs | |
parent | * Missed a file while committing. (diff) | |
download | opensim-SC-fe3265f4913d4d40be6e4bd2473cbcb3c6f01feb.zip opensim-SC-fe3265f4913d4d40be6e4bd2473cbcb3c6f01feb.tar.gz opensim-SC-fe3265f4913d4d40be6e4bd2473cbcb3c6f01feb.tar.bz2 opensim-SC-fe3265f4913d4d40be6e4bd2473cbcb3c6f01feb.tar.xz |
Update svn properties. Add copyright info to some source files.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs | 301 |
1 files changed, 164 insertions, 137 deletions
diff --git a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs index 71882fd..a27ccec 100644 --- a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs +++ b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs | |||
@@ -1,137 +1,164 @@ | |||
1 | using System; | 1 | /* |
2 | using System.Collections.Generic; | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | using Nini.Config; | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | using OpenSim.Region.Environment.Interfaces; | 4 | * |
5 | using OpenSim.Region.Environment.Scenes; | 5 | * Redistribution and use in source and binary forms, with or without |
6 | using OpenSim.Region.Environment.Modules.ExportSerialiser; | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * * Redistributions of source code must retain the above copyright | |
8 | using PumaCode.SvnDotNet.SubversionSharp; | 8 | * notice, this list of conditions and the following disclaimer. |
9 | using PumaCode.SvnDotNet.AprSharp; | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the | |
11 | namespace OpenSim.Region.Modules.SvnSerialiser | 11 | * documentation and/or other materials provided with the distribution. |
12 | { | 12 | * * Neither the name of the OpenSim Project nor the |
13 | public class SvnBackupModule : IRegionModule | 13 | * names of its contributors may be used to endorse or promote products |
14 | { | 14 | * derived from this software without specific prior written permission. |
15 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 15 | * |
16 | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | |
17 | private SvnClient m_svnClient; | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | private bool m_installBackupOnLoad = false; | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | private string m_svnurl = "svn://url.tld/repository/"; | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | private string m_svnuser = "user"; | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | private string m_svnpass = "password"; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | private string m_svndir = "modsvn/"; | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | private IRegionSerialiser m_serialiser; | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | private List<Scene> m_scenes = new List<Scene>(); | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | #region SvnModule Core | 26 | */ |
27 | 27 | ||
28 | public void SaveRegion(Scene scene) | 28 | using System; |
29 | { | 29 | using System.Collections.Generic; |
30 | List<string> filenames = m_serialiser.SerialiseRegion(scene, m_svndir); | 30 | using Nini.Config; |
31 | foreach (string filename in filenames) | 31 | using OpenSim.Region.Environment.Interfaces; |
32 | { | 32 | using OpenSim.Region.Environment.Scenes; |
33 | m_svnClient.Add3(filename, false, true, false); | 33 | using OpenSim.Region.Environment.Modules.ExportSerialiser; |
34 | } | 34 | |
35 | 35 | using PumaCode.SvnDotNet.SubversionSharp; | |
36 | m_svnClient.Commit3(filenames, true, false); | 36 | using PumaCode.SvnDotNet.AprSharp; |
37 | } | 37 | |
38 | 38 | namespace OpenSim.Region.Modules.SvnSerialiser | |
39 | #endregion | 39 | { |
40 | 40 | public class SvnBackupModule : IRegionModule | |
41 | #region SvnDotNet Callbacks | 41 | { |
42 | 42 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
43 | private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton, | 43 | |
44 | AprString realm, AprString username, bool maySave, AprPool pool) | 44 | private SvnClient m_svnClient; |
45 | { | 45 | private bool m_installBackupOnLoad = false; |
46 | svnCredentials = SvnAuthCredSimple.Alloc(pool); | 46 | private string m_svnurl = "svn://url.tld/repository/"; |
47 | svnCredentials.Username = new AprString(m_svnuser, pool); | 47 | private string m_svnuser = "user"; |
48 | svnCredentials.Password = new AprString(m_svnpass, pool); | 48 | private string m_svnpass = "password"; |
49 | svnCredentials.MaySave = false; | 49 | private string m_svndir = "modsvn/"; |
50 | return SvnError.NoError; | 50 | private IRegionSerialiser m_serialiser; |
51 | } | 51 | private List<Scene> m_scenes = new List<Scene>(); |
52 | 52 | ||
53 | private SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, AprArray commitItems, IntPtr baton, AprPool pool) | 53 | #region SvnModule Core |
54 | { | 54 | |
55 | if (!commitItems.IsNull) | 55 | public void SaveRegion(Scene scene) |
56 | { | 56 | { |
57 | foreach (SvnClientCommitItem item in commitItems) | 57 | List<string> filenames = m_serialiser.SerialiseRegion(scene, m_svndir); |
58 | { | 58 | foreach (string filename in filenames) |
59 | m_log.Debug("[SVNBACKUP]: Updated " + item.Path.ToString() + " (" + item.Kind.ToString() + ") " + item.Revision.ToString()); | 59 | { |
60 | m_log.Debug("[SVNBACKUP]: " + item.Url.ToString() + " -> " + item.CopyFromUrl.ToString()); | 60 | m_svnClient.Add3(filename, false, true, false); |
61 | } | 61 | } |
62 | } | 62 | |
63 | 63 | m_svnClient.Commit3(filenames, true, false); | |
64 | m_log.Debug("[SVNBACKUP]: Appending log message."); | 64 | } |
65 | 65 | ||
66 | logMessage = new AprString("Automated Region Backup", pool); | 66 | #endregion |
67 | tmpFile = new SvnPath(pool); | 67 | |
68 | 68 | #region SvnDotNet Callbacks | |
69 | return (SvnError.NoError); | 69 | |
70 | } | 70 | private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton, |
71 | 71 | AprString realm, AprString username, bool maySave, AprPool pool) | |
72 | #endregion | 72 | { |
73 | 73 | svnCredentials = SvnAuthCredSimple.Alloc(pool); | |
74 | #region IRegionModule Members | 74 | svnCredentials.Username = new AprString(m_svnuser, pool); |
75 | 75 | svnCredentials.Password = new AprString(m_svnpass, pool); | |
76 | public void Initialise(Scene scene, IConfigSource source) | 76 | svnCredentials.MaySave = false; |
77 | { | 77 | return SvnError.NoError; |
78 | lock (m_scenes) | 78 | } |
79 | { | 79 | |
80 | m_scenes.Add(scene); | 80 | private SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, AprArray commitItems, IntPtr baton, AprPool pool) |
81 | } | 81 | { |
82 | 82 | if (!commitItems.IsNull) | |
83 | scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | 83 | { |
84 | } | 84 | foreach (SvnClientCommitItem item in commitItems) |
85 | 85 | { | |
86 | void EventManager_OnPluginConsole(string[] args) | 86 | m_log.Debug("[SVNBACKUP]: Updated " + item.Path.ToString() + " (" + item.Kind.ToString() + ") " + item.Revision.ToString()); |
87 | { | 87 | m_log.Debug("[SVNBACKUP]: " + item.Url.ToString() + " -> " + item.CopyFromUrl.ToString()); |
88 | if (args[0] == "testsvn") | 88 | } |
89 | SaveRegion(m_scenes[0]); | 89 | } |
90 | } | 90 | |
91 | 91 | m_log.Debug("[SVNBACKUP]: Appending log message."); | |
92 | public void PostInitialise() | 92 | |
93 | { | 93 | logMessage = new AprString("Automated Region Backup", pool); |
94 | m_log.Info("[SVNBACKUP]: Disabled."); | 94 | tmpFile = new SvnPath(pool); |
95 | return; | 95 | |
96 | 96 | return (SvnError.NoError); | |
97 | m_log.Info("[SVNBACKUP]: Connecting..."); | 97 | } |
98 | 98 | ||
99 | m_svnClient = new SvnClient(); | 99 | #endregion |
100 | m_svnClient.AddUsernameProvider(); | 100 | |
101 | m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2); | 101 | #region IRegionModule Members |
102 | m_svnClient.OpenAuth(); | 102 | |
103 | 103 | public void Initialise(Scene scene, IConfigSource source) | |
104 | m_log.Info("[SVNBACKUP]: Checking out base directory..."); | 104 | { |
105 | 105 | lock (m_scenes) | |
106 | if (!System.IO.Directory.Exists(m_svndir)) | 106 | { |
107 | System.IO.Directory.CreateDirectory(m_svndir); | 107 | m_scenes.Add(scene); |
108 | 108 | } | |
109 | m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false); | 109 | |
110 | 110 | scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | |
111 | if (m_scenes.Count > 0) | 111 | } |
112 | m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiser>(); | 112 | |
113 | 113 | void EventManager_OnPluginConsole(string[] args) | |
114 | if (m_installBackupOnLoad) | 114 | { |
115 | { | 115 | if (args[0] == "testsvn") |
116 | 116 | SaveRegion(m_scenes[0]); | |
117 | } | 117 | } |
118 | } | 118 | |
119 | 119 | public void PostInitialise() | |
120 | public void Close() | 120 | { |
121 | { | 121 | m_log.Info("[SVNBACKUP]: Disabled."); |
122 | 122 | return; | |
123 | } | 123 | |
124 | 124 | m_log.Info("[SVNBACKUP]: Connecting..."); | |
125 | public string Name | 125 | |
126 | { | 126 | m_svnClient = new SvnClient(); |
127 | get { return "SvnBackupModule"; } | 127 | m_svnClient.AddUsernameProvider(); |
128 | } | 128 | m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2); |
129 | 129 | m_svnClient.OpenAuth(); | |
130 | public bool IsSharedModule | 130 | |
131 | { | 131 | m_log.Info("[SVNBACKUP]: Checking out base directory..."); |
132 | get { return true; } | 132 | |
133 | } | 133 | if (!System.IO.Directory.Exists(m_svndir)) |
134 | 134 | System.IO.Directory.CreateDirectory(m_svndir); | |
135 | #endregion | 135 | |
136 | } | 136 | m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false); |
137 | } | 137 | |
138 | if (m_scenes.Count > 0) | ||
139 | m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiser>(); | ||
140 | |||
141 | if (m_installBackupOnLoad) | ||
142 | { | ||
143 | |||
144 | } | ||
145 | } | ||
146 | |||
147 | public void Close() | ||
148 | { | ||
149 | |||
150 | } | ||
151 | |||
152 | public string Name | ||
153 | { | ||
154 | get { return "SvnBackupModule"; } | ||
155 | } | ||
156 | |||
157 | public bool IsSharedModule | ||
158 | { | ||
159 | get { return true; } | ||
160 | } | ||
161 | |||
162 | #endregion | ||
163 | } | ||
164 | } | ||