Merge lp:~peter-stuifzand/do-plugins/vmware into lp:do-plugins

Proposed by Peter Stuifzand
Status: Needs review
Proposed branch: lp:~peter-stuifzand/do-plugins/vmware
Merge into: lp:do-plugins
Diff against target: 380 lines (+326/-0)
8 files modified
Makefile.am (+1/-0)
VMWare/Makefile.am (+18/-0)
VMWare/Resources/VMWare.addin.xml.in (+30/-0)
VMWare/src/VMWarePreferencesReader.cs (+81/-0)
VMWare/src/VMWareStartAction.cs (+75/-0)
VMWare/src/VMWareVMItem.cs (+45/-0)
VMWare/src/VMWareVMSource.cs (+74/-0)
configure.ac (+2/-0)
To merge this branch: bzr merge lp:~peter-stuifzand/do-plugins/vmware
Reviewer Review Type Date Requested Status
Do Plugins Team Pending
Review via email: mp+21596@code.launchpad.net

Description of the change

Start of a VMWare plugin. Reads the VM locations from a VMware preferences file. Includes a Start Virtual Machine action to start one of those VMs.

To post a comment you must log in.

Unmerged revisions

677. By Peter Stuifzand

Added beginning of VMWare plugin

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2009-11-08 23:58:01 +0000
3+++ Makefile.am 2010-03-17 21:07:23 +0000
4@@ -73,6 +73,7 @@
5 Tomboy \
6 Vinagre \
7 VirtualBox \
8+ VMWare \
9 VolumeControl \
10 WindowManager \
11 Woof \
12
13=== added directory 'VMWare'
14=== added file 'VMWare/Makefile.am'
15--- VMWare/Makefile.am 1970-01-01 00:00:00 +0000
16+++ VMWare/Makefile.am 2010-03-17 21:07:23 +0000
17@@ -0,0 +1,18 @@
18+include $(top_srcdir)/build.rules.mk
19+
20+ASSEMBLY=VMWare
21+
22+FILES = \
23+ src/VMWareStartAction.cs \
24+ src/VMWareVMItem.cs \
25+ src/VMWareVMSource.cs \
26+ src/VMWarePreferencesReader.cs
27+
28+RESOURCES = \
29+ Resources/VMWare.addin.xml
30+
31+REFERENCES = \
32+ System \
33+ System.Core \
34+ $(DO_PLATFORM_LIBS) \
35+ $(DO_UNIVERSE_LIBS)
36
37=== added directory 'VMWare/Resources'
38=== added file 'VMWare/Resources/VMWare.addin.xml.in'
39--- VMWare/Resources/VMWare.addin.xml.in 1970-01-01 00:00:00 +0000
40+++ VMWare/Resources/VMWare.addin.xml.in 2010-03-17 21:07:23 +0000
41@@ -0,0 +1,30 @@
42+<Addin
43+ id="VMWare"
44+ namespace="Do"
45+ version="1.0"
46+ name="VMWare"
47+ description="Start VMWare VMs"
48+ author="Peter Stuifzand"
49+ category="Community"
50+ defaultEnabled="false"
51+ >
52+
53+ <Runtime>
54+ <Import assembly="VMWare.dll"/>
55+ </Runtime>
56+
57+ <Localizer type="Gettext" catalog="gnome-do-plugins" location="@expanded_datadir@/locale" />
58+
59+ <Dependencies>
60+ <Addin id="Universe" version="1.0" />
61+ </Dependencies>
62+
63+ <Extension path="/Do/ItemSource">
64+ <ItemSource type="VMWare.VMWareVMSource" />
65+ </Extension>
66+
67+ <!-- Extensions included in this assembly -->
68+ <Extension path= "/Do/Action">
69+ <Action type="VMWare.VMWareStartAction" />
70+ </Extension>
71+</Addin>
72
73=== added directory 'VMWare/src'
74=== added file 'VMWare/src/VMWarePreferencesReader.cs'
75--- VMWare/src/VMWarePreferencesReader.cs 1970-01-01 00:00:00 +0000
76+++ VMWare/src/VMWarePreferencesReader.cs 2010-03-17 21:07:23 +0000
77@@ -0,0 +1,81 @@
78+
79+using System;
80+using System.IO;
81+using System.Collections.Generic;
82+using System.Text.RegularExpressions;
83+
84+namespace VMWare {
85+
86+ public class VMWarePreferencesReader {
87+ public List<string> ReadPreferences() {
88+ return ReadFile(FindPreferencesFile());
89+ }
90+
91+ private string FindPreferencesFile() {
92+ string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
93+ return Path.Combine(home, ".vmware/preferences");
94+ }
95+
96+ private List<string> ReadFile(string filename) {
97+ Dictionary<string, VM> vms = new Dictionary<string, VM>();
98+
99+ using (FileStream fs = new FileStream (filename, FileMode.Open, FileAccess.Read)) {
100+ using (StreamReader reader = new StreamReader (fs)) {
101+
102+ Regex preferenceLine = new Regex ("^pref\\.ws\\.(\\w+)\\.(\\w+)\\s*=\\s*\"([^\"]+)\"$");
103+ string s;
104+ while ((s = reader.ReadLine ()) != null) {
105+ Match preference = preferenceLine.Match (s);
106+ if (preference.Groups.Count != 4) continue;
107+
108+ string obj = preference.Groups[1].ToString();
109+ if (!vms.ContainsKey(obj)) {
110+ vms[obj] = new VM();
111+ }
112+
113+ string prop = preference.Groups[2].ToString();
114+ string val = preference.Groups[3].ToString();
115+
116+ if (prop == "present") {
117+ vms[obj].present = val == "TRUE";
118+ }
119+ else if (prop == "type") {
120+ vms[obj].type = val;
121+ }
122+ else if (prop == "path") {
123+ vms[obj].path = val;
124+ }
125+ else if (prop == "file") {
126+ vms[obj].file = val;
127+ }
128+ else if (prop == "dest") {
129+ vms[obj].dest = val;
130+ }
131+ }
132+ }
133+ }
134+
135+ Dictionary<string, int> unique_vms = new Dictionary<string, int>();
136+ foreach (string vm in vms.Keys) {
137+ if (vms[vm].file == null) continue;
138+ if (!vms[vm].present) continue;
139+ unique_vms[ vms[vm].file ] = 1;
140+ }
141+
142+ List<string> vm_list = new List<string> (unique_vms.Keys);
143+ foreach (string vm in unique_vms.Keys) {
144+ vm_list.Add (vm);
145+ }
146+ return vm_list;
147+ }
148+ }
149+
150+ class VM {
151+ public bool present;
152+ public string type;
153+ public string path;
154+ public string file;
155+ public string dest;
156+ }
157+
158+}
159
160=== added file 'VMWare/src/VMWareStartAction.cs'
161--- VMWare/src/VMWareStartAction.cs 1970-01-01 00:00:00 +0000
162+++ VMWare/src/VMWareStartAction.cs 2010-03-17 21:07:23 +0000
163@@ -0,0 +1,75 @@
164+
165+/* SSHAction.cs
166+ *
167+ * GNOME Do is the legal property of its developers. Please refer to the
168+ * COPYRIGHT file distributed with this
169+ * source distribution.
170+ *
171+ * This program is free software: you can redistribute it and/or modify
172+ * it under the terms of the GNU General Public License as published by
173+ * the Free Software Foundation, either version 3 of the License, or
174+ * (at your option) any later version.
175+ *
176+ * This program is distributed in the hope that it will be useful,
177+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
178+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
179+ * GNU General Public License for more details.
180+ *
181+ * You should have received a copy of the GNU General Public License
182+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
183+ */
184+
185+using System;
186+using System.Collections.Generic;
187+using System.Linq;
188+using Do.Universe;
189+using Do.Platform;
190+using System.Diagnostics;
191+
192+using Mono.Addins;
193+
194+namespace VMWare {
195+
196+ public class VMWareStartAction : Act {
197+
198+ public override string Name {
199+ get {
200+ return AddinManager.CurrentLocalizer.GetString ("Start Virtual Machine");
201+ }
202+ }
203+
204+ public override string Description {
205+ get {
206+ return AddinManager.CurrentLocalizer.GetString ("Start VMWare Virtual Machine");
207+ }
208+ }
209+
210+ public override string Icon {
211+ get {
212+ return "vm-power-on";
213+ }
214+ }
215+
216+ public override IEnumerable<Type> SupportedItemTypes {
217+ get {
218+ yield return typeof (VMWareVMItem);
219+ }
220+ }
221+
222+ public override bool SupportsItem (Item item) {
223+ return true;
224+ }
225+
226+ public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
227+ if (items.First () is VMWareVMItem) {
228+ VMWareVMItem item = items.First () as VMWareVMItem;
229+
230+ Process term = new Process ();
231+ term.StartInfo.FileName = "vmrun";
232+ term.StartInfo.Arguments = "start \"" + item.Filename + "\"";
233+ term.Start ();
234+ }
235+ yield break;
236+ }
237+ }
238+}
239
240=== added file 'VMWare/src/VMWareVMItem.cs'
241--- VMWare/src/VMWareVMItem.cs 1970-01-01 00:00:00 +0000
242+++ VMWare/src/VMWareVMItem.cs 2010-03-17 21:07:23 +0000
243@@ -0,0 +1,45 @@
244+/* VMWareVMItem.cs
245+ *
246+ * GNOME Do is the legal property of its developers. Please refer to the
247+ * COPYRIGHT file distributed with this
248+ * source distribution.
249+ *
250+ * This program is free software: you can redistribute it and/or modify
251+ * it under the terms of the GNU General Public License as published by
252+ * the Free Software Foundation, either version 3 of the License, or
253+ * (at your option) any later version.
254+ *
255+ * This program is distributed in the hope that it will be useful,
256+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
257+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
258+ * GNU General Public License for more details.
259+ *
260+ * You should have received a copy of the GNU General Public License
261+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
262+ */
263+
264+using System;
265+using System.IO;
266+using System.Collections.Generic;
267+
268+using Do.Universe;
269+
270+using Mono.Addins;
271+
272+namespace VMWare {
273+
274+ public class VMWareVMItem : Item {
275+
276+ public VMWareVMItem (string filename)
277+ {
278+ this.Filename = filename;
279+ }
280+
281+ public override string Name { get { return Path.GetFileNameWithoutExtension(this.Filename); } }
282+ public override string Description { get { return AddinManager.CurrentLocalizer.GetString ("VMWare Virtual Machine"); } }
283+ public override string Icon { get { return "application-x-vmware-vm"; } }
284+
285+ public string Filename { get; private set; }
286+ }
287+}
288+
289
290=== added file 'VMWare/src/VMWareVMSource.cs'
291--- VMWare/src/VMWareVMSource.cs 1970-01-01 00:00:00 +0000
292+++ VMWare/src/VMWareVMSource.cs 2010-03-17 21:07:23 +0000
293@@ -0,0 +1,74 @@
294+/* VMWareVMSource.cs
295+ *
296+ * GNOME Do is the legal property of its developers. Please refer to the
297+ * COPYRIGHT file distributed with this
298+ * source distribution.
299+ *
300+ * This program is free software: you can redistribute it and/or modify
301+ * it under the terms of the GNU General Public License as published by
302+ * the Free Software Foundation, either version 3 of the License, or
303+ * (at your option) any later version.
304+ *
305+ * This program is distributed in the hope that it will be useful,
306+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
307+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
308+ * GNU General Public License for more details.
309+ *
310+ * You should have received a copy of the GNU General Public License
311+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
312+ */
313+
314+using System;
315+using System.IO;
316+using System.Collections.Generic;
317+using System.Text.RegularExpressions;
318+
319+using Do.Platform;
320+using Do.Universe;
321+
322+using Mono.Addins;
323+
324+namespace VMWare
325+{
326+
327+ public class VMWareVMSource : ItemSource
328+ {
329+ List<Item> items;
330+
331+ public VMWareVMSource ()
332+ {
333+ items = new List<Item> ();
334+ }
335+
336+ public override string Name { get { return AddinManager.CurrentLocalizer.GetString ("VMWare Virtual machines"); } }
337+ public override string Description { get { return AddinManager.CurrentLocalizer.GetString ("Virtual machines from Workstation configuration"); } }
338+ public override string Icon { get { return "network-server"; } }
339+
340+ public override IEnumerable<Type> SupportedItemTypes {
341+ get {
342+ yield return typeof (VMWareVMItem);
343+ }
344+ }
345+
346+ public override IEnumerable<Item> Items {
347+ get { return items; }
348+ }
349+
350+ public override IEnumerable<Item> ChildrenOfItem (Item parent)
351+ {
352+ yield break;
353+ }
354+
355+ public override void UpdateItems ()
356+ {
357+ items.Clear ();
358+
359+ VMWarePreferencesReader r = new VMWarePreferencesReader ();
360+ List<string> vms = r.ReadPreferences ();
361+ foreach (string vm in vms) {
362+ items.Add (new VMWareVMItem (vm));
363+ }
364+ }
365+ }
366+}
367+
368
369=== modified file 'configure.ac'
370--- configure.ac 2010-03-08 02:43:56 +0000
371+++ configure.ac 2010-03-17 21:07:23 +0000
372@@ -391,6 +391,8 @@
373 VirtualBox/Resources/VirtualBox.addin.xml
374 VolumeControl/Makefile
375 VolumeControl/Resources/VolumeControl.addin.xml
376+VMWare/Makefile
377+VMWare/Resources/VMWare.addin.xml
378 WindowManager/Makefile
379 WindowManager/Resources/WindowManager.addin.xml
380 Woof/Makefile

Subscribers

People subscribed via source and target branches