OpenShot Video Editor  2.0.0
logger_libopenshot.py
Go to the documentation of this file.
1 ##
2 #
3 # @file
4 # @brief This file connects to libopenshot and logs debug messages (if debug preference enabled)
5 # @author Jonathan Thomas <jonathan@openshot.org>
6 #
7 # @section LICENSE
8 #
9 # Copyright (c) 2008-2018 OpenShot Studios, LLC
10 # (http://www.openshotstudios.com). This file is part of
11 # OpenShot Video Editor (http://www.openshot.org), an open-source project
12 # dedicated to delivering high quality video editing and animation solutions
13 # to the world.
14 #
15 # OpenShot Video Editor is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
19 #
20 # OpenShot Video Editor is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
27 #
28 
29 from threading import Thread
30 from classes import settings, info
31 from classes.logger import log
32 import openshot
33 import os
34 import zmq
35 
36 
37 class LoggerLibOpenShot(Thread):
38 
39  def kill(self):
40  self.running = False
41 
42  def run(self):
43  # Running
44  self.running = True
45 
46  # Get settings
48 
49  # Get port from settings
50  port = s.get("debug-port")
51  debug_enabled = s.get("debug-mode")
52 
53  # Set port on ZmqLogger singleton
54  openshot.ZmqLogger.Instance().Connection("tcp://*:%s" % port)
55 
56  # Set filepath for ZmqLogger also
57  openshot.ZmqLogger.Instance().Path(os.path.join(info.USER_PATH, 'libopenshot.log'))
58 
59  # Enable / Disable logger
60  openshot.ZmqLogger.Instance().Enable(debug_enabled)
61 
62  # Socket to talk to server
63  context = zmq.Context()
64  socket = context.socket(zmq.SUB)
65  socket.setsockopt_string(zmq.SUBSCRIBE, '')
66 
67  poller = zmq.Poller()
68  poller.register(socket, zmq.POLLIN)
69 
70  log.info("Connecting to libopenshot with debug port: %s" % port)
71  socket.connect ("tcp://localhost:%s" % port)
72 
73  while self.running:
74  msg = None
75 
76  # Receive all debug message sent from libopenshot (if any)
77  socks = dict(poller.poll(1000))
78  if socks:
79  if socks.get(socket) == zmq.POLLIN:
80  msg = socket.recv(zmq.NOBLOCK)
81 
82  # Log the message (if any)
83  if msg:
84  log.info(msg.strip().decode('UTF-8'))
def get_settings
Get the current QApplication's settings instance.
Definition: settings.py:44