log_dialog.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/python2
  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 <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. #
  23. import sys
  24. import os
  25. from PyQt4.QtCore import *
  26. from PyQt4.QtGui import *
  27. from qubes.qubes import QubesException
  28. import qubesmanager.resources_rc
  29. from .ui_logdlg import *
  30. from .clipboard import *
  31. # Display only this size of log
  32. LOG_DISPLAY_SIZE = 1024*1024
  33. class LogDialog(Ui_LogDialog, QDialog):
  34. def __init__(self, app, log_path, parent=None):
  35. super(LogDialog, self).__init__(parent)
  36. self.app = app
  37. self.log_path = log_path
  38. self.setupUi(self)
  39. self.setWindowTitle(log_path)
  40. self.connect(self.copy_to_qubes_clipboard, SIGNAL("clicked()"), self.copy_to_qubes_clipboard_triggered)
  41. self.__init_log_text__()
  42. def __init_log_text__(self):
  43. self.displayed_text = ""
  44. log = open(self.log_path)
  45. log.seek(0, os.SEEK_END)
  46. if log.tell() > LOG_DISPLAY_SIZE:
  47. self.displayed_text = self.tr("(Showing only last %d bytes of file)\n") % LOG_DISPLAY_SIZE
  48. log.seek(-LOG_DISPLAY_SIZE, os.SEEK_END)
  49. else:
  50. log.seek(0, os.SEEK_SET)
  51. self.displayed_text += log.read()
  52. log.close()
  53. self.log_text.setPlainText(self.displayed_text)
  54. def copy_to_qubes_clipboard_triggered(self):
  55. copy_text_to_qubes_clipboard(self.displayed_text)