qube_manager.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski-Górecki
  7. # <marmarek@invisiblethingslab.com>
  8. # Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Lesser General Public License along
  21. # with this program; if not, see <http://www.gnu.org/licenses/>.
  22. #
  23. #
  24. import sys
  25. import os
  26. import os.path
  27. import subprocess
  28. import time
  29. from datetime import datetime, timedelta
  30. import traceback
  31. from qubesadmin import Qubes
  32. from qubesadmin import exc
  33. from PyQt4 import QtGui # pylint: disable=import-error
  34. from PyQt4 import QtCore # pylint: disable=import-error
  35. from . import ui_qubemanager # pylint: disable=no-name-in-module
  36. from . import thread_monitor
  37. from . import table_widgets
  38. from . import settings
  39. from . import global_settings
  40. from . import restore
  41. from . import backup
  42. from . import log_dialog
  43. import threading
  44. from qubesmanager.about import AboutDialog
  45. class SearchBox(QtGui.QLineEdit):
  46. def __init__(self, parent=None):
  47. super(SearchBox, self).__init__(parent)
  48. self.focusing = False
  49. def focusInEvent(self, e): # pylint: disable=invalid-name
  50. super(SearchBox, self).focusInEvent(e)
  51. self.selectAll()
  52. self.focusing = True
  53. def mousePressEvent(self, e): # pylint: disable=invalid-name
  54. super(SearchBox, self).mousePressEvent(e)
  55. if self.focusing:
  56. self.selectAll()
  57. self.focusing = False
  58. class VmRowInTable(object):
  59. # pylint: disable=too-few-public-methods
  60. def __init__(self, vm, row_no, table):
  61. self.vm = vm
  62. self.row_no = row_no
  63. # TODO: replace a various different widgets with a more generic
  64. # VmFeatureWidget or VMPropertyWidget
  65. table_widgets.row_height = VmManagerWindow.row_height
  66. table.setRowHeight(row_no, VmManagerWindow.row_height)
  67. self.type_widget = table_widgets.VmTypeWidget(vm)
  68. table.setCellWidget(row_no, VmManagerWindow.columns_indices['Type'],
  69. self.type_widget)
  70. table.setItem(row_no, VmManagerWindow.columns_indices['Type'],
  71. self.type_widget.table_item)
  72. self.label_widget = table_widgets.VmLabelWidget(vm)
  73. table.setCellWidget(row_no, VmManagerWindow.columns_indices['Label'],
  74. self.label_widget)
  75. table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
  76. self.label_widget.table_item)
  77. self.name_widget = table_widgets.VmNameItem(vm)
  78. table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
  79. self.name_widget)
  80. self.info_widget = table_widgets.VmInfoWidget(vm)
  81. table.setCellWidget(row_no, VmManagerWindow.columns_indices['State'],
  82. self.info_widget)
  83. table.setItem(row_no, VmManagerWindow.columns_indices['State'],
  84. self.info_widget.table_item)
  85. self.template_widget = table_widgets.VmTemplateItem(vm)
  86. table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
  87. self.template_widget)
  88. self.netvm_widget = table_widgets.VmNetvmItem(vm)
  89. table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'],
  90. self.netvm_widget)
  91. self.size_widget = table_widgets.VmSizeOnDiskItem(vm)
  92. table.setItem(row_no, VmManagerWindow.columns_indices['Size'],
  93. self.size_widget)
  94. self.internal_widget = table_widgets.VmInternalItem(vm)
  95. table.setItem(row_no, VmManagerWindow.columns_indices['Internal'],
  96. self.internal_widget)
  97. self.ip_widget = table_widgets.VmIPItem(vm)
  98. table.setItem(row_no, VmManagerWindow.columns_indices['IP'],
  99. self.ip_widget)
  100. self.include_in_backups_widget = \
  101. table_widgets.VmIncludeInBackupsItem(vm)
  102. table.setItem(row_no, VmManagerWindow.columns_indices[
  103. 'Backups'], self.include_in_backups_widget)
  104. self.last_backup_widget = table_widgets.VmLastBackupItem(vm)
  105. table.setItem(row_no, VmManagerWindow.columns_indices[
  106. 'Last backup'], self.last_backup_widget)
  107. def update(self, update_size_on_disk=False):
  108. """
  109. Update info in a single VM row
  110. :param update_size_on_disk: should disk utilization be updated? the
  111. widget will extract the data from VM object
  112. :return: None
  113. """
  114. self.info_widget.update_vm_state(self.vm)
  115. if update_size_on_disk:
  116. self.size_widget.update()
  117. vm_shutdown_timeout = 20000 # in msec
  118. vm_restart_check_timeout = 1000 # in msec
  119. class VmShutdownMonitor(QtCore.QObject):
  120. def __init__(self, vm, shutdown_time=vm_shutdown_timeout,
  121. check_time=vm_restart_check_timeout,
  122. and_restart=False, caller=None):
  123. QtCore.QObject.__init__(self)
  124. self.vm = vm
  125. self.shutdown_time = shutdown_time
  126. self.check_time = check_time
  127. self.and_restart = and_restart
  128. self.shutdown_started = datetime.now()
  129. self.caller = caller
  130. def restart_vm_if_needed(self):
  131. if self.and_restart and self.caller:
  132. self.caller.start_vm(self.vm)
  133. def check_again_later(self):
  134. # noinspection PyTypeChecker,PyCallByClass
  135. QtCore.QTimer.singleShot(self.check_time, self.check_if_vm_has_shutdown)
  136. def timeout_reached(self):
  137. actual = datetime.now() - self.shutdown_started
  138. allowed = timedelta(milliseconds=self.shutdown_time)
  139. return actual > allowed
  140. def check_if_vm_has_shutdown(self):
  141. vm = self.vm
  142. vm_is_running = vm.is_running()
  143. try:
  144. vm_start_time = datetime.fromtimestamp(float(vm.start_time))
  145. except (AttributeError, TypeError, ValueError):
  146. vm_start_time = None
  147. if vm_is_running and vm_start_time \
  148. and vm_start_time < self.shutdown_started:
  149. if self.timeout_reached():
  150. reply = QtGui.QMessageBox.question(
  151. None, self.tr("Qube Shutdown"),
  152. self.tr(
  153. "The Qube <b>'{0}'</b> hasn't shutdown within the last "
  154. "{1} seconds, do you want to kill it?<br>").format(
  155. vm.name, self.shutdown_time / 1000),
  156. self.tr("Kill it!"),
  157. self.tr("Wait another {0} seconds...").format(
  158. self.shutdown_time / 1000))
  159. if reply == 0:
  160. try:
  161. vm.kill()
  162. except exc.QubesVMNotStartedError:
  163. # the VM shut down while the user was thinking about
  164. # shutting it down
  165. pass
  166. self.restart_vm_if_needed()
  167. else:
  168. self.shutdown_started = datetime.now()
  169. self.check_again_later()
  170. else:
  171. self.check_again_later()
  172. else:
  173. if vm_is_running:
  174. # Due to unknown reasons, Xen sometimes reports that a domain
  175. # is running even though its start-up timestamp is not valid.
  176. # Make sure that "restart_vm_if_needed" is not called until
  177. # the domain has been completely shut down according to Xen.
  178. self.check_again_later()
  179. return
  180. self.restart_vm_if_needed()
  181. class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
  182. # pylint: disable=too-many-instance-attributes
  183. row_height = 30
  184. column_width = 200
  185. search = ""
  186. # suppress saving settings while initializing widgets
  187. settings_loaded = False
  188. columns_indices = {"Type": 0,
  189. "Label": 1,
  190. "Name": 2,
  191. "State": 3,
  192. "Template": 4,
  193. "NetVM": 5,
  194. "Size": 6,
  195. "Internal": 7,
  196. "IP": 8,
  197. "Backups": 9,
  198. "Last backup": 10,
  199. }
  200. def __init__(self, qubes_app, qt_app, parent=None):
  201. # pylint: disable=unused-argument
  202. super(VmManagerWindow, self).__init__()
  203. self.setupUi(self)
  204. self.manager_settings = QtCore.QSettings(self)
  205. self.qubes_app = qubes_app
  206. self.qt_app = qt_app
  207. self.searchbox = SearchBox()
  208. self.searchbox.setValidator(QtGui.QRegExpValidator(
  209. QtCore.QRegExp("[a-zA-Z0-9-]*", QtCore.Qt.CaseInsensitive), None))
  210. self.searchContainer.addWidget(self.searchbox)
  211. self.connect(self.table, QtCore.SIGNAL("itemSelectionChanged()"),
  212. self.table_selection_changed)
  213. self.table.setColumnWidth(0, self.column_width)
  214. self.sort_by_column = "Type"
  215. self.sort_order = QtCore.Qt.AscendingOrder
  216. self.vms_list = []
  217. self.vms_in_table = {}
  218. self.frame_width = 0
  219. self.frame_height = 0
  220. self.move(self.x(), 0)
  221. self.columns_actions = {
  222. self.columns_indices["Type"]: self.action_vm_type,
  223. self.columns_indices["Label"]: self.action_label,
  224. self.columns_indices["Name"]: self.action_name,
  225. self.columns_indices["State"]: self.action_state,
  226. self.columns_indices["Template"]: self.action_template,
  227. self.columns_indices["NetVM"]: self.action_netvm,
  228. self.columns_indices["Size"]: self.action_size_on_disk,
  229. self.columns_indices["Internal"]: self.action_internal,
  230. self.columns_indices["IP"]: self
  231. .action_ip, self.columns_indices["Backups"]: self
  232. .action_backups, self.columns_indices["Last backup"]: self
  233. .action_last_backup
  234. }
  235. self.visible_columns_count = len(self.columns_indices)
  236. self.table.setColumnWidth(self.columns_indices["State"], 80)
  237. self.table.setColumnWidth(self.columns_indices["Name"], 150)
  238. self.table.setColumnWidth(self.columns_indices["Label"], 40)
  239. self.table.setColumnWidth(self.columns_indices["Type"], 40)
  240. self.table.setColumnWidth(self.columns_indices["Size"], 100)
  241. self.table.setColumnWidth(self.columns_indices["Internal"], 60)
  242. self.table.setColumnWidth(self.columns_indices["IP"], 100)
  243. self.table.setColumnWidth(self.columns_indices["Backups"], 60)
  244. self.table.setColumnWidth(self.columns_indices["Last backup"], 90)
  245. self.table.horizontalHeader().setResizeMode(
  246. QtGui.QHeaderView.Interactive)
  247. self.table.horizontalHeader().setStretchLastSection(True)
  248. self.table.sortItems(self.columns_indices[self.sort_by_column],
  249. self.sort_order)
  250. self.context_menu = QtGui.QMenu(self)
  251. self.context_menu.addAction(self.action_settings)
  252. self.context_menu.addAction(self.action_editfwrules)
  253. self.context_menu.addAction(self.action_appmenus)
  254. self.context_menu.addAction(self.action_set_keyboard_layout)
  255. self.context_menu.addSeparator()
  256. self.context_menu.addAction(self.action_updatevm)
  257. self.context_menu.addAction(self.action_run_command_in_vm)
  258. self.context_menu.addAction(self.action_resumevm)
  259. self.context_menu.addAction(self.action_startvm_tools_install)
  260. self.context_menu.addAction(self.action_pausevm)
  261. self.context_menu.addAction(self.action_shutdownvm)
  262. self.context_menu.addAction(self.action_restartvm)
  263. self.context_menu.addAction(self.action_killvm)
  264. self.context_menu.addSeparator()
  265. self.context_menu.addAction(self.action_clonevm)
  266. self.context_menu.addAction(self.action_removevm)
  267. self.context_menu.addSeparator()
  268. self.context_menu.addMenu(self.logs_menu)
  269. self.context_menu.addSeparator()
  270. self.tools_context_menu = QtGui.QMenu(self)
  271. self.tools_context_menu.addAction(self.action_toolbar)
  272. self.tools_context_menu.addAction(self.action_menubar)
  273. self.connect(
  274. self.table.horizontalHeader(),
  275. QtCore.SIGNAL("sortIndicatorChanged(int, Qt::SortOrder)"),
  276. self.sort_indicator_changed)
  277. self.connect(self.table,
  278. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  279. self.open_context_menu)
  280. self.connect(self.menubar,
  281. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  282. lambda pos: self.open_tools_context_menu(self.menubar,
  283. pos))
  284. self.connect(self.toolbar,
  285. QtCore.SIGNAL("customContextMenuRequested(const QPoint&)"),
  286. lambda pos: self.open_tools_context_menu(self.toolbar,
  287. pos))
  288. self.connect(self.logs_menu, QtCore.SIGNAL("triggered(QAction *)"),
  289. self.show_log)
  290. self.connect(self.searchbox,
  291. QtCore.SIGNAL("textChanged(const QString&)"),
  292. self.do_search)
  293. self.table.setContentsMargins(0, 0, 0, 0)
  294. self.centralwidget.layout().setContentsMargins(0, 0, 0, 0)
  295. self.layout().setContentsMargins(0, 0, 0, 0)
  296. self.connect(self.action_menubar, QtCore.SIGNAL("toggled(bool)"),
  297. self.showhide_menubar)
  298. self.connect(self.action_toolbar, QtCore.SIGNAL("toggled(bool)"),
  299. self.showhide_toolbar)
  300. self.load_manager_settings()
  301. self.fill_table()
  302. self.counter = 0
  303. self.update_size_on_disk = False
  304. self.shutdown_monitor = {}
  305. def load_manager_settings(self):
  306. # visible columns
  307. self.visible_columns_count = 0
  308. for col in self.columns_indices:
  309. col_no = self.columns_indices[col]
  310. visible = self.manager_settings.value(
  311. 'columns/%s' % col,
  312. defaultValue="true")
  313. self.columns_actions[col_no].setChecked(visible == "true")
  314. self.visible_columns_count += 1
  315. self.sort_by_column = str(
  316. self.manager_settings.value("view/sort_column",
  317. defaultValue=self.sort_by_column))
  318. self.sort_order = QtCore.Qt.SortOrder(
  319. self.manager_settings.value("view/sort_order",
  320. defaultValue=self.sort_order))
  321. self.table.sortItems(self.columns_indices[self.sort_by_column],
  322. self.sort_order)
  323. if not self.manager_settings.value("view/menubar_visible",
  324. defaultValue=True):
  325. self.action_menubar.setChecked(False)
  326. if not self.manager_settings.value("view/toolbar_visible",
  327. defaultValue=True):
  328. self.action_toolbar.setChecked(False)
  329. self.settings_loaded = True
  330. def get_vms_list(self):
  331. return [vm for vm in self.qubes_app.domains]
  332. def update_single_row(self, vm):
  333. # this fuction should be used to update a row that already exists
  334. # to add a row, one needs to use the update_table function - the
  335. # whole table needs to be redrawn (and sorted)
  336. if vm in self.qubes_app.domains:
  337. self.vms_in_table[vm.qid].update()
  338. else:
  339. self.update_table()
  340. def fill_table(self):
  341. # save current selection
  342. row_index = self.table.currentRow()
  343. selected_qid = -1
  344. if row_index != -1:
  345. vm_item = self.table.item(row_index, self.columns_indices["Name"])
  346. if vm_item:
  347. selected_qid = vm_item.qid
  348. self.table.setSortingEnabled(False)
  349. self.table.clearContents()
  350. vms_list = self.get_vms_list()
  351. vms_in_table = {}
  352. row_no = 0
  353. for vm in vms_list:
  354. vm_row = VmRowInTable(vm, row_no, self.table)
  355. vms_in_table[vm.qid] = vm_row
  356. row_no += 1
  357. self.table.setRowCount(row_no)
  358. self.vms_list = vms_list
  359. self.vms_in_table = vms_in_table
  360. if selected_qid in vms_in_table.keys():
  361. self.table.setCurrentItem(
  362. self.vms_in_table[selected_qid].name_widget)
  363. self.table.setSortingEnabled(True)
  364. self.showhide_vms()
  365. def showhide_vms(self):
  366. if not self.search:
  367. for row_no in range(self.table.rowCount()):
  368. self.table.setRowHidden(row_no, False)
  369. else:
  370. for row_no in range(self.table.rowCount()):
  371. widget = self.table.cellWidget(row_no,
  372. self.columns_indices["State"])
  373. show = (self.search in widget.vm.name)
  374. self.table.setRowHidden(row_no, not show)
  375. @QtCore.pyqtSlot(str)
  376. def do_search(self, search):
  377. self.search = str(search)
  378. self.showhide_vms()
  379. # noinspection PyArgumentList
  380. @QtCore.pyqtSlot(name='on_action_search_triggered')
  381. def action_search_triggered(self):
  382. self.searchbox.setFocus()
  383. def update_table(self):
  384. self.fill_table()
  385. # TODO: instead of manually refreshing the entire table, use dbus events
  386. # reapply sorting
  387. if self.sort_by_column:
  388. self.table.sortByColumn(self.columns_indices[self.sort_by_column])
  389. self.table_selection_changed()
  390. # noinspection PyPep8Naming
  391. def sort_indicator_changed(self, column, order):
  392. self.sort_by_column = [name for name in self.columns_indices if
  393. self.columns_indices[name] == column][0]
  394. self.sort_order = order
  395. if self.settings_loaded:
  396. self.manager_settings.setValue('view/sort_column',
  397. self.sort_by_column)
  398. self.manager_settings.setValue('view/sort_order', self.sort_order)
  399. self.manager_settings.sync()
  400. def table_selection_changed(self):
  401. vm = self.get_selected_vm()
  402. if vm is not None and vm in self.qubes_app.domains:
  403. # TODO: add boot from device to menu and add windows tools there
  404. # Update available actions:
  405. self.action_settings.setEnabled(vm.klass != 'AdminVM')
  406. self.action_removevm.setEnabled(
  407. vm.klass != 'AdminVM' and not vm.is_running())
  408. self.action_clonevm.setEnabled(vm.klass != 'AdminVM')
  409. self.action_resumevm.setEnabled(
  410. not vm.is_running() or vm.get_power_state() == "Paused")
  411. self.action_pausevm.setEnabled(
  412. vm.is_running() and vm.get_power_state() != "Paused"
  413. and vm.klass != 'AdminVM')
  414. self.action_shutdownvm.setEnabled(
  415. vm.is_running() and vm.get_power_state() != "Paused"
  416. and vm.klass != 'AdminVM')
  417. self.action_restartvm.setEnabled(
  418. vm.is_running() and vm.get_power_state() != "Paused"
  419. and vm.klass != 'AdminVM'
  420. and (vm.klass != 'DispVM' or not vm.auto_cleanup))
  421. self.action_killvm.setEnabled(
  422. (vm.get_power_state() == "Paused" or vm.is_running())
  423. and vm.klass != 'AdminVM')
  424. self.action_appmenus.setEnabled(
  425. vm.klass != 'AdminVM' and vm.klass != 'DispVM'
  426. and not vm.features.get('internal', False))
  427. self.action_editfwrules.setEnabled(vm.klass != 'AdminVM')
  428. self.action_updatevm.setEnabled(getattr(vm, 'updateable', False)
  429. or vm.qid == 0)
  430. self.action_run_command_in_vm.setEnabled(
  431. not vm.get_power_state() == "Paused" and vm.qid != 0)
  432. self.action_set_keyboard_layout.setEnabled(
  433. vm.qid != 0 and
  434. vm.get_power_state() != "Paused" and vm.is_running())
  435. self.update_single_row(vm)
  436. else:
  437. self.action_settings.setEnabled(False)
  438. self.action_removevm.setEnabled(False)
  439. self.action_clonevm.setEnabled(False)
  440. self.action_resumevm.setEnabled(False)
  441. self.action_pausevm.setEnabled(False)
  442. self.action_shutdownvm.setEnabled(False)
  443. self.action_restartvm.setEnabled(False)
  444. self.action_killvm.setEnabled(False)
  445. self.action_appmenus.setEnabled(False)
  446. self.action_editfwrules.setEnabled(False)
  447. self.action_updatevm.setEnabled(False)
  448. self.action_run_command_in_vm.setEnabled(False)
  449. self.action_set_keyboard_layout.setEnabled(False)
  450. # noinspection PyArgumentList
  451. @QtCore.pyqtSlot(name='on_action_createvm_triggered')
  452. def action_createvm_triggered(self): # pylint: disable=no-self-use
  453. subprocess.check_call('qubes-vm-create')
  454. def get_selected_vm(self):
  455. # vm selection relies on the VmInfo widget's value used
  456. # for sorting by VM name
  457. row_index = self.table.currentRow()
  458. if row_index != -1:
  459. vm_item = self.table.item(row_index, self.columns_indices["Name"])
  460. # here is possible race with update_table timer so check
  461. # if really got the item
  462. if vm_item is None:
  463. return None
  464. qid = vm_item.qid
  465. assert self.vms_in_table[qid] is not None
  466. vm = self.vms_in_table[qid].vm
  467. return vm
  468. else:
  469. return None
  470. # noinspection PyArgumentList
  471. @QtCore.pyqtSlot(name='on_action_removevm_triggered')
  472. def action_removevm_triggered(self):
  473. vm = self.get_selected_vm()
  474. if vm.klass == 'TemplateVM':
  475. dependent_vms = 0
  476. for single_vm in self.qubes_app.domains:
  477. if getattr(single_vm, 'template', None) == vm:
  478. dependent_vms += 1
  479. if dependent_vms > 0:
  480. QtGui.QMessageBox.warning(
  481. None, self.tr("Warning!"),
  482. self.tr("This Template Qube cannot be removed, "
  483. "because there is at least one Qube that is based "
  484. "on it.<br><small>If you want to remove this "
  485. "Template Qube and all the Qubes based on it, you "
  486. "should first remove each individual Qube that "
  487. "uses this template.</small>"))
  488. return
  489. (requested_name, ok) = QtGui.QInputDialog.getText(
  490. None, self.tr("Qube Removal Confirmation"),
  491. self.tr("Are you sure you want to remove the Qube <b>'{0}'</b>"
  492. "?<br> All data on this Qube's private storage will be "
  493. "lost!<br><br>Type the name of the Qube (<b>{1}</b>) below "
  494. "to confirm:").format(vm.name, vm.name))
  495. if not ok:
  496. # user clicked cancel
  497. return
  498. elif requested_name != vm.name:
  499. # name did not match
  500. QtGui.QMessageBox.warning(
  501. None,
  502. self.tr("Qube removal confirmation failed"),
  503. self.tr(
  504. "Entered name did not match! Not removing "
  505. "{0}.").format(vm.name))
  506. return
  507. else:
  508. # remove the VM
  509. t_monitor = thread_monitor.ThreadMonitor()
  510. thread = threading.Thread(target=self.do_remove_vm,
  511. args=(vm, self.qubes_app, t_monitor))
  512. thread.daemon = True
  513. thread.start()
  514. progress = QtGui.QProgressDialog(
  515. self.tr(
  516. "Removing Qube: <b>{0}</b>...").format(vm.name), "", 0, 0)
  517. progress.setCancelButton(None)
  518. progress.setModal(True)
  519. progress.show()
  520. while not t_monitor.is_finished():
  521. self.qt_app.processEvents()
  522. time.sleep(0.1)
  523. progress.hide()
  524. if t_monitor.success:
  525. pass
  526. else:
  527. QtGui.QMessageBox.warning(None, self.tr("Error removing Qube!"),
  528. self.tr("ERROR: {0}").format(
  529. t_monitor.error_msg))
  530. self.update_table()
  531. @staticmethod
  532. def do_remove_vm(vm, qubes_app, t_monitor):
  533. try:
  534. del qubes_app.domains[vm.name]
  535. except exc.QubesException as ex:
  536. t_monitor.set_error_msg(str(ex))
  537. t_monitor.set_finished()
  538. # noinspection PyArgumentList
  539. @QtCore.pyqtSlot(name='on_action_clonevm_triggered')
  540. def action_clonevm_triggered(self):
  541. vm = self.get_selected_vm()
  542. name_number = 1
  543. name_format = vm.name + '-clone-%d'
  544. while name_format % name_number in self.qubes_app.domains.keys():
  545. name_number += 1
  546. (clone_name, ok) = QtGui.QInputDialog.getText(
  547. self, self.tr('Qubes clone Qube'),
  548. self.tr('Enter name for Qube <b>{}</b> clone:').format(vm.name),
  549. text=(name_format % name_number))
  550. if not ok or clone_name == "":
  551. return
  552. t_monitor = thread_monitor.ThreadMonitor()
  553. thread = threading.Thread(target=self.do_clone_vm,
  554. args=(vm, self.qubes_app,
  555. clone_name, t_monitor))
  556. thread.daemon = True
  557. thread.start()
  558. progress = QtGui.QProgressDialog(
  559. self.tr("Cloning Qube <b>{0}</b> to <b>{1}</b>...").format(
  560. vm.name, clone_name), "", 0, 0)
  561. progress.setCancelButton(None)
  562. progress.setModal(True)
  563. progress.show()
  564. while not t_monitor.is_finished():
  565. self.qt_app.processEvents()
  566. time.sleep(0.2)
  567. progress.hide()
  568. if not t_monitor.success:
  569. QtGui.QMessageBox.warning(
  570. None,
  571. self.tr("Error while cloning Qube"),
  572. self.tr("Exception while cloning:<br>{0}").format(
  573. t_monitor.error_msg))
  574. self.update_table()
  575. @staticmethod
  576. def do_clone_vm(src_vm, qubes_app, dst_name, t_monitor):
  577. dst_vm = None
  578. try:
  579. dst_vm = qubes_app.clone_vm(src_vm, dst_name)
  580. except exc.QubesException as ex:
  581. t_monitor.set_error_msg(str(ex))
  582. if dst_vm:
  583. pass
  584. t_monitor.set_finished()
  585. # noinspection PyArgumentList
  586. @QtCore.pyqtSlot(name='on_action_resumevm_triggered')
  587. def action_resumevm_triggered(self):
  588. vm = self.get_selected_vm()
  589. if vm.get_power_state() in ["Paused", "Suspended"]:
  590. try:
  591. vm.unpause()
  592. except exc.QubesException as ex:
  593. QtGui.QMessageBox.warning(
  594. None, self.tr("Error unpausing Qube!"),
  595. self.tr("ERROR: {0}").format(ex))
  596. return
  597. self.start_vm(vm)
  598. self.update_single_row(vm)
  599. def start_vm(self, vm):
  600. if vm.is_running():
  601. return
  602. t_monitor = thread_monitor.ThreadMonitor()
  603. thread = threading.Thread(target=self.do_start_vm,
  604. args=(vm, t_monitor))
  605. thread.daemon = True
  606. thread.start()
  607. while not t_monitor.is_finished():
  608. self.qt_app.processEvents()
  609. time.sleep(0.1)
  610. if not t_monitor.success:
  611. QtGui.QMessageBox.warning(
  612. None,
  613. self.tr("Error starting Qube!"),
  614. self.tr("ERROR: {0}").format(t_monitor.error_msg))
  615. self.update_single_row(vm)
  616. @staticmethod
  617. def do_start_vm(vm, t_monitor):
  618. try:
  619. vm.start()
  620. except exc.QubesException as ex:
  621. t_monitor.set_error_msg(str(ex))
  622. t_monitor.set_finished()
  623. return
  624. t_monitor.set_finished()
  625. # noinspection PyArgumentList
  626. @QtCore.pyqtSlot(name='on_action_startvm_tools_install_triggered')
  627. # TODO: replace with boot from device
  628. def action_startvm_tools_install_triggered(self):
  629. # pylint: disable=invalid-name
  630. pass
  631. @QtCore.pyqtSlot(name='on_action_pausevm_triggered')
  632. def action_pausevm_triggered(self):
  633. vm = self.get_selected_vm()
  634. try:
  635. vm.pause()
  636. self.update_single_row(vm)
  637. except exc.QubesException as ex:
  638. QtGui.QMessageBox.warning(
  639. None,
  640. self.tr("Error pausing Qube!"),
  641. self.tr("ERROR: {0}").format(ex))
  642. return
  643. # noinspection PyArgumentList
  644. @QtCore.pyqtSlot(name='on_action_shutdownvm_triggered')
  645. def action_shutdownvm_triggered(self):
  646. vm = self.get_selected_vm()
  647. reply = QtGui.QMessageBox.question(
  648. None, self.tr("Qube Shutdown Confirmation"),
  649. self.tr("Are you sure you want to power down the Qube"
  650. " <b>'{0}'</b>?<br><small>This will shutdown all the "
  651. "running applications within this Qube.</small>").format(
  652. vm.name), QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  653. self.qt_app.processEvents()
  654. if reply == QtGui.QMessageBox.Yes:
  655. self.shutdown_vm(vm)
  656. self.update_single_row(vm)
  657. def shutdown_vm(self, vm, shutdown_time=vm_shutdown_timeout,
  658. check_time=vm_restart_check_timeout, and_restart=False):
  659. try:
  660. vm.shutdown()
  661. except exc.QubesException as ex:
  662. QtGui.QMessageBox.warning(
  663. None,
  664. self.tr("Error shutting down Qube!"),
  665. self.tr("ERROR: {0}").format(ex))
  666. return
  667. self.shutdown_monitor[vm.qid] = VmShutdownMonitor(vm, shutdown_time,
  668. check_time,
  669. and_restart, self)
  670. # noinspection PyCallByClass,PyTypeChecker
  671. QtCore.QTimer.singleShot(check_time, self.shutdown_monitor[
  672. vm.qid].check_if_vm_has_shutdown)
  673. # noinspection PyArgumentList
  674. @QtCore.pyqtSlot(name='on_action_restartvm_triggered')
  675. def action_restartvm_triggered(self):
  676. vm = self.get_selected_vm()
  677. reply = QtGui.QMessageBox.question(
  678. None, self.tr("Qube Restart Confirmation"),
  679. self.tr("Are you sure you want to restart the Qube <b>'{0}'</b>?"
  680. "<br><small>This will shutdown all the running "
  681. "applications within this Qube.</small>").format(vm.name),
  682. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  683. self.qt_app.processEvents()
  684. if reply == QtGui.QMessageBox.Yes:
  685. # in case the user shut down the VM in the meantime
  686. if vm.is_running():
  687. self.shutdown_vm(vm, and_restart=True)
  688. else:
  689. self.start_vm(vm)
  690. self.update_single_row(vm)
  691. # noinspection PyArgumentList
  692. @QtCore.pyqtSlot(name='on_action_killvm_triggered')
  693. def action_killvm_triggered(self):
  694. vm = self.get_selected_vm()
  695. if not (vm.is_running() or vm.is_paused()):
  696. info = self.tr("Qube <b>'{0}'</b> is not running. Are you "
  697. "absolutely sure you want to try to kill it?<br>"
  698. "<small>This will end <b>(not shutdown!)</b> all "
  699. "the running applications within this "
  700. "Qube.</small>").format(vm.name)
  701. else:
  702. info = self.tr("Are you sure you want to kill the Qube "
  703. "<b>'{0}'</b>?<br><small>This will end <b>(not "
  704. "shutdown!)</b> all the running applications within "
  705. "this Qube.</small>").format(vm.name)
  706. reply = QtGui.QMessageBox.question(
  707. None, self.tr("Qube Kill Confirmation"), info,
  708. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel,
  709. QtGui.QMessageBox.Cancel)
  710. self.qt_app.processEvents()
  711. if reply == QtGui.QMessageBox.Yes:
  712. try:
  713. vm.kill()
  714. except exc.QubesException as ex:
  715. QtGui.QMessageBox.critical(
  716. None, self.tr("Error while killing Qube!"),
  717. self.tr(
  718. "<b>An exception ocurred while killing {0}.</b><br>"
  719. "ERROR: {1}").format(vm.name, ex))
  720. return
  721. # noinspection PyArgumentList
  722. @QtCore.pyqtSlot(name='on_action_settings_triggered')
  723. def action_settings_triggered(self):
  724. vm = self.get_selected_vm()
  725. if vm:
  726. settings_window = settings.VMSettingsWindow(
  727. vm, self.qt_app, "basic")
  728. settings_window.exec_()
  729. self.update_single_row(vm)
  730. # noinspection PyArgumentList
  731. @QtCore.pyqtSlot(name='on_action_appmenus_triggered')
  732. def action_appmenus_triggered(self):
  733. vm = self.get_selected_vm()
  734. if vm:
  735. settings_window = settings.VMSettingsWindow(
  736. vm, self.qt_app, "applications")
  737. settings_window.exec_()
  738. # noinspection PyArgumentList
  739. @QtCore.pyqtSlot(name='on_action_refresh_list_triggered')
  740. def action_refresh_list_triggered(self):
  741. self.qubes_app.domains.clear_cache()
  742. self.update_table()
  743. # noinspection PyArgumentList
  744. @QtCore.pyqtSlot(name='on_action_updatevm_triggered')
  745. def action_updatevm_triggered(self):
  746. vm = self.get_selected_vm()
  747. if not vm.is_running():
  748. reply = QtGui.QMessageBox.question(
  749. None, self.tr("Qube Update Confirmation"),
  750. self.tr(
  751. "<b>{0}</b><br>The Qube has to be running to be updated."
  752. "<br>Do you want to start it?<br>").format(vm.name),
  753. QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
  754. if reply != QtGui.QMessageBox.Yes:
  755. return
  756. self.qt_app.processEvents()
  757. t_monitor = thread_monitor.ThreadMonitor()
  758. thread = threading.Thread(target=self.do_update_vm,
  759. args=(vm, t_monitor))
  760. thread.daemon = True
  761. thread.start()
  762. progress = QtGui.QProgressDialog(
  763. self.tr(
  764. "<b>{0}</b><br>Please wait for the updater to "
  765. "launch...").format(vm.name), "", 0, 0)
  766. progress.setCancelButton(None)
  767. progress.setModal(True)
  768. progress.show()
  769. while not t_monitor.is_finished():
  770. self.qt_app.processEvents()
  771. time.sleep(0.2)
  772. progress.hide()
  773. if vm.qid != 0:
  774. if not t_monitor.success:
  775. QtGui.QMessageBox.warning(
  776. None,
  777. self.tr("Error on Qube update!"),
  778. self.tr("ERROR: {0}").format(t_monitor.error_msg))
  779. self.update_single_row(vm)
  780. @staticmethod
  781. def do_update_vm(vm, t_monitor):
  782. try:
  783. if vm.qid == 0:
  784. subprocess.check_call(
  785. ["/usr/bin/qubes-dom0-update", "--clean", "--gui"])
  786. else:
  787. if not vm.is_running():
  788. vm.start()
  789. vm.run_service("qubes.InstallUpdatesGUI",
  790. user="root", wait=False)
  791. except (ChildProcessError, exc.QubesException) as ex:
  792. t_monitor.set_error_msg(str(ex))
  793. t_monitor.set_finished()
  794. return
  795. t_monitor.set_finished()
  796. # noinspection PyArgumentList
  797. @QtCore.pyqtSlot(name='on_action_run_command_in_vm_triggered')
  798. def action_run_command_in_vm_triggered(self):
  799. # pylint: disable=invalid-name
  800. vm = self.get_selected_vm()
  801. (command_to_run, ok) = QtGui.QInputDialog.getText(
  802. self, self.tr('Qubes command entry'),
  803. self.tr('Run command in <b>{}</b>:').format(vm.name))
  804. if not ok or command_to_run == "":
  805. return
  806. t_monitor = thread_monitor.ThreadMonitor()
  807. thread = threading.Thread(target=self.do_run_command_in_vm, args=(
  808. vm, command_to_run, t_monitor))
  809. thread.daemon = True
  810. thread.start()
  811. while not t_monitor.is_finished():
  812. self.qt_app.processEvents()
  813. time.sleep(0.2)
  814. if not t_monitor.success:
  815. QtGui.QMessageBox.warning(
  816. None, self.tr("Error while running command"),
  817. self.tr("Exception while running command:<br>{0}").format(
  818. t_monitor.error_msg))
  819. @staticmethod
  820. def do_run_command_in_vm(vm, command_to_run, t_monitor):
  821. try:
  822. vm.run(command_to_run)
  823. except (ChildProcessError, exc.QubesException) as ex:
  824. t_monitor.set_error_msg(str(ex))
  825. t_monitor.set_finished()
  826. # noinspection PyArgumentList
  827. @QtCore.pyqtSlot(name='on_action_set_keyboard_layout_triggered')
  828. def action_set_keyboard_layout_triggered(self):
  829. # pylint: disable=invalid-name
  830. vm = self.get_selected_vm()
  831. vm.run('qubes-change-keyboard-layout')
  832. # noinspection PyArgumentList
  833. @QtCore.pyqtSlot(name='on_action_editfwrules_triggered')
  834. def action_editfwrules_triggered(self):
  835. vm = self.get_selected_vm()
  836. settings_window = settings.VMSettingsWindow(vm, self.qt_app, "firewall")
  837. settings_window.exec_()
  838. # noinspection PyArgumentList
  839. @QtCore.pyqtSlot(name='on_action_global_settings_triggered')
  840. def action_global_settings_triggered(self): # pylint: disable=invalid-name
  841. global_settings_window = global_settings.GlobalSettingsWindow(
  842. self.qt_app,
  843. self.qubes_app)
  844. global_settings_window.exec_()
  845. # noinspection PyArgumentList
  846. @QtCore.pyqtSlot(name='on_action_show_network_triggered')
  847. def action_show_network_triggered(self):
  848. pass
  849. # TODO: revive for 4.1
  850. # network_notes_dialog = NetworkNotesDialog()
  851. # network_notes_dialog.exec_()
  852. # noinspection PyArgumentList
  853. @QtCore.pyqtSlot(name='on_action_restore_triggered')
  854. def action_restore_triggered(self):
  855. restore_window = restore.RestoreVMsWindow(self.qt_app, self.qubes_app)
  856. restore_window.exec_()
  857. # noinspection PyArgumentList
  858. @QtCore.pyqtSlot(name='on_action_backup_triggered')
  859. def action_backup_triggered(self):
  860. backup_window = backup.BackupVMsWindow(self.qt_app, self.qubes_app)
  861. backup_window.exec_()
  862. # noinspection PyArgumentList
  863. @QtCore.pyqtSlot(name='on_action_exit_triggered')
  864. def action_exit_triggered(self):
  865. self.close()
  866. def showhide_menubar(self, checked):
  867. self.menubar.setVisible(checked)
  868. if not checked:
  869. self.context_menu.addAction(self.action_menubar)
  870. else:
  871. self.context_menu.removeAction(self.action_menubar)
  872. if self.settings_loaded:
  873. self.manager_settings.setValue('view/menubar_visible', checked)
  874. self.manager_settings.sync()
  875. def showhide_toolbar(self, checked):
  876. self.toolbar.setVisible(checked)
  877. if not checked:
  878. self.context_menu.addAction(self.action_toolbar)
  879. else:
  880. self.context_menu.removeAction(self.action_toolbar)
  881. if self.settings_loaded:
  882. self.manager_settings.setValue('view/toolbar_visible', checked)
  883. self.manager_settings.sync()
  884. def showhide_column(self, col_num, show):
  885. self.table.setColumnHidden(col_num, not show)
  886. val = 1 if show else -1
  887. self.visible_columns_count += val
  888. if self.visible_columns_count == 1:
  889. # disable hiding the last one
  890. for col in self.columns_actions:
  891. if self.columns_actions[col].isChecked():
  892. self.columns_actions[col].setEnabled(False)
  893. break
  894. elif self.visible_columns_count == 2 and val == 1:
  895. # enable hiding previously disabled column
  896. for col in self.columns_actions:
  897. if not self.columns_actions[col].isEnabled():
  898. self.columns_actions[col].setEnabled(True)
  899. break
  900. if self.settings_loaded:
  901. col_name = [name for name in self.columns_indices if
  902. self.columns_indices[name] == col_num][0]
  903. self.manager_settings.setValue('columns/%s' % col_name, show)
  904. self.manager_settings.sync()
  905. def on_action_vm_type_toggled(self, checked):
  906. self.showhide_column(self.columns_indices['Type'], checked)
  907. def on_action_label_toggled(self, checked):
  908. self.showhide_column(self.columns_indices['Label'], checked)
  909. def on_action_name_toggled(self, checked):
  910. self.showhide_column(self.columns_indices['Name'], checked)
  911. def on_action_state_toggled(self, checked):
  912. self.showhide_column(self.columns_indices['State'], checked)
  913. def on_action_internal_toggled(self, checked):
  914. self.showhide_column(self.columns_indices['Internal'], checked)
  915. def on_action_ip_toggled(self, checked):
  916. self.showhide_column(self.columns_indices['IP'], checked)
  917. def on_action_backups_toggled(self, checked):
  918. self.showhide_column(self.columns_indices['Backups'], checked)
  919. def on_action_last_backup_toggled(self, checked):
  920. self.showhide_column(self.columns_indices['Last backup'], checked)
  921. def on_action_template_toggled(self, checked):
  922. self.showhide_column(self.columns_indices['Template'], checked)
  923. def on_action_netvm_toggled(self, checked):
  924. self.showhide_column(self.columns_indices['NetVM'], checked)
  925. def on_action_size_on_disk_toggled(self, checked):
  926. self.showhide_column(self.columns_indices['Size'], checked)
  927. # noinspection PyArgumentList
  928. @QtCore.pyqtSlot(name='on_action_about_qubes_triggered')
  929. def action_about_qubes_triggered(self): # pylint: disable=no-self-use
  930. about = AboutDialog()
  931. about.exec_()
  932. def createPopupMenu(self): # pylint: disable=invalid-name
  933. menu = QtGui.QMenu()
  934. menu.addAction(self.action_toolbar)
  935. menu.addAction(self.action_menubar)
  936. return menu
  937. def open_tools_context_menu(self, widget, point):
  938. self.tools_context_menu.exec_(widget.mapToGlobal(point))
  939. @QtCore.pyqtSlot('const QPoint&')
  940. def open_context_menu(self, point):
  941. vm = self.get_selected_vm()
  942. # logs menu
  943. self.logs_menu.clear()
  944. if vm.qid == 0:
  945. logfiles = ["/var/log/xen/console/hypervisor.log"]
  946. else:
  947. logfiles = [
  948. "/var/log/xen/console/guest-" + vm.name + ".log",
  949. "/var/log/xen/console/guest-" + vm.name + "-dm.log",
  950. "/var/log/qubes/guid." + vm.name + ".log",
  951. "/var/log/qubes/qrexec." + vm.name + ".log",
  952. ]
  953. menu_empty = True
  954. for logfile in logfiles:
  955. if os.path.exists(logfile):
  956. action = self.logs_menu.addAction(QtGui.QIcon(":/log.png"),
  957. logfile)
  958. action.setData(logfile)
  959. menu_empty = False
  960. self.logs_menu.setEnabled(not menu_empty)
  961. self.context_menu.exec_(self.table.mapToGlobal(point))
  962. @QtCore.pyqtSlot('QAction *')
  963. def show_log(self, action):
  964. log = str(action.data())
  965. log_dlg = log_dialog.LogDialog(self.qt_app, log)
  966. log_dlg.exec_()
  967. # Bases on the original code by:
  968. # Copyright (c) 2002-2007 Pascal Varet <p.varet@gmail.com>
  969. def handle_exception(exc_type, exc_value, exc_traceback):
  970. filename, line, dummy, dummy = traceback.extract_tb(exc_traceback).pop()
  971. filename = os.path.basename(filename)
  972. error = "%s: %s" % (exc_type.__name__, exc_value)
  973. strace = ""
  974. stacktrace = traceback.extract_tb(exc_traceback)
  975. while stacktrace:
  976. (filename, line, func, txt) = stacktrace.pop()
  977. strace += "----\n"
  978. strace += "line: %s\n" % txt
  979. strace += "func: %s\n" % func
  980. strace += "line no.: %d\n" % line
  981. strace += "file: %s\n" % filename
  982. msg_box = QtGui.QMessageBox()
  983. msg_box.setDetailedText(strace)
  984. msg_box.setIcon(QtGui.QMessageBox.Critical)
  985. msg_box.setWindowTitle("Houston, we have a problem...")
  986. msg_box.setText("Whoops. A critical error has occured. "
  987. "This is most likely a bug in Qubes Manager.<br><br>"
  988. "<b><i>%s</i></b>" % error +
  989. "<br/>at line <b>%d</b><br/>of file %s.<br/><br/>"
  990. % (line, filename))
  991. msg_box.exec_()
  992. def main():
  993. qt_app = QtGui.QApplication(sys.argv)
  994. qt_app.setOrganizationName("The Qubes Project")
  995. qt_app.setOrganizationDomain("http://qubes-os.org")
  996. qt_app.setApplicationName("Qube Manager")
  997. qt_app.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
  998. sys.excepthook = handle_exception
  999. qubes_app = Qubes()
  1000. manager_window = VmManagerWindow(qubes_app, qt_app)
  1001. manager_window.show()
  1002. manager_window.update_table()
  1003. qt_app.exec_()
  1004. if __name__ == "__main__":
  1005. main()