2018-01-08 02:46:41 +01:00
|
|
|
#!/usr/bin/python3
|
2012-05-10 13:17:24 +02:00
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
|
|
|
|
# Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
2017-11-06 21:06:30 +01:00
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-05-10 13:17:24 +02:00
|
|
|
#
|
|
|
|
#
|
2018-06-20 21:01:49 +02:00
|
|
|
import sys
|
2019-05-22 23:10:09 +02:00
|
|
|
from PyQt5 import QtWidgets # pylint: disable=import-error
|
2012-05-10 13:17:24 +02:00
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
from . import ui_logdlg # pylint: disable=no-name-in-module
|
2018-01-08 02:46:41 +01:00
|
|
|
from . import clipboard
|
2018-01-10 01:54:30 +01:00
|
|
|
import os
|
2012-05-10 13:17:24 +02:00
|
|
|
|
2018-06-20 21:01:49 +02:00
|
|
|
from qubesadmin import Qubes
|
|
|
|
|
2014-05-05 02:15:01 +02:00
|
|
|
# Display only this size of log
|
|
|
|
LOG_DISPLAY_SIZE = 1024*1024
|
2012-05-10 13:17:24 +02:00
|
|
|
|
2018-01-08 02:46:41 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog):
|
2018-01-08 03:06:42 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2012-05-10 13:17:24 +02:00
|
|
|
|
|
|
|
def __init__(self, app, log_path, parent=None):
|
|
|
|
super(LogDialog, self).__init__(parent)
|
|
|
|
|
|
|
|
self.app = app
|
|
|
|
self.log_path = log_path
|
|
|
|
|
|
|
|
self.setupUi(self)
|
|
|
|
self.setWindowTitle(log_path)
|
2018-01-08 02:46:41 +01:00
|
|
|
|
2019-05-22 23:10:09 +02:00
|
|
|
self.copy_to_qubes_clipboard.clicked.connect(
|
|
|
|
self.copy_to_clipboard_triggered)
|
|
|
|
self.copy_to_qubes_clipboard.clicked.connect(
|
|
|
|
self.copy_to_clipboard_triggered)
|
2018-01-08 02:46:41 +01:00
|
|
|
|
2012-05-10 13:17:24 +02:00
|
|
|
self.__init_log_text__()
|
|
|
|
|
|
|
|
def __init_log_text__(self):
|
2014-05-05 02:15:01 +02:00
|
|
|
self.displayed_text = ""
|
2012-05-10 13:17:24 +02:00
|
|
|
log = open(self.log_path)
|
2018-01-10 01:54:30 +01:00
|
|
|
log.seek(0, os.SEEK_END)
|
2014-05-05 02:15:01 +02:00
|
|
|
if log.tell() > LOG_DISPLAY_SIZE:
|
2018-01-08 02:46:41 +01:00
|
|
|
self.displayed_text = self.tr(
|
|
|
|
"(Showing only last %d bytes of file)\n") % LOG_DISPLAY_SIZE
|
2018-06-20 23:08:22 +02:00
|
|
|
log.seek(log.tell()-LOG_DISPLAY_SIZE, os.SEEK_SET)
|
2014-05-05 02:15:01 +02:00
|
|
|
else:
|
2018-01-10 01:54:30 +01:00
|
|
|
log.seek(0, os.SEEK_SET)
|
2014-05-05 02:15:01 +02:00
|
|
|
self.displayed_text += log.read()
|
2012-05-10 13:17:24 +02:00
|
|
|
log.close()
|
2014-05-05 02:15:01 +02:00
|
|
|
self.log_text.setPlainText(self.displayed_text)
|
2019-05-22 23:10:09 +02:00
|
|
|
self.log_text.show()
|
2012-05-10 13:17:24 +02:00
|
|
|
|
2018-01-08 03:06:42 +01:00
|
|
|
def copy_to_clipboard_triggered(self):
|
2018-01-08 02:46:41 +01:00
|
|
|
clipboard.copy_text_to_qubes_clipboard(self.displayed_text)
|
2018-06-20 21:01:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
qubes_app = Qubes()
|
2019-05-22 23:10:09 +02:00
|
|
|
qt_app = QtWidgets.QApplication(sys.argv)
|
2018-06-20 21:01:49 +02:00
|
|
|
|
|
|
|
log_window = LogDialog(qubes_app, sys.argv[1])
|
|
|
|
log_window.show()
|
|
|
|
|
|
|
|
qt_app.exec_()
|
|
|
|
qt_app.exit()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|