This file is indexed.

/usr/share/pyshared/ecacontrol.py is in python-ecasound 2.9.1-7ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"""Native python ECI (ecasound control interface) implementation

   Can be used to replace the C implementation 'pyecasound.so'.
"""

authors="""Kai Vehmanen, Eric S. Tiedemann and Janne Halttunen."""

import sys
if sys.hexversion < 0x02040000:
    print >>sys.stderr, "ERROR: Python 2.4 or newer is required by ecacontrol.py"
    sys.exit(-1)

import re
import subprocess
from select import select
import os
import signal
import string
import time

_ecasound=[]

type_override={}
eci_str_sync_lost= 'Connection to the processing engine was lost.\n'

class ECA_CONTROL_INTERFACE:
    
    def __init__(I, verbose=1):
        """Instantiate new ECI session
        
        verbose: set this false to get rid of startup-messages
        """

        I.verbose=verbose
        I._cmd=''
        I._type=''
        I._timeout=5 # in seconds
        I._resp={}
        I.initialize()
        
    def __call__(I, cmd, f=None):
        if f != None:
            val=I.command_float_arg(cmd, f)
        else:
            cmds=string.split(cmd, '\n')
            if len(cmds) > 1:
                v=[]
                for c in cmds:
                    c=string.strip(c)
                    if c:
                        v.append(I.command(c))
                    
                        if I.error():
                            raise Exception(v[-1])
                    
                val=string.join(map(str, v), '\n')
            else:
                val=I.command(cmd)
                    
        if I.error():
            raise Exception(val)
        
        return val            

    def _readline(I):
        return string.strip(I.eca.stdout.readline())
        
    def _read_eca(I):
        buffer=''
        while select([I.eca.stdout.fileno()],[],[I.eca.stdout.fileno()],0.01)[0]:
           buffer=buffer+I.eca.stdout.read(1)
        return buffer
    
    def _parse_response(I):
        tm=''; r=(); failcount=0
        if I.verbose > 2:
            print 'c=' + I._cmd
        while 1:
            
            s=I._read_eca()
            #print 'read s=' + s
            if s:
                if I.verbose > 3:
                    print 's=<', s, '>'
            else:
                failcount = failcount + 1
                if failcount < I._timeout * 10:
                #if failcount < 0:
                    time.sleep(0.01)
                    continue
                else:
                    print 'timeout: s=<' + s, '>, cmd=' + I._cmd + '.'
                    r=('e', eci_str_sync_lost)
                    break
            tm=tm+s
            m=expand_eiam_response(tm)
            r=parse_eiam_response(tm, m)
            if r:
                if I.verbose > 2:
                    print 'r=', r
                break

        if not r:
            I._resp['e']='-'            
            I._type='e'
            r=None
        else:
            I._type=r[0]
            
            if I._cmd in type_override.keys():
                I._type=type_override[I._cmd]
            
            if I._type == 'S':
                    I._resp[I._type]=string.split(r[1], ',')            
            elif I._type == 'Sn':
                    I._resp[I._type]=string.split(r[1], '\n')
            elif I._type == 'f':
                    I._resp[I._type]=float(r[1])
            elif I._type == 'i':
                    I._resp[I._type]=int(r[1])
            elif I._type == 'li':
                    I._resp[I._type]=long(r[1])
            else:
                    I._resp[I._type]=r[1]

        return I._resp[I._type]

    
    def initialize(I):
        """Reserve resources"""
                
