Добавлены скрипты для работы с разбитыми на фрагменты СМС
[openhab-process.git] / mqtt-pulse / DEADJOE
1
2 *** These modified files were found in JOE when it aborted on Fri Sep 23 20:31:28 2016
3 *** JOE was aborted because the terminal closed
4
5 *** Файл '(БезИмени)'
6 mqtt_pulse.py
7
8 *** Файл 'mqtt_pulse.py'
9 #!/usr/bin/python
10
11 from pulsectl import Pulse,PulseLoopStop
12
13 import threading
14
15 sink_name=None
16 muted=False
17 volume=None
18
19 paLock1=threading.RLock()
20 paLock2=threading.RLock()
21 stopFlag=False
22
23 def Init():
24   global pulse
25   pulse = Pulse("mqtt-pa")
26
27 def Reconnect():
28   pulse.close()
29   Init()
30
31 def GetDefaultOut():
32   return pulse.server_info().default_sink_name
33
34 def GetDefaultSink():
35   sinkname=GetDefaultOut()
36   for sink in pulse.sink_list():
37     if sink.name==sinkname:
38       return sink
39
40 def GetDefaultVolume():
41   return pulse.volume_get_all_chans(GetDefaultSink())
42
43 def IsDefaultMuted():
44   return GetDefaultSink().mute<>0
45   
46 def MuteDefault(mute = True):
47   return pulse.mute(GetDefaultSink(),mute)
48
49 def EventListener(callback):
50   pulse.event_mask_set('all')
51   pulse.event_callback_set(callback)
52   pulse.event_listen()
53
54 def EventProcess(ev):
55   raise PulseLoopStop
56
57 def AcquirePALock():
58   paLock1.acquire()
59   
60   pulse.event_listen_stop()
61   paLock2.acquire()
62
63 def ReleasePALock():
64   paLock2.release()
65   paLock1.release()
66
67 def StateProcess():
68   global sink_name,muted,volume
69   try:
70     tname=threading.current_thread().name
71 #    print tname+">trying to aquire lock"
72     AcquirePALock()
73 #    print tname+">lock aquired"
74     current_sink=GetDefaultOut()
75     current_vol=round(GetDefaultVolume(),2)
76     current_muted=IsDefaultMuted()
77     if current_sink<>sink_name:
78       sink_name=current_sink
79       print tname+">sink: "+sink_name
80     if current_vol<>volume:
81       volume=current_vol
82       print tname+">volume: "+str(volume)
83     if current_muted<>muted:
84       muted=current_muted
85       print tname+">muted: "+str(muted)
86   finally:
87     ReleasePALock()
88 #    print tname+">lock released"
89
90 def PAListener():
91   while not stopFlag:    
92 #    print "entering wait loop"
93     EventListener(EventProcess)
94 #    print "event or break happened"
95     StateProcess()
96
97 def RunBackground(process):
98   stopFlag=False
99   thread = threading.Thread(target=process,name="Background")
100   thread.start()
101
102 def StopBackground():
103   global stopFlag
104   stopFlag=True
105   pulse.event_listen_stop()
106
107 def CommandGetDefaultOut():
108   try:
109     tname=threading.current_thread().name
110 #    print tname+">trying to aquire lock"
111     AcquirePALock()
112 #    print tname+">lock aquired"
113     result=GetDefaultOut()
114   finally:
115     ReleasePALock()
116 #    print tname+">lock released"
117   return result
118
119 def CommandGetDefaultVolume():
120   try:
121     tname=threading.current_thread().name
122 #    print tname+">trying to aquire lock"
123     AcquirePALock()
124 #    print tname+">lock aquired"
125     result=GetDefaultVolume()
126   finally:
127     ReleasePALock()
128 #    print tname+">lock released"
129   return result
130
131 def CommandIsDefaultMuted():
132   try:
133     tname=threading.current_thread().name
134 #    print tname+">trying to aquire lock"
135     AcquirePALock()
136 #    print tname+">lock aquired"
137     result=IsDefaultMuted()
138   finally:
139     ReleasePALock()
140 #    print tname+">lock released"
141   return result
142   
143 *** Файл '* Startup Log *'
144 Processing '/etc/joe/joerc'...
145 Processing '/etc/joe/ftyperc'...
146 Finished processing /etc/joe/ftyperc
147 Finished processing /etc/joe/joerc