Merge lp:~cmulk/cardapio/virtualbox-plugin_update into lp:cardapio

Proposed by cmulk
Status: Merged
Merge reported by: Thiago Teixeira
Merged at revision: not available
Proposed branch: lp:~cmulk/cardapio/virtualbox-plugin_update
Merge into: lp:cardapio
Diff against target: 124 lines (+61/-33)
1 file modified
src/plugins/virtualbox.py (+61/-33)
To merge this branch: bzr merge lp:~cmulk/cardapio/virtualbox-plugin_update
Reviewer Review Type Date Requested Status
Thiago Teixeira Pending
Review via email: mp+30052@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Thiago Teixeira (tvst) wrote :

Thanks. I just merged this branch into the trunk code :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugins/virtualbox.py' (properties changed: -x to +x)
2--- src/plugins/virtualbox.py 2010-07-12 00:35:06 +0000
3+++ src/plugins/virtualbox.py 2010-07-15 22:18:43 +0000
4@@ -1,4 +1,12 @@
5-import re
6+import_error = None
7+
8+try:
9+ import os
10+ import gio
11+ from vboxapi import VirtualBoxManager
12+
13+except Exception, exception:
14+ import_error = exception
15
16 class CardapioPlugin (CardapioPluginInterface):
17
18@@ -9,7 +17,7 @@
19 # not used in the GUI yet:
20 url = ''
21 help_text = ''
22- version = '1.1'
23+ version = '1.2'
24
25 plugin_api_version = 1.3
26
27@@ -31,41 +39,34 @@
28 '''
29
30 self.c = cardapio_proxy
31-
32- self.num_search_results = self.c.settings['search results limit']
33- self.vm_items = [] # List of virtual machine items
34-
35- self.c.write_to_log(self, "Loading virtual machine list...")
36+
37+ if import_error:
38+ self.c.write_to_log(self, "Error importing some modules: %s" % import_error, is_error = True)
39+ self.loaded = False
40+ return
41
42 try:
43- vms = subprocess.Popen(['VBoxManage', 'list', 'vms'], stdout = subprocess.PIPE).communicate()[0]
44-
45- vms = re.findall('\".*\"', vms)
46- # Virtual machines are listed in quotes, this extracts them
47- # and builds a list from the VBoxManage output
48-
49- # The list of virtual machine items is built when the plugin loads
50- # to save time when searching
51-
52- for vm in vms:
53- name = vm.replace('\"','')
54- item = {
55- 'name' : name,
56- 'tooltip' : _('Start virtual machine %(name)s') % {'name' : name},
57- 'icon name' : 'VBox',
58- 'type' : 'raw',
59- 'command' : 'VBoxManage startvm %s' % vm,
60- 'context menu' : None,
61- }
62-
63- self.vm_items.append(item)
64-
65- self.loaded = True
66+ subprocess.Popen(['VBoxManage'], stdout = subprocess.PIPE)
67
68 except OSError:
69-
70- self.c.write_to_log(self, "VBoxManage command not recognized: Maybe VirtualBox is not installed...")
71+ self.c.write_to_log(self, "VBoxManage command not recognized: Maybe virtualbox is not installed...", is_error = True)
72 self.loaded = False
73+ return
74+
75+ self.vboxmgr = VirtualBoxManager(None,None)
76+ self.load_vm_items()
77+
78+ machine_path = self.vboxmgr.vbox.systemProperties.defaultMachineFolder
79+
80+ if os.path.exists(machine_path):
81+ self.package_monitor = gio.File(machine_path).monitor_directory()
82+ self.package_monitor.connect('changed', self.on_vms_changed)
83+
84+ else:
85+ self.c.write_to_log(self, 'Path does not exist:' + machine_path)
86+ self.c.write_to_log(self, 'Will not be able to monitor for virtual machine changes')
87+
88+ self.loaded = True
89
90
91 def search(self, text):
92@@ -79,5 +80,32 @@
93 results.append(item)
94
95 self.c.handle_search_result(self, results)
96-
97+
98+ def load_vm_items(self):
99+ self.vm_items = []
100+ vms = self.vboxmgr.getArray(self.vboxmgr.vbox, 'machines')
101+ tooltip = _('Start virtual machine %s\nOS Type: %s')
102+
103+ for vm in vms:
104+ item = {
105+ 'name' : vm.name,
106+ 'tooltip' : tooltip % (vm.name, vm.OSTypeId),
107+ 'icon name' : 'VBox',
108+ 'type' : 'raw',
109+ 'command' : 'VBoxManage startvm %s' % vm.name,
110+ 'context menu' : None,
111+ }
112+
113+ self.vm_items.append(item)
114+
115+
116+ def on_vms_changed(self, monitor, file, other_file, event):
117+
118+ if event in [gio.FILE_MONITOR_EVENT_CREATED,
119+ gio.FILE_MONITOR_EVENT_DELETED]:
120+
121+ self.c.ask_for_reload_permission(self)
122+
123+ def on_reload_permission_granted(self):
124+ self.load_vm_items()
125

Subscribers

People subscribed via source and target branches