##        if _ecasound is not None:
##            I.cleanup()             # exit previous ecasound session cleanly
           
        global _ecasound

        try:
            ecasound_binary = os.environ['ECASOUND']
        except KeyError:
            ecasound_binary = ''

        if ecasound_binary == '':
            ecasound_binary = 'ecasound'

        p = subprocess.Popen(ecasound_binary + ' -c -d:256 2>/dev/null',
                             shell=True, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
        _ecasound.append(p)
        
        I.eca=_ecasound[-1]
        
        lines=''
        
        lines=lines+I._readline()+'\n'

        version=I._readline()
            
        s=string.find(version, 'ecasound v')
        if float(version[s+10:s+13])>=2.2:
            lines=lines+version+'\n'
        else:
            raise RuntimeError('ecasound version 2.2 required!')
        
        lines=lines+I._readline()+'\n'
        
        if I.verbose:
            print lines
            print __doc__
            print 'by', authors
            print '\n(to get rid of this message, pass zero to instance init)'
            
        I.command('int-output-mode-wellformed')
        #I._read_eca()
        #I.command('debug 256')
        
    def cleanup(I):
        """Free all reserved resources"""
        
        I.eca.stdin.write('quit\n')

        os.kill(I.eca.pid, signal.SIGTERM)
                
        signal.signal(signal.SIGALRM, handler)
        signal.alarm(2)
        
        try:
            return I.eca.wait()
        except:
            pass
        
        signal.alarm(0)
        os.kill(I.eca.pid, signal.SIGKILL)
        
        
    def command(I,cmd):
        """Issue an EIAM command"""
        
        cmd=string.strip(cmd)
        if cmd:
            I._cmd=cmd
            I.eca.stdin.write(cmd+'\n')
            return I._parse_response()
        
    def command_float_arg(I,cmd,f=None):
        """Issue an EIAM command
        
        This function can be used instead of command(string), 
        if the command in question requires exactly one numerical parameter."""
        
        cmd=string.strip(cmd)
        if cmd:
            I._cmd=cmd
            if f:
                    I.eca.stdin.write('%s %f\n' % (cmd,f))
            else:
                    I.eca.stdin.write(cmd+'\n')
            return I._parse_response()
            
    def error(I):
        """Return true if error has occured during the execution of last EIAM command"""
        
        if I._type=='e': return 1
        
    def last_error(I):
        """Return a string describing the last error"""
        
        if I.error():
            return I._resp.get('e')
        else: 
            return ''
        
    def last_float(I):
        """Return the last floating-point return value"""
        return I._resp.get('f')
    
    def last_integer(I):
        """Return the last integer return value
        
        This function is also used to return boolean values."""
        return I._resp.get('i')
    
    def last_long_integer(I):
        """Return the last long integer return value
        
        Long integers are used to pass values like 'length_in_samples' 
        and 'length_in_bytes'.  It's implementation specific whether there's 
        any real difference between integers and long integers."""
        return I._resp.get('li')
    
    def last_string(I):
        """Return the last string return value"""
        return I._resp.get('s')
    
    def last_string_list(I):
        """Return the last collection of strings (one or more strings)"""
        return I._resp.get('S')
    
    def last_type(I):
        return I._type
    
    def current_event(I):
        """** not implemented **"""
        pass
    def events_available(I): 
        """** not implemented **"""
        pass
    def next_event(I): 
        """** not implemented **"""
        pass


def handler(*args):
    print 'AARGH!'
    raise Exception, 'killing me not so softly'

expand=re.compile('256 ([0-9]{1,5}) (.+)\r\n(.*)\r\n\r\n.*', re.MULTILINE | re.S)

def expand_eiam_response(st):
    """Checks wheter 'str' is a valid EIAM response.

    @return Regex match object.
    """

    m = expand.search(st)
    return m

parse=re.compile('256 ([0-9]{1,5}) (.+)\r\n(.*)', re.MULTILINE | re.S)

def parse_eiam_response(st, m=None):
    """Parses a valid EIAM response.

    @param m Valid regex match object.
    @param str The whole EIAM response.

    @return tuple of return value type and value
    """

    if not m:
        m = parse.search(st)
        if not m:
            return ()

    if m and len(m.groups()) == 0:
        #print "(pyeca) Matching groups failed: %s" % str(m.groups())
        return ('e','Matching groups failed')

    if m and len(m.groups()) == 3:
        #print 'received=', len(m.group(3)), ', expected=', m.group(1)
        if int(m.group(1)) != len(m.group(3)):
            print '(pyeca) Response length error. Received ', len(m.group(3)), ', expected for ', m.group(1), '.'
            #print 'g=', m.group(3)
            return ('e', 'Response length error.')

    if m:
        return (m.group(2), m.group(3))

    return ('e','')


class base:
    def __init__(I, eci, cmd):
        I.eci=eci
        I.cmd=string.replace(cmd, '_', '-')

    def __call__(I):
        return I.eci(I.cmd)

class string_argument(base):
    def __call__(I, s):
        return I.eci('%s %s' % (I.cmd,s))

class EIAM:
    def __init__(I, verbose=0):
        I._eci=ECA_CONTROL_INTERFACE(verbose)
        I._cmds=I._eci('int-cmd-list')

        for c in I._cmds:
            c=string.replace(c, '-', '_')
            if string.count(c, 'add') \
            or string.count(c, 'select'):
                I.__dict__[c]=string_argument(I._eci,c)
            else:
                I.__dict__[c]=base(I._eci,c)

def main():
    e=ECA_CONTROL_INTERFACE()
    print e.command('c-add huppaa')
    print e.command('c-list')

    print e("""

    c-list
    c-status
    """)

    print e.cleanup()

if __name__ == '__main__':
    main()