Multiple file log dialog
This commit is contained in:
parent
b4d6080f7b
commit
dc0ee97b27
@ -20,13 +20,12 @@
|
||||
#
|
||||
#
|
||||
import sys
|
||||
import os
|
||||
from functools import partial
|
||||
from PyQt5 import QtWidgets # pylint: disable=import-error
|
||||
|
||||
from qubesadmin import Qubes
|
||||
from . import ui_logdlg # pylint: disable=no-name-in-module
|
||||
from . import clipboard
|
||||
import os
|
||||
|
||||
from qubesadmin import Qubes
|
||||
|
||||
# Display only this size of log
|
||||
LOG_DISPLAY_SIZE = 1024*1024
|
||||
@ -39,10 +38,9 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog):
|
||||
super().__init__(parent)
|
||||
|
||||
self.app = app
|
||||
self.log_path = log_path
|
||||
self.logfiles = log_path
|
||||
|
||||
self.setupUi(self)
|
||||
self.setWindowTitle(log_path)
|
||||
|
||||
self.copy_to_qubes_clipboard.clicked.connect(
|
||||
self.copy_to_clipboard_triggered)
|
||||
@ -52,8 +50,31 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog):
|
||||
self.__init_log_text__()
|
||||
|
||||
def __init_log_text__(self):
|
||||
butts_in_row = 3
|
||||
count = 0
|
||||
for log_path in self.logfiles:
|
||||
if os.path.exists(log_path):
|
||||
button = QtWidgets.QPushButton(log_path)
|
||||
button.clicked.connect(partial(self.set_current_log, log_path))
|
||||
self.buttonsLayout.addWidget(button, count / butts_in_row, count % butts_in_row)
|
||||
count += 1
|
||||
|
||||
if count == 0:
|
||||
QtWidgets.QMessageBox.warning(
|
||||
self,
|
||||
self.tr("Error"),
|
||||
self.tr(
|
||||
"No log files where found for current selection"))
|
||||
else:
|
||||
self.buttonsLayout.itemAt(0).widget().click()
|
||||
|
||||
def copy_to_clipboard_triggered(self):
|
||||
clipboard.copy_text_to_qubes_clipboard(self.displayed_text)
|
||||
|
||||
def set_current_log(self, log_path):
|
||||
self.setWindowTitle(log_path)
|
||||
self.displayed_text = ""
|
||||
log = open(self.log_path)
|
||||
log = open(log_path)
|
||||
log.seek(0, os.SEEK_END)
|
||||
if log.tell() > LOG_DISPLAY_SIZE:
|
||||
self.displayed_text = self.tr(
|
||||
@ -64,11 +85,6 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog):
|
||||
self.displayed_text += log.read()
|
||||
log.close()
|
||||
self.log_text.setPlainText(self.displayed_text)
|
||||
self.log_text.show()
|
||||
|
||||
def copy_to_clipboard_triggered(self):
|
||||
clipboard.copy_text_to_qubes_clipboard(self.displayed_text)
|
||||
|
||||
|
||||
def main():
|
||||
qubes_app = Qubes()
|
||||
|
@ -689,7 +689,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
|
||||
self.context_menu.addAction(self.action_removevm)
|
||||
self.context_menu.addSeparator()
|
||||
|
||||
self.context_menu.addMenu(self.logs_menu)
|
||||
self.context_menu.addAction(self.action_show_logs)
|
||||
self.context_menu.addSeparator()
|
||||
|
||||
self.tools_context_menu = QMenu(self)
|
||||
@ -702,7 +702,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
|
||||
lambda pos: self.open_tools_context_menu(self.toolbar, pos))
|
||||
self.action_menubar.toggled.connect(self.showhide_menubar)
|
||||
self.action_toolbar.toggled.connect(self.showhide_toolbar)
|
||||
self.logs_menu.triggered.connect(self.show_log)
|
||||
self.action_show_logs.triggered.connect(self.show_log)
|
||||
|
||||
self.table.resizeColumnsToContents()
|
||||
|
||||
@ -1030,8 +1030,6 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
|
||||
if not vm.updateable and vm.klass != 'AdminVM':
|
||||
self.action_updatevm.setEnabled(False)
|
||||
|
||||
self.update_logs_menu()
|
||||
|
||||
# noinspection PyArgumentList
|
||||
@pyqtSlot(name='on_action_createvm_triggered')
|
||||
def action_createvm_triggered(self):
|
||||
@ -1428,48 +1426,32 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
|
||||
def open_tools_context_menu(self, widget, point):
|
||||
self.tools_context_menu.exec_(widget.mapToGlobal(point))
|
||||
|
||||
def update_logs_menu(self):
|
||||
self.logs_menu.clear()
|
||||
menu_empty = True
|
||||
|
||||
try:
|
||||
vm_info = self.get_selected_vms()
|
||||
|
||||
if len(vm_info) == 1:
|
||||
vm = vm_info[0].vm
|
||||
|
||||
if vm.klass == 'AdminVM':
|
||||
logfiles = ["/var/log/xen/console/hypervisor.log"]
|
||||
else:
|
||||
logfiles = [
|
||||
"/var/log/xen/console/guest-" + vm.name + ".log",
|
||||
"/var/log/xen/console/guest-" + vm.name + "-dm.log",
|
||||
"/var/log/qubes/guid." + vm.name + ".log",
|
||||
"/var/log/qubes/qrexec." + vm.name + ".log",
|
||||
]
|
||||
|
||||
for logfile in logfiles:
|
||||
if os.path.exists(logfile):
|
||||
action = self.logs_menu.addAction(QIcon(":/log.png"),
|
||||
logfile)
|
||||
action.setData(logfile)
|
||||
menu_empty = False
|
||||
|
||||
self.logs_menu.setEnabled(not menu_empty)
|
||||
except exc.QubesDaemonAccessError:
|
||||
pass
|
||||
|
||||
@pyqtSlot('const QPoint&')
|
||||
def open_context_menu(self, point):
|
||||
self.context_menu.exec_(self.table.mapToGlobal(
|
||||
point + QPoint(10, 0)))
|
||||
|
||||
@pyqtSlot('QAction *')
|
||||
def show_log(self, action):
|
||||
log = str(action.data())
|
||||
log_dlg = log_dialog.LogDialog(self.qt_app, log)
|
||||
log_dlg.exec_()
|
||||
def show_log(self):
|
||||
logfiles = []
|
||||
|
||||
try:
|
||||
for vm_info in self.get_selected_vms():
|
||||
vm = vm_info.vm
|
||||
|
||||
if vm.klass == 'AdminVM':
|
||||
logfiles.append("/var/log/xen/console/hypervisor.log")
|
||||
else:
|
||||
logfiles.extend([
|
||||
"/var/log/xen/console/guest-" + vm.name + ".log",
|
||||
"/var/log/xen/console/guest-" + vm.name + "-dm.log",
|
||||
"/var/log/qubes/guid." + vm.name + ".log",
|
||||
"/var/log/qubes/qrexec." + vm.name + ".log",
|
||||
])
|
||||
|
||||
log_dlg = log_dialog.LogDialog(self.qt_app, logfiles)
|
||||
log_dlg.exec_()
|
||||
except exc.QubesDaemonAccessError:
|
||||
pass
|
||||
|
||||
def main():
|
||||
manager_utils.run_asynchronous(VmManagerWindow)
|
||||
|
@ -14,6 +14,9 @@
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="buttonsLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="log_text">
|
||||
<property name="font">
|
||||
|
@ -297,7 +297,7 @@ Template</string>
|
||||
<addaction name="action_open_console"/>
|
||||
<addaction name="action_set_keyboard_layout"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="logs_menu"/>
|
||||
<addaction name="action_show_logs"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_about">
|
||||
<property name="title">
|
||||
@ -869,6 +869,15 @@ Template</string>
|
||||
<string>Open a secure Xen console in the qube. Useful chiefly for debugging purposes: for normal operation, use "Run Terminal" from the Domains widget. </string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_show_logs">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normaloff>:/log.png</normaloff>:/log.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Logs</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
|
Loading…
Reference in New Issue
Block a user