log_dialog.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python2.6
  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. import fcntl
  26. from PyQt4.QtCore import *
  27. from PyQt4.QtGui import *
  28. from qubes.qubes import QubesException
  29. import qubesmanager.resources_rc
  30. from ui_logdlg import *
  31. class LogDialog(Ui_LogDialog, QDialog):
  32. def __init__(self, app, log_path, parent=None):
  33. super(LogDialog, self).__init__(parent)
  34. self.app = app
  35. self.log_path = log_path
  36. self.setupUi(self)
  37. self.setWindowTitle(log_path)
  38. self.connect(self.copy_to_qubes_clipboard, SIGNAL("clicked()"), self.copy_to_qubes_clipboard_triggered)
  39. self.__init_log_text__()
  40. def __init_log_text__(self):
  41. log = open(self.log_path)
  42. self.displayed_text = log.read()
  43. log.close()
  44. self.log_text.setText(self.displayed_text)
  45. def copy_to_qubes_clipboard_triggered(self):
  46. copy_text_to_qubes_clipboard(self.displayed_text)
  47. ########################COPY TEXT TO QUBES CLIPBOARD
  48. def copy_text_to_qubes_clipboard(text):
  49. #inter-appviewer lock
  50. try:
  51. fd = os.open("/var/run/qubes/appviewer.lock", os.O_RDWR|os.O_CREAT, 0600);
  52. fcntl.flock(fd, fcntl.LOCK_EX);
  53. except IOError:
  54. QMessageBox.warning (None, "Warning!", "Error while accessing Qubes clipboard!")
  55. return
  56. qubes_clipboard = open("/var/run/qubes/qubes_clipboard.bin", 'w')
  57. qubes_clipboard.write(text)
  58. qubes_clipboard.close()
  59. qubes_clip_source = open("/var/run/qubes/qubes_clipboard.bin.source", 'w')
  60. qubes_clip_source.write("dom0")
  61. qubes_clip_source.close()
  62. try:
  63. fcntl.flock(fd, fcntl.LOCK_UN)
  64. os.close(fd)
  65. except IOError:
  66. QMessageBox.warning (None, "Warning!", "Error while writing to Qubes clipboard!")
  67. return