[kupfer] +plugin.virtualbox; pl: update translation



commit 51177e9245d103928d15873b2c7467c5557369d2
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Thu Oct 8 20:33:09 2009 +0200

    +plugin.virtualbox; pl: update translation
    
    virtualbox: quick acces to Sun VirtualBox virtual machines (start, stop,
    etc) via vboxapi.

 kupfer/plugin/virtualbox.py |  200 +++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in              |    1 +
 po/pl.po                    |   51 ++++++++++-
 3 files changed, 249 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/virtualbox.py b/kupfer/plugin/virtualbox.py
new file mode 100644
index 0000000..f1bba4b
--- /dev/null
+++ b/kupfer/plugin/virtualbox.py
@@ -0,0 +1,200 @@
+# -*- coding: UTF-8 -*-
+
+import os
+import sys
+
+from kupfer.objects import Leaf, Action, Source, AppLeafContentMixin
+from kupfer.helplib import FilesystemWatchMixin
+from kupfer import pretty, plugin_support
+
+# try import vboxapi
+try:
+	import vboxapi
+except ImportError:
+	pretty.print_error('No vboxapi found...')
+	vboxapi = None
+
+# try to load xpcom from vbox sdk
+if vboxapi:
+	xpcom_path = vboxapi.VboxSdkDir+'/bindings/xpcom/python/'
+	xpcom_Exception = Exception
+	if os.path.isdir(xpcom_path):
+		sys.path.append(xpcom_path)
+		try:
+			import xpcom
+		except ImportError:
+			pretty.print_error('Cannot import xpcom')
+		else:
+			xpcom_Exception = xpcom.Exception
+
+__kupfer_name__ = _("VirtualBox")
+__kupfer_sources__ = ("VBoxMachinesSource", )
+__description__ = _("Control Sun VirtualBox Virtual Machines")
+__version__ = "0.1"
+__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
+__kupfer_settings__ = plugin_support.PluginSettings(
+		plugin_support.SETTING_PREFER_CATALOG,
+)
+
+
+VM_POWEROFF = 0
+VM_POWERON = 1
+VM_PAUSED = 2
+
+
+def _get_object_session():
+	''' get new session to vm '''
+	vbox, session = None, None
+	if vboxapi is not None:
+		try:
+			vbox = vboxapi.VirtualBoxManager(None, None)
+			session = vbox.mgr.getSessionObject(vbox.vbox)
+		except xpcom_Exception, err:
+			vbox = None
+			pretty.print_error('_get_object_session error ', err)
+
+	return vbox, session
+
+def _get_existing_session(vm_uuid):
+	''' get existing session by machine uuid '''
+	vbox, session = None, None
+	if vboxapi is not None:
+		try:
+			vbox = vboxapi.VirtualBoxManager(None, None)
+			session = vbox.mgr.getSessionObject(vbox.vbox)
+			vbox.vbox.openExistingSession(session, vm_uuid)
+		except xpcom_Exception, err:
+			vbox = None
+			pretty.print_error('_get_existing_session error', err)
+	return vbox, session
+
+def _check_machine_state(vbox, vbox_sess, machine_id):
+	''' check vms state (on/off/paused) '''
+	state = VM_POWERON
+	try:
+		vbox.vbox.openExistingSession(vbox_sess, machine_id)
+		machine_state = vbox_sess.machine.state
+		if machine_state == vbox.constants.MachineState_Paused:
+			state = VM_PAUSED
+		elif machine_state in (vbox.constants.MachineState_PoweredOff, vbox.constants.MachineState_Aborted,
+				vbox.constants.MachineState_Starting):
+			state = VM_POWEROFF
+	except xpcom_Exception, err: # exception == machine is off (xpcom.Exception)
+		# silently set state to off
+		state = VM_POWEROFF
+
+	if vbox_sess.state == vbox.constants.SessionState_Open:
+		vbox_sess.close()
+
+	return state
+
+
+class VirtualMachine(Leaf):
+	def __init__(self, obj, name, state, description):
+		Leaf.__init__(self, obj, name)
+		self.state = state
+		self.description = description
+
+	def get_description(self):
+		return self.description
+
+	def get_icon_name(self):
+		return "VBox"
+
+	def get_actions(self):
+		# actions depend on machine state
+		if self.state == VM_POWEROFF:
+			yield StartVM(_('Power On'), 'system-run', 'gui')
+			yield StartVM(_('Power On Headless'), 'system-run', 'headless', -5)
+		elif self.state == VM_POWERON:
+			yield StdVmAction(_('Send Power Off Signal'), 'system-shutdown', \
+					lambda c:c.powerButton(), -5)
+			yield StdVmAction(_('Pause'), 'pause', lambda c:c.pause())
+			yield StdVmAction(_('Reboot'), 'system-reboot', lambda c:c.reset(), -10)
+		else: # VM_PAUSED
+			yield StdVmAction(_('Resume'), 'resume', lambda c:c.resume())
+
+		if self.state in (VM_POWERON, VM_PAUSED):
+			yield StdVmAction(_('Save State'), 'system-supsend', lambda c:c.saveState())
+			yield StdVmAction(_('Power Off'), 'system-shutdown', lambda c:c.powerDown(), -10)
+
+class _VMAction(Action):
+	def __init__(self, name, icon):
+		Action.__init__(self, name)
+		self._icon = icon
+
+	def get_icon_name(self):
+		return self._icon
+
+	def item_types(self):
+		yield VirtualMachine
+
+
+class StartVM(_VMAction):
+	def __init__(self, name, icon, mode, rank_adjust=0):
+		_VMAction.__init__(self, name, icon)
+		self.mode = mode
+		self.rank_adjust = rank_adjust
+
+	def activate(self, leaf):
+		vbox, session = _get_object_session()
+		if vbox:
+			try:
+				remote_sess = vbox.vbox.openRemoteSession(session, leaf.object, self.mode, '')
+				remote_sess.waitForCompletion(-1)
+			except xpcom_Exception, err: 
+				pretty.print_error('StartVM: ' + self.name + " vm: " + leaf.name + " error", err)
+
+			if session.state == vbox.constants.SessionState_Open:
+				session.close()
+
+
+class StdVmAction(_VMAction):
+	def __init__(self, name, icon, command, rank_adjust=0):
+		_VMAction.__init__(self, name, icon)
+		self.rank_adjust = rank_adjust
+		self.command = command
+
+	def activate(self, leaf):
+		vbox, session = _get_existing_session(leaf.object)
+		if session:
+			try:
+				self.command(session.console)
+			except xpcom_Exception, err: 
+				pretty.print_error('StdVmAction: ' + self.name + " vm: " + leaf.name + " error", err)
+			if session.state == vbox.constants.SessionState_Open:
+				session.close()
+
+
+class VBoxMachinesSource(AppLeafContentMixin, Source):
+	appleaf_content_id = 'Sun VirtualBox'
+
+	def __init__(self, name=_("Sun VirtualBox Machines")):
+		Source.__init__(self, name)
+
+	def is_dynamic(self):
+		return True
+
+	def get_items(self):
+		vbox, vbox_sess = _get_object_session()
+		if vbox is None:
+			return
+
+		machines = vbox.getArray(vbox.vbox, 'machines')
+		session = vbox.mgr.getSessionObject(vbox.vbox)
+		for machine in machines:
+			state = _check_machine_state(vbox, vbox_sess, machine.id)
+			description = machine.description or machine.OSTypeId
+			yield VirtualMachine(machine.id, machine.name, state, description)
+
+	def get_description(self):
+		return None
+
+	def get_icon_name(self):
+		return "VBox"
+
+	def provides(self):
+		yield VirtualMachine
+
+
+
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 276540f..d5a00aa 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -44,5 +44,6 @@ kupfer/plugin/wikipedia.py
 kupfer/plugin/windows.py
 kupfer/plugin/volumes.py
 kupfer/plugin/zim.py
