From c809896b523ac0afc90c40a629793688b6d895c9 Mon Sep 17 00:00:00 2001 From: Agnieszka Kostrzewa Date: Fri, 11 May 2012 12:50:45 +0200 Subject: [PATCH] Run command in VM (#544) --- icons/run-command.png | Bin 0 -> 2182 bytes mainwindow.ui | 13 ++++++++++++ qubesmanager/main.py | 45 ++++++++++++++++++++++++++++++++++++++++++ resources.qrc | 1 + 4 files changed, 59 insertions(+) create mode 100644 icons/run-command.png diff --git a/icons/run-command.png b/icons/run-command.png new file mode 100644 index 0000000000000000000000000000000000000000..9dcc87ad90ac84d54c84aca78f6f55fc67f16c14 GIT binary patch literal 2182 zcmV;12zmF3P)LCeZsCj6F z3cEq};6qv2ZRjn=r@}#E9=h1YOR0PQZ?)HE?X~wl7bnkx#s2p``|^MP|NZ~^|8+Dr zL1WIGIq@Gqe$4Rse9Ju^k5Bzw)3lK97#SHEr1{s>sZ)Diy?Qm|bWiBFjANvxrY5JP zq#WP7ckhX`w6r8rR)@kgH3Fm4WHfQA8#?HcJ~|D4@7UOw-rL*TfByXWGbFe4_4R$8 zZ~*b~@g7njucoHvPXgkdGG&UkV8H_2>-BP_45ek+R9eVnbwetY@y<*y$;e6UdIhXWw1CNEpItm(jk1I6pstz$_^NhU=|F^jeJ??W7! zDwD;{drL}60uLWP{N*!^i3X68m6g?4T3TAXbLURZbtZ9KXe24?3V^Jy$HvC;=ZcDo z0uLTMh#r7_`}URW*|W!%ZNj0Cn4k}+gi%;n$N^AXOgw<4OP4lM1}ZKnC>XZ~DC=lM zKYjA#$voim^Ya5;U0u-ukeQj;SWJW5&L&NoWXm#&vNiyuyh)*igai&?_wL<+`}glh z4*>LQQ#jc|`y~S;T4avUmVBk4z!i1IR*n4p}HF0LbD1(7bu` zX8+NnM@;~R^_?<~MQIrf0HB6~o)lBjNu%U)1aV-)h7JB>$Bvm4FaWq_9GOBwroxaJ zD=}Zlq5^=dmO{l`V9lB}g;YU82}ch|8HZcl$piGPZlqx?YAZ23Kv^h|o15!DdGaI= zMAiDL<<$TdM|h8_ThjwksfEbpDGL`aY^F-oUsY9wg~*cog@q-{+hRb-1b{a`(9`et zj~@WFhlzuOgQ+BX#Wi6;A!Ce=j}KgLaQu8%3ZyB zwdJ~;08max41ivcPBneojvYI)zkU0L+FYA9Z5r=yp(ss_CU?0k!+Owp%?vT0i!|Zr81gy zA*08Y8+ORr_l7{FO+)~oCl$Am0U)J))Qg@71OjJpzGB4+P7y;XW+>_?%SX}B1k3lN zI5Pm)C&2ZI)KOA+}ONWuYxwwpctM zXCWAk89i~t0A|mgUD?voQj1hLfBt;_F^MLQN{j0<0JRHKDo+!@rcIkHzXJfpo&~^{ zFJB@9(AwHshb28dJ)Ic=05bqsD1`4C062vnKYkoJfQuI|){>~r zojcb?p?_~gL3{YRI4-XGBD)vkO+qZAm4<9~kivd9)5d-4_(B9r&hmsh@7AO>o zHf|Z{{rmTC6%>L8o;`aOIe_ceuk(eBR%S;E zxp@Ev7eRdE#tj{%HL}^MQ>S$7HcNEU=r1s;&BZ0G=;){umO%P*%0f;aaPorMf`;+{x;fzi0?E4&78{$M-SjR{KZ7QxbQ$^08k5230=|E)m4X962VLE)Tn6}idm?l zrcPBhEbg>ZZ36`XL5?<7=vh!uzyZ+r!vjER)0>=}Ttw-wmAv5r7eOIp1<@tRbO<#f zxlc^&31Mpya&B&JO$(cSjY?vATx4-B-|zHpl`5)NR9QZkpSO(v0MoE7xRfK`A^-pY07*qo IM6N<$g7uH_@Bjb+ literal 0 HcmV?d00001 diff --git a/mainwindow.ui b/mainwindow.ui index 30cfa25..7f17ac8 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -295,6 +295,7 @@ + @@ -725,6 +726,18 @@ Size on Disk + + + + :/run-command.png:/run-command.png + + + Run command in VM + + + Run command in the specified VM + + diff --git a/qubesmanager/main.py b/qubesmanager/main.py index 91a80c3..f99340b 100755 --- a/qubesmanager/main.py +++ b/qubesmanager/main.py @@ -23,6 +23,7 @@ import sys import os import fcntl +import errno import dbus from PyQt4.QtCore import * from PyQt4.QtGui import * @@ -735,6 +736,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): self.context_menu.addAction(self.action_appmenus) self.context_menu.addAction(self.action_editfwrules) self.context_menu.addAction(self.action_updatevm) + self.context_menu.addAction(self.action_run_command_in_vm) self.context_menu.addAction(self.action_set_keyboard_layout) self.context_menu.addMenu(self.logs_menu) self.context_menu.addMenu(self.blk_menu) @@ -1040,6 +1042,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): self.action_appmenus.setEnabled(not vm.is_netvm()) self.action_editfwrules.setEnabled(vm.is_networked() and not (vm.is_netvm() and not vm.is_proxyvm())) self.action_updatevm.setEnabled(vm.is_updateable() or vm.qid == 0) + self.action_run_command_in_vm.setEnabled(vm.qid != 0) self.action_set_keyboard_layout.setEnabled(vm.qid != 0 and vm.last_running) else: self.action_settings.setEnabled(False) @@ -1051,6 +1054,7 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): self.action_appmenus.setEnabled(False) self.action_editfwrules.setEnabled(False) self.action_updatevm.setEnabled(False) + self.action_run_command_in_vm.setEnabled(False) self.action_set_keyboard_layout.setEnabled(False) @@ -1401,6 +1405,47 @@ class VmManagerWindow(Ui_VmManagerWindow, QMainWindow): thread_monitor.set_finished() + @pyqtSlot(name='on_action_run_command_in_vm_triggered') + def action_run_command_in_vm_triggered(self): + vm = self.get_selected_vm() + + thread_monitor = ThreadMonitor() + thread = threading.Thread (target=self.do_run_command_in_vm, args=(vm, thread_monitor)) + thread.daemon = True + thread.start() + + while not thread_monitor.is_finished(): + app.processEvents() + time.sleep (0.2) + + if not thread_monitor.success: + QMessageBox.warning (None, "Error while running command", "Exception while running command:
{0}".format(thread_monitor.error_msg)) + + + def do_run_command_in_vm(self, vm, thread_monitor): + cmd = ['kdialog', '--title', 'Qubes command entry', '--inputbox', 'Run command in '+vm.name+':'] + kdialog = subprocess.Popen(cmd, stdout = subprocess.PIPE) + command_to_run = kdialog.stdout.read() + command_to_run = "'"+command_to_run.strip()+"'" + if command_to_run != "": + command_to_run = "qvm-run -a "+ vm.name + " " + command_to_run + try: + subprocess.check_call(command_to_run, shell=True) + except OSError as ex: + if ex.errno == errno.EINTR: + pass + else: + thread_monitor.set_error_msg(str(ex)) + thread_monitor.set_finished() + except Exception as ex: + thread_monitor.set_error_msg(str(ex)) + thread_monitor.set_finished() + thread_monitor.set_finished() + + + + + @pyqtSlot(name='on_action_set_keyboard_layout_triggered') def action_set_keyboard_layout_triggered(self): vm = self.get_selected_vm() diff --git a/resources.qrc b/resources.qrc index 0ca3594..e418cf4 100644 --- a/resources.qrc +++ b/resources.qrc @@ -12,6 +12,7 @@ icons/show-all-running.png icons/mount.png icons/log.png + icons/run-command.png icons/kbd-layout.png icons/copy.png icons/pencil.png