~monodevelop-bzr/monodevelop-bzr/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright (C) 2008 by Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com>
//        
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//    
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//   
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;

using MonoDevelop.Core;
using MonoDevelop.VersionControl;

using IronPython.Runtime;
using IronPython.Runtime.Types;
using IronPython.Runtime.Operations;
using IronPython.Hosting;
using IronPython.Modules;


namespace MonoDevelop.VersionControl.Bazaar
{
	
	
	public class BazaarLibClient: BazaarClient
	{
		delegate string VersionMethod ();
		delegate void UpdateMethod (string localPath, bool recurse, IProgressMonitor monitor);
		delegate IList<LocalStatus> StatusMethod (string path, BazaarRevision revision);
		delegate void RevertMethod (string localPath, bool recurse, IProgressMonitor monitor, BazaarRevision toRevision);
		delegate void RemoveMethod (string path, bool force, IProgressMonitor monitor);
		delegate void ResolveMethod (string path, bool recurse, IProgressMonitor monitor);
		delegate void PushMethod (string pushLocation, string localPath, IProgressMonitor monitor);
		delegate void MergeMethod (string path, BazaarRevision start, BazaarRevision end, IProgressMonitor monitor);
		delegate IList<string> ListMethod (string path, bool recurse, ListKind kind);
		delegate string GetTextAtRevisionMethod (string path, BazaarRevision rev);
		delegate string GetPathUrlMethod (string path);
		delegate BazaarRevision[] GetHistoryMethod (BazaarRepository repo, string localFile, BazaarRevision since);
		delegate DiffInfo[] DiffMethod (string basePath, string[] files);
		delegate void CommitMethod (ChangeSet changeSet, IProgressMonitor monitor);
		delegate void CheckoutMethod (string url, string targetLocalPath, BazaarRevision rev, bool recurse, IProgressMonitor monitor);
		delegate bool CheckInstalledMethod ();
		delegate void AddMethod (string localPath, bool recurse, IProgressMonitor monitor);

		VersionMethod version;
		UpdateMethod update;
		StatusMethod status;
		RevertMethod revert;
		RemoveMethod remoove;
		ResolveMethod resolve;
		PushMethod push;
		MergeMethod merge;
		ListMethod list;
		GetTextAtRevisionMethod gettextatrevision;
		GetPathUrlMethod getpathurl;
		GetHistoryMethod gethistory;
		DiffMethod diff;
		CommitMethod commit;
		CheckoutMethod checkout;
		CheckInstalledMethod checkinstalled;
		AddMethod addd;
			
		public override string Version {
			get {
				return version ();
			}
		}

		public BazaarLibClient ()
		{
			PythonEngine engine = new PythonEngine ();
			engine.InitializeModules ("", "", PythonEngine.VersionString);
			EngineModule module = engine.CreateModule ("bazaarlibclient", true);
			string file = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "bazaarlibclient.py");
			System.Console.WriteLine("Loading {0}", file);

			try
			{
				engine.ExecuteFile (file, module);
			}
			catch (Exception ex)
			{
				Console.WriteLine ("Failed to execute bazaarlibclient.py file");
				Console.WriteLine ("Exception: {0}", ex.Message);
				throw;
			}

			// Get the Python Class from the module's global list
			UserType ptype = module.Globals["BazaarLibClientReal"] as UserType;

			// Create an instance of the object
			object pobj = ptype.AllocateObject ();
			object tmp = null;

