log_dialog: display only last 1MB of log, force it plain text

This commit is contained in:
Marek Marczykowski-Górecki 2014-05-05 02:15:01 +02:00
parent b4dcf0ceb4
commit 04c0f4472a

View File

@ -33,6 +33,8 @@ import qubesmanager.resources_rc
from ui_logdlg import *
# Display only this size of log
LOG_DISPLAY_SIZE = 1024*1024
class LogDialog(Ui_LogDialog, QDialog):
@ -50,10 +52,17 @@ class LogDialog(Ui_LogDialog, QDialog):
self.__init_log_text__()
def __init_log_text__(self):
self.displayed_text = ""
log = open(self.log_path)
self.displayed_text = log.read()
log.seek(0, os.SEEK_END)
if log.tell() > LOG_DISPLAY_SIZE:
self.displayed_text = "(Showing only last %d bytes of file)\n" % LOG_DISPLAY_SIZE
log.seek(-LOG_DISPLAY_SIZE, os.SEEK_END)
else:
log.seek(0, os.SEEK_SET)
self.displayed_text += log.read()
log.close()
self.log_text.setText(self.displayed_text)
self.log_text.setPlainText(self.displayed_text)
def copy_to_qubes_clipboard_triggered(self):