~taiebot65/cairo-dock-plug-ins-extras/Subdock-2

« back to all changes in this revision

Viewing changes to Pulseaudio/pulseaudio/lib.py

  • Committer: taiebot65
  • Date: 2010-06-20 20:36:27 UTC
  • Revision ID: taiebot65@yahoo.fr-20100620203627-t3cx1bqi6y6t1srl
just added all the library and the beginning of this applet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2006-2008 Alex Holkner
 
2
# All rights reserved.
 
3
 
4
# Redistribution and use in source and binary forms, with or without
 
5
# modification, are permitted provided that the following conditions are met:
 
6
 
7
#   * Redistributions of source code must retain the above copyright
 
8
#     notice, this list of conditions and the following disclaimer.
 
9
#   * Redistributions in binary form must reproduce the above copyright 
 
10
#     notice, this list of conditions and the following disclaimer in
 
11
#     the documentation and/or other materials provided with the
 
12
#     distribution.
 
13
#   * Neither the name of pyglet nor the names of its
 
14
#     contributors may be used to endorse or promote products
 
15
#     derived from this software without specific prior written
 
16
#     permission.
 
17
 
18
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
19
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
20
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
21
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
22
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 
23
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
24
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
25
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
26
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
27
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 
28
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
29
# POSSIBILITY OF SUCH DAMAGE.
 
30
 
 
31
 
 
32
import os
 
33
import re
 
34
import sys
 
35
 
 
36
import ctypes
 
37
import ctypes.util
 
38
 
 
39
_debug_lib = False
 
40
_debug_trace = False
 
41
 
 
42
class LibraryLoader(object):
 
43
    def load_library(self, *names, **kwargs):
 
44
        '''Find and load a library.  
 
45
        
 
46
        More than one name can be specified, they will be tried in order.
 
47
        Platform-specific library names (given as kwargs) are tried first.
 
48
 
 
49
        Raises ImportError if library is not found.
 
50
        '''
 
51
        if 'framework' in kwargs and self.platform == 'darwin':
 
52
            return self.load_framework(kwargs['framework'])
 
53
        
 
54
        platform_names = kwargs.get(self.platform, [])
 
55
        if type(platform_names) in (str, unicode):
 
56
            platform_names = [platform_names]
 
57
        elif type(platform_names) is tuple:
 
58
            platform_names = list(platform_names)
 
59
 
 
60
        if self.platform == 'linux2':
 
61
            platform_names.extend(['lib%s.so' % n for n in names])
 
62
 
 
63
        platform_names.extend(names)
 
64
        for name in platform_names:
 
65
            try:
 
66
                lib = ctypes.cdll.LoadLibrary(name)
 
67
                #if _debug_lib:
 
68
                print "Loaded library :", name
 
69
                #if _debug_trace:
 
70
                #    lib = _TraceLibrary(lib)
 
71
                return lib
 
72
            except OSError:
 
73
                path = self.find_library(name)
 
74
                if path:
 
75
                    try:
 
76
                        lib = ctypes.cdll.LoadLibrary(path)
 
77
                        if _debug_lib:
 
78
                            print path
 
79
                        if _debug_trace:
 
80
                            lib = _TraceLibrary(lib)
 
81
                        return lib
 
82
                    except OSError:
 
83
                        pass
 
84
        raise ImportError('Library "%s" not found.' % names[0])
 
85
 
 
86
    find_library = lambda self, name: ctypes.util.find_library(name)
 
87
 
 
88
    platform = sys.platform
 
89
    if platform == 'cygwin':
 
90
        platform = 'win32'
 
91
 
 
92
    def load_framework(self, path):
 
93
        raise RuntimeError("Can't load framework on this platform.")
 
94