+kupfer/plugin/virtualbox.py
 kupfer/preferences.py
 kupfer/version.py
diff --git a/po/pl.po b/po/pl.po
index e232c43..bfcb90f 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: kupfer\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-10-08 09:17+0200\n"
+"POT-Creation-Date: 2009-10-08 20:32+0200\n"
 "PO-Revision-Date: 2009-09-17 19:40+0200\n"
 "Last-Translator: Maciej Kwiatkowski <kfiadeg gmail com>\n"
 "Language-Team: Polish\n"
@@ -888,7 +888,7 @@ msgstr "Odtwarzaj"
 msgid "Resume playback in Rhythmbox"
 msgstr "Wznów odtwarzanie w Rhythmboksie"
 
-#: ../kupfer/plugin/rhythmbox.py:75
+#: ../kupfer/plugin/rhythmbox.py:75 ../kupfer/plugin/virtualbox.py:112
 msgid "Pause"
 msgstr "Pauza"
 
@@ -1346,6 +1346,47 @@ msgstr "Strony Zima"
 msgid "Pages stored in Zim Notebooks"
 msgstr "Strony w notatnikach Zima"
 
+#: ../kupfer/plugin/virtualbox.py:30
+msgid "VirtualBox"
+msgstr ""
+
+#: ../kupfer/plugin/virtualbox.py:32
+msgid "Control Sun VirtualBox Virtual Machines"
+msgstr "ZarzÄ?dzanie maszynami wirtualnymi Sun VirtualBox"
+
+#: ../kupfer/plugin/virtualbox.py:107
+msgid "Power On"
+msgstr "Uruchom"
+
+#: ../kupfer/plugin/virtualbox.py:108
+msgid "Power On Headless"
+msgstr "Uruchom bez okna"
+
+#: ../kupfer/plugin/virtualbox.py:110
+msgid "Send Power Off Signal"
+msgstr "WyÅ?lij sygnaÅ? wyÅ?Ä?czenia"
+
+#: ../kupfer/plugin/virtualbox.py:113
+msgid "Reboot"
+msgstr "Resetuj"
+
+#. VM_PAUSED
+#: ../kupfer/plugin/virtualbox.py:115
+msgid "Resume"
+msgstr "Wznów"
+
+#: ../kupfer/plugin/virtualbox.py:118
+msgid "Save State"
+msgstr "Zapisz stan"
+
+#: ../kupfer/plugin/virtualbox.py:119
+msgid "Power Off"
+msgstr "WyÅ?Ä?cz"
+
+#: ../kupfer/plugin/virtualbox.py:172
+msgid "Sun VirtualBox Machines"
+msgstr "Maszyny Wirtualne Sun VirtualBox"
+
 #: ../kupfer/preferences.py:218
 msgid "Applied"
 msgstr "Zastosowane"
@@ -1389,7 +1430,8 @@ msgstr "Wybierz katalog"
 
 #: ../kupfer/version.py:36
 msgid "translator-credits"
-msgstr "Maciej Kwiatkowski <kfiadeg gmail com>\n"
+msgstr ""
+"Maciej Kwiatkowski <kfiadeg gmail com>\n"
 "Karol BÄ?dkowski <karol bedkowski gmail com>"
 
 #: ../kupfer/version.py:40
@@ -1428,3 +1470,6 @@ msgstr ""
 "Z pewnoÅ?ciÄ? wraz z niniejszym programem otrzymaÅ?eÅ? też egzemplarz\n"
 "Powszechnej Licencji Publicznej GNU (GNU General Public License);\n"
 "jeÅ?li nie - wejdź na <http://www.gnu.org/licenses/>.\n"
+
+#~ msgid "Control VirtualBox VM"
+#~ msgstr "Sterowanie maszynami wirtualnymi VirtualBoxa"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]