			// Hookup delegates
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Version"), out tmp);
			version = (VersionMethod)Ops.GetDelegate (tmp, typeof (VersionMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Update"), out tmp);
			update = (UpdateMethod)Ops.GetDelegate (tmp, typeof (UpdateMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Status"), out tmp);
			status = (StatusMethod)Ops.GetDelegate (tmp, typeof (StatusMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Revert"), out tmp);
			revert = (RevertMethod)Ops.GetDelegate (tmp, typeof (RevertMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Remove"), out tmp);
			remoove = (RemoveMethod)Ops.GetDelegate (tmp, typeof (RemoveMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Resolve"), out tmp);
			resolve = (ResolveMethod)Ops.GetDelegate (tmp, typeof (ResolveMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Push"), out tmp);
			push = (PushMethod)Ops.GetDelegate (tmp, typeof (PushMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Merge"), out tmp);
			merge = (MergeMethod)Ops.GetDelegate (tmp, typeof (MergeMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("List"), out tmp);
			list = (ListMethod)Ops.GetDelegate (tmp, typeof (ListMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("GetTextAtRevision"), out tmp);
			gettextatrevision = (GetTextAtRevisionMethod)Ops.GetDelegate (tmp, typeof (GetTextAtRevisionMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("GetPathUrl"), out tmp);
			getpathurl = (GetPathUrlMethod)Ops.GetDelegate (tmp, typeof (GetPathUrlMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("GetHistory"), out tmp);
			gethistory = (GetHistoryMethod)Ops.GetDelegate (tmp, typeof (GetHistoryMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Diff"), out tmp);
			diff = (DiffMethod)Ops.GetDelegate (tmp, typeof (DiffMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Commit"), out tmp);
			commit = (CommitMethod)Ops.GetDelegate (tmp, typeof (CommitMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Checkout"), out tmp);
			checkout = (CheckoutMethod)Ops.GetDelegate (tmp, typeof (CheckoutMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("CheckInstalled"), out tmp);
			checkinstalled = (CheckInstalledMethod)Ops.GetDelegate (tmp, typeof (CheckInstalledMethod));
			Ops.TryGetAttr (pobj, SymbolTable.StringToId ("Add"), out tmp);
			addd = (AddMethod)Ops.GetDelegate (tmp, typeof (AddMethod));

		}// constructor

		public override void Update (string localPath, bool recurse, IProgressMonitor monitor)
		{
			update (localPath, recurse, monitor);
		}

		public override IList<LocalStatus> Status (string path, BazaarRevision revision)
		{
			return status (path, revision);
		}

		public override void Revert (string localPath, bool recurse, IProgressMonitor monitor, BazaarRevision toRevision)
		{
			revert (localPath, recurse, monitor, toRevision);
		}

		public override void Remove (string path, bool force, IProgressMonitor monitor)
		{
			remoove (path, force, monitor);
		}

		public override void Push (string pushLocation, string localPath, IProgressMonitor monitor)
		{
			push (pushLocation, localPath, monitor);
		}

		public override void Merge (string path, BazaarRevision start, BazaarRevision end, IProgressMonitor monitor)
		{
			merge (path, start, end, monitor);
		}

		public override IList<string> List (string path, bool recurse, ListKind kind)
		{
			return list (path, recurse, kind);
		}

		public override string GetTextAtRevision (string path, BazaarRevision rev)
		{
			return gettextatrevision (path, rev);
		}

		public override string GetPathUrl (string path)
		{
			return getpathurl (path);
		}

		public override BazaarRevision[] GetHistory (BazaarRepository repo, string localFile, BazaarRevision since)
		{
			return gethistory (repo, localFile, since);
		}

		public override DiffInfo[] Diff (string basePath, string[] files)
		{
			return diff (basePath, files);
		}

		public override void Commit (ChangeSet changeSet, IProgressMonitor monitor)
		{
			commit (changeSet, monitor);
		}

		public override void Checkout (string url, string targetLocalPath, BazaarRevision rev, bool recurse, IProgressMonitor monitor)
		{
			checkout (url, targetLocalPath, rev, recurse, monitor);
		}

		public override bool CheckInstalled ()
		{
			return checkinstalled ();
		}

		public override void Add (string localPath, bool recurse, IProgressMonitor monitor)
		{
			addd (localPath, recurse, monitor);
		}

	}// BazaarLibClient
}