-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_gdbus_proxy_service.py
208 lines (166 loc) · 6.31 KB
/
test_gdbus_proxy_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# NOTE: This is the new task_runner
# NOTE: [02/21/2016]
import os
import sys
import time
import argparse
import pprint
pp = pprint.PrettyPrinter(indent=4)
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject
from gi.repository import Gst
from gi.repository import GLib
from gi.repository import Gio
import threading
from pydbus import SessionBus
GObject.threads_init()
Gst.init(None)
print '********************************************************'
print 'GObject: '
pp.pprint(GObject.pygobject_version)
print ''
print 'Gst: '
pp.pprint(Gst.version_string())
print '********************************************************'
Gst.debug_set_active(True)
Gst.debug_set_default_threshold(3)
import StringIO
import re
import ConfigParser
import signal
from IPython.core.debugger import Tracer
from IPython.core import ultratb
sys.excepthook = ultratb.FormattedTB(mode='Verbose',
color_scheme='Linux',
call_pdb=True,
ostream=sys.__stdout__)
from colorlog import ColoredFormatter
import logging
import scarlett_config
from gettext import gettext as _
gst = Gst
SCARLETT_DEBUG = False
def setup_logger():
"""Return a logger with a default ColoredFormatter."""
formatter = ColoredFormatter(
"(%(threadName)-9s) %(log_color)s%(levelname)-8s%(reset)s %(message_log_color)s%(message)s",
datefmt=None,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red',
},
secondary_log_colors={
'message': {
'ERROR': 'red',
'CRITICAL': 'red',
'DEBUG': 'yellow'
}
},
style='%'
)
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
return logger
logger = setup_logger()
# NOTE: enumerate req to iterate through tuple and find GVariant
def player_cb(*args, **kwargs):
if SCARLETT_DEBUG:
logger.debug("player_cb PrettyPrinter: ")
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(args)
for i, v in enumerate(args):
if SCARLETT_DEBUG:
logger.debug(f"Type v: {type(v)}")
logger.debug(f"Type i: {type(i)}")
if type(v) is gi.overrides.GLib.Variant:
if SCARLETT_DEBUG:
logger.debug(f"THIS SHOULD BE A Tuple now: {v}")
msg, scarlett_sound = v
logger.warning(f" msg: {msg}")
logger.warning(f" scarlett_sound: {scarlett_sound}")
# NOTE: enumerate req to iterate through tuple and find GVariant
def command_cb(*args, **kwargs):
if SCARLETT_DEBUG:
logger.debug("player_cb PrettyPrinter: ")
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(args)
for i, v in enumerate(args):
if SCARLETT_DEBUG:
logger.debug(f"Type v: {type(v)}")
logger.debug(f"Type i: {type(i)}")
if type(v) is gi.overrides.GLib.Variant:
if SCARLETT_DEBUG:
logger.debug(f"THIS SHOULD BE A Tuple now: {v}")
msg, scarlett_sound, command = v
logger.warning(f" msg: {msg}")
logger.warning(f" scarlett_sound: {scarlett_sound}")
logger.warning(f" command: {command}")
# with SessionBus() as bus:
bus = SessionBus()
# bus.watch_name("org.scarlett.Listener.SttFailedSignal", 0, player_cb)
ss = bus.get("org.scarlett", object_path='/org/scarlett/Listener')
# SttFailedSignal / player_cb
ss_failed_signal = bus.con.signal_subscribe(None,
"org.scarlett.Listener",
"SttFailedSignal",
'/org/scarlett/Listener',
None,
0,
player_cb)
# ss.emitConnectedToListener("ScarlettProxy")
# ListenerReadySignal / player_cb
ss_rdy_signal = bus.con.signal_subscribe(None,
"org.scarlett.Listener",
"ListenerReadySignal",
'/org/scarlett/Listener',
None,
0,
player_cb)
# KeywordRecognizedSignal / player_cb
ss_kw_rec_signal = bus.con.signal_subscribe(None,
"org.scarlett.Listener",
"KeywordRecognizedSignal",
'/org/scarlett/Listener',
None,
0,
player_cb)
# CommandRecognizedSignal /command_cb
ss_cmd_rec_signal = bus.con.signal_subscribe(None,
"org.scarlett.Listener",
"CommandRecognizedSignal",
'/org/scarlett/Listener',
None,
0,
command_cb)
# ListenerCancelSignal / player_cb
ss_cancel_signal = bus.con.signal_subscribe(None,
"org.scarlett.Listener",
"ListenerCancelSignal",
'/org/scarlett/Listener',
None,
0,
player_cb)
logger.debug("ss PrettyPrinter: ")
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ss)
def sigint_handler(*args):
"""Exit on Ctrl+C"""
# Unregister handler, next Ctrl-C will kill app
# TOD: figure out if this is really needed or not
signal.signal(signal.SIGINT, signal.SIG_DFL)
GLib.MainLoop().quit()
signal.signal(signal.SIGINT, sigint_handler)
try:
GLib.MainLoop().run()
finally:
print 'Proxy text finished'