Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

367 lines
13KB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # JACK, A2J, LASH and LADISH Logs Viewer
  4. # Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the COPYING file
  17. # Imports (Global)
  18. from PyQt4.QtCore import pyqtSlot, Qt, QFile, QIODevice, QTextStream, QThread, SIGNAL, SLOT
  19. from PyQt4.QtGui import QDialog, QPalette, QSyntaxHighlighter
  20. # Imports (Custom Stuff)
  21. import ui_logs
  22. from shared import *
  23. # Fix log text output (get rid of terminal colors stuff)
  24. def fixLogText(text):
  25. return text.replace("","").replace("","").replace("","").replace("","").replace("","")
  26. # Syntax Highlighter for JACK
  27. class SyntaxHighligher_JACK(QSyntaxHighlighter):
  28. def __init__(self, parent):
  29. QSyntaxHighlighter.__init__(self, parent)
  30. self.m_palette = self.parent().palette()
  31. def highlightBlock(self, text):
  32. if (": ERROR: " in text):
  33. self.setFormat(text.find(" ERROR: "), len(text), Qt.red)
  34. elif (": WARNING: " in text):
  35. self.setFormat(text.find(" WARNING: "), len(text), Qt.darkRed)
  36. elif (": ------------------" in text):
  37. self.setFormat(text.find(" ------------------"), len(text), self.m_palette.color(QPalette.Active, QPalette.Mid))
  38. elif (": Connecting " in text):
  39. self.setFormat(text.find(" Connecting "), len(text), self.m_palette.color(QPalette.Active, QPalette.Link))
  40. elif (": Disconnecting " in text):
  41. self.setFormat(text.find(" Disconnecting "), len(text), self.m_palette.color(QPalette.Active, QPalette.LinkVisited))
  42. #elif (": New client " in text):
  43. #self.setFormat(text.find(" New client "), len(text), self.m_palette.color(QPalette.Active, QPalette.Link))
  44. # Syntax Highlighter for A2J
  45. class SyntaxHighligher_A2J(QSyntaxHighlighter):
  46. def __init__(self, parent):
  47. QSyntaxHighlighter.__init__(self, parent)
  48. self.m_palette = self.parent().palette()
  49. def highlightBlock(self, text):
  50. if (": error: " in text):
  51. self.setFormat(text.find(" error: "), len(text), Qt.red)
  52. elif (": WARNING: " in text):
  53. self.setFormat(text.find(" WARNING: "), len(text), Qt.darkRed)
  54. elif (": ----------------------------" in text):
  55. self.setFormat(text.find("----------------------------"), len(text), self.m_palette.color(QPalette.Active, QPalette.Mid))
  56. elif (": port created: " in text):
  57. self.setFormat(text.find(" port created: "), len(text), self.m_palette.color(QPalette.Active, QPalette.Link))
  58. elif (": port deleted: " in text):
  59. self.setFormat(text.find(" port deleted: "), len(text), self.m_palette.color(QPalette.Active, QPalette.LinkVisited))
  60. # Syntax Highlighter for LASH
  61. class SyntaxHighligher_LASH(QSyntaxHighlighter):
  62. def __init__(self, parent):
  63. QSyntaxHighlighter.__init__(self, parent)
  64. self.m_palette = self.parent().palette()
  65. def highlightBlock(self, text):
  66. if (": ERROR: " in text):
  67. self.setFormat(text.find(" ERROR: "), len(text), Qt.red)
  68. elif (": WARNING: " in text):
  69. self.setFormat(text.find(" WARNING: "), len(text), Qt.darkRed)
  70. elif (": ------------------" in text):
  71. self.setFormat(text.find(" ------------------"), len(text), self.m_palette.color(QPalette.Active, QPalette.Mid))
  72. # Syntax Highlighter for LADISH
  73. class SyntaxHighligher_LADISH(QSyntaxHighlighter):
  74. def __init__(self, parent):
  75. QSyntaxHighlighter.__init__(self, parent)
  76. self.m_palette = self.parent().palette()
  77. def highlightBlock(self, text):
  78. if (": ERROR: " in text):
  79. self.setFormat(text.find(" ERROR: "), len(text), Qt.red)
  80. elif (": WARNING: " in text):
  81. self.setFormat(text.find(" WARNING: "), len(text), Qt.darkRed)
  82. elif (": -------" in text):
  83. self.setFormat(text.find(" -------"), len(text), self.m_palette.color(QPalette.Active, QPalette.Mid))
  84. # Lockless file read thread
  85. class LogsReadThread(QThread):
  86. def __init__(self, parent):
  87. QThread.__init__(self, parent)
  88. self.m_purgeLogs = False
  89. # -------------------------------------------------------------
  90. # Take some values from parent
  91. self.LOG_FILE_JACK = self.parent().LOG_FILE_JACK
  92. self.LOG_FILE_A2J = self.parent().LOG_FILE_A2J
  93. self.LOG_FILE_LASH = self.parent().LOG_FILE_LASH
  94. self.LOG_FILE_LADISH = self.parent().LOG_FILE_LADISH
  95. # -------------------------------------------------------------
  96. # Init logs
  97. if (self.LOG_FILE_JACK):
  98. self.log_jack_file = QFile(self.LOG_FILE_JACK)
  99. self.log_jack_file.open(QIODevice.ReadOnly)
  100. self.log_jack_stream = QTextStream(self.log_jack_file)
  101. self.log_jack_stream.setCodec("UTF-8")
  102. if (self.LOG_FILE_A2J):
  103. self.log_a2j_file = QFile(self.LOG_FILE_A2J)
  104. self.log_a2j_file.open(QIODevice.ReadOnly)
  105. self.log_a2j_stream = QTextStream(self.log_a2j_file)
  106. self.log_a2j_stream.setCodec("UTF-8")
  107. if (self.LOG_FILE_LASH):
  108. self.log_lash_file = QFile(self.LOG_FILE_LASH)
  109. self.log_lash_file.open(QIODevice.ReadOnly)
  110. self.log_lash_stream = QTextStream(self.log_lash_file)
  111. self.log_lash_stream.setCodec("UTF-8")
  112. if (self.LOG_FILE_LADISH):
  113. self.log_ladish_file = QFile(self.LOG_FILE_LADISH)
  114. self.log_ladish_file.open(QIODevice.ReadOnly)
  115. self.log_ladish_stream = QTextStream(self.log_ladish_file)
  116. self.log_ladish_stream.setCodec("UTF-8")
  117. def purgeLogs(self):
  118. self.m_purgeLogs = True
  119. def run(self):
  120. # -------------------------------------------------------------
  121. # Read logs and set text in main thread
  122. while (self.isRunning()):
  123. if (self.m_purgeLogs):
  124. if (self.LOG_FILE_JACK):
  125. self.log_jack_stream.flush()
  126. self.log_jack_file.close()
  127. self.log_jack_file.open(QIODevice.WriteOnly)
  128. self.log_jack_file.close()
  129. self.log_jack_file.open(QIODevice.ReadOnly)
  130. if (self.LOG_FILE_A2J):
  131. self.log_a2j_stream.flush()
  132. self.log_a2j_file.close()
  133. self.log_a2j_file.open(QIODevice.WriteOnly)
  134. self.log_a2j_file.close()
  135. self.log_a2j_file.open(QIODevice.ReadOnly)
  136. if (self.LOG_FILE_LASH):
  137. self.log_lash_stream.flush()
  138. self.log_lash_file.close()
  139. self.log_lash_file.open(QIODevice.WriteOnly)
  140. self.log_lash_file.close()
  141. self.log_lash_file.open(QIODevice.ReadOnly)
  142. if (self.LOG_FILE_LADISH):
  143. self.log_ladish_stream.flush()
  144. self.log_ladish_file.close()
  145. self.log_ladish_file.open(QIODevice.WriteOnly)
  146. self.log_ladish_file.close()
  147. self.log_ladish_file.open(QIODevice.ReadOnly)
  148. else:
  149. text_jack = ""
  150. text_a2j = ""
  151. text_lash = ""
  152. text_ladish = ""
  153. if (self.LOG_FILE_JACK):
  154. text_jack = fixLogText(self.log_jack_stream.readAll()).strip()
  155. if (self.LOG_FILE_A2J):
  156. text_a2j = fixLogText(self.log_a2j_stream.readAll()).strip()
  157. if (self.LOG_FILE_LASH):
  158. text_lash = fixLogText(self.log_lash_stream.readAll()).strip()
  159. if (self.LOG_FILE_LADISH):
  160. text_ladish = fixLogText(self.log_ladish_stream.readAll()).strip()
  161. self.parent().setLogsText(text_jack, text_a2j, text_lash, text_ladish)
  162. self.emit(SIGNAL("updateLogs()"))
  163. self.sleep(1)
  164. # -------------------------------------------------------------
  165. # Close logs before closing thread
  166. if (self.LOG_FILE_JACK):
  167. self.log_jack_file.close()
  168. if (self.LOG_FILE_A2J):
  169. self.log_a2j_file.close()
  170. if (self.LOG_FILE_LASH):
  171. self.log_lash_file.close()
  172. if (self.LOG_FILE_LADISH):
  173. self.log_ladish_file.close()
  174. # Logs Window
  175. class LogsW(QDialog, ui_logs.Ui_LogsW):
  176. LOG_PATH = os.path.join(HOME, ".log")
  177. LOG_FILE_JACK = os.path.join(LOG_PATH, "jack", "jackdbus.log")
  178. LOG_FILE_A2J = os.path.join(LOG_PATH, "a2j", "a2j.log")
  179. LOG_FILE_LASH = os.path.join(LOG_PATH, "lash", "lash.log")
  180. LOG_FILE_LADISH = os.path.join(LOG_PATH, "ladish", "ladish.log")
  181. def __init__(self, parent, flags):
  182. QDialog.__init__(self, parent, flags)
  183. self.setupUi(self)
  184. self.b_close.setIcon(getIcon("dialog-close"))
  185. self.b_purge.setIcon(getIcon("user-trash"))
  186. self.m_firstRun = True
  187. self.m_text_jack = ""
  188. self.m_text_a2j = ""
  189. self.m_text_lash = ""
  190. self.m_text_ladish = ""
  191. # -------------------------------------------------------------
  192. # Check for unexisting logs and remove tabs for those
  193. tab_index = 0
  194. if (os.path.exists(self.LOG_FILE_JACK) == False):
  195. self.LOG_FILE_JACK = None
  196. self.tabWidget.removeTab(0-tab_index)
  197. tab_index += 1
  198. if (os.path.exists(self.LOG_FILE_A2J) == False):
  199. self.LOG_FILE_A2J = None
  200. self.tabWidget.removeTab(1-tab_index)
  201. tab_index += 1
  202. if (os.path.exists(self.LOG_FILE_LASH) == False):
  203. self.LOG_FILE_LASH = None
  204. self.tabWidget.removeTab(2-tab_index)
  205. tab_index += 1
  206. if (os.path.exists(self.LOG_FILE_LADISH) == False):
  207. self.LOG_FILE_LADISH = None
  208. self.tabWidget.removeTab(3-tab_index)
  209. tab_index += 1
  210. # -------------------------------------------------------------
  211. # Init logs viewers
  212. if (self.LOG_FILE_JACK):
  213. syntax_jack = SyntaxHighligher_JACK(self.pte_jack)
  214. syntax_jack.setDocument(self.pte_jack.document())
  215. if (self.LOG_FILE_A2J):
  216. syntax_a2j = SyntaxHighligher_A2J(self.pte_a2j)
  217. syntax_a2j.setDocument(self.pte_a2j.document())
  218. if (self.LOG_FILE_LASH):
  219. syntax_lash = SyntaxHighligher_LASH(self.pte_lash)
  220. syntax_lash.setDocument(self.pte_lash.document())
  221. if (self.LOG_FILE_LADISH):
  222. syntax_ladish = SyntaxHighligher_LADISH(self.pte_ladish)
  223. syntax_ladish.setDocument(self.pte_ladish.document())
  224. # -------------------------------------------------------------
  225. # Init file read thread
  226. self.m_readThread = LogsReadThread(self)
  227. self.m_readThread.start(QThread.IdlePriority)
  228. # -------------------------------------------------------------
  229. # Set-up connections
  230. self.connect(self.b_purge, SIGNAL("clicked()"), SLOT("slot_purgeLogs()"))
  231. self.connect(self.m_readThread, SIGNAL("updateLogs()"), SLOT("slot_updateLogs()"))
  232. def setLogsText(self, text_jack, text_a2j, text_lash, text_ladish):
  233. self.m_text_jack = text_jack
  234. self.m_text_a2j = text_a2j
  235. self.m_text_lash = text_lash
  236. self.m_text_ladish = text_ladish
  237. @pyqtSlot()
  238. def slot_updateLogs(self):
  239. if (self.m_firstRun):
  240. self.pte_jack.clear()
  241. self.pte_a2j.clear()
  242. self.pte_lash.clear()
  243. self.pte_ladish.clear()
  244. if (self.LOG_FILE_JACK):
  245. if (self.m_text_jack):
  246. self.pte_jack.appendPlainText(self.m_text_jack)
  247. if (self.LOG_FILE_A2J):
  248. if (self.m_text_a2j):
  249. self.pte_a2j.appendPlainText(self.m_text_a2j)
  250. if (self.LOG_FILE_LASH):
  251. if (self.m_text_lash):
  252. self.pte_lash.appendPlainText(self.m_text_lash)
  253. if (self.LOG_FILE_LADISH):
  254. if (self.m_text_ladish):
  255. self.pte_ladish.appendPlainText(self.m_text_ladish)
  256. if (self.m_firstRun):
  257. self.pte_jack.horizontalScrollBar().setValue(0)
  258. self.pte_jack.verticalScrollBar().setValue(self.pte_jack.verticalScrollBar().maximum())
  259. self.pte_a2j.horizontalScrollBar().setValue(0)
  260. self.pte_a2j.verticalScrollBar().setValue(self.pte_a2j.verticalScrollBar().maximum())
  261. self.pte_lash.horizontalScrollBar().setValue(0)
  262. self.pte_lash.verticalScrollBar().setValue(self.pte_lash.verticalScrollBar().maximum())
  263. self.pte_ladish.horizontalScrollBar().setValue(0)
  264. self.pte_ladish.verticalScrollBar().setValue(self.pte_ladish.verticalScrollBar().maximum())
  265. self.m_firstRun = False
  266. @pyqtSlot()
  267. def slot_purgeLogs(self):
  268. self.m_readThread.purgeLogs()
  269. self.pte_jack.clear()
  270. self.pte_a2j.clear()
  271. self.pte_lash.clear()
  272. self.pte_ladish.clear()
  273. def closeEvent(self, event):
  274. self.m_readThread.quit()
  275. return QDialog.closeEvent(self, event)
  276. # -------------------------------------------------------------
  277. # Allow to use this as a standalone app
  278. if __name__ == '__main__':
  279. # Additional imports
  280. import sys
  281. from PyQt4.QtGui import QApplication
  282. # App initialization
  283. app = QApplication(sys.argv)
  284. # Show GUI
  285. gui = LogsW(None, Qt.WindowFlags())
  286. gui.show()
  287. # App-Loop
  288. sys.exit(app.exec_())