]> granicus.if.org Git - python/commitdiff
Add missing svn properties.
authorThomas Heller <theller@ctypes.org>
Fri, 12 May 2006 18:16:03 +0000 (18:16 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 12 May 2006 18:16:03 +0000 (18:16 +0000)
Lib/ctypes/util.py

index 4b8057ee62678903942e69254027c2ff591af4ca..d756c1c75fb8e657077a2994f19d8060b97c41f3 100644 (file)
-import sys, os\r
-import ctypes\r
-\r
-# find_library(name) returns the pathname of a library, or None.\r
-if os.name == "nt":\r
-    def find_library(name):\r
-        # See MSDN for the REAL search order.\r
-        for directory in os.environ['PATH'].split(os.pathsep):\r
-            fname = os.path.join(directory, name)\r
-            if os.path.exists(fname):\r
-                return fname\r
-            if fname.lower().endswith(".dll"):\r
-                continue\r
-            fname = fname + ".dll"\r
-            if os.path.exists(fname):\r
-                return fname\r
-        return None\r
-\r
-if os.name == "ce":\r
-    # search path according to MSDN:\r
-    # - absolute path specified by filename\r
-    # - The .exe launch directory\r
-    # - the Windows directory\r
-    # - ROM dll files (where are they?)\r
-    # - OEM specified search path: HKLM\Loader\SystemPath\r
-    def find_library(name):\r
-        return name\r
-\r
-if os.name == "posix" and sys.platform == "darwin":\r
-    from ctypes.macholib.dyld import dyld_find as _dyld_find\r
-    def find_library(name):\r
-        possible = ['lib%s.dylib' % name,\r
-                    '%s.dylib' % name,\r
-                    '%s.framework/%s' % (name, name)]\r
-        for name in possible:\r
-            try:\r
-                return _dyld_find(name)\r
-            except ValueError:\r
-                continue\r
-        return None\r
-\r
-elif os.name == "posix":\r
-    # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump\r
-    import re, tempfile\r
-\r
-    def _findLib_gcc(name):\r
-        expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name\r
-        cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \\r
-              '$CC -Wl,-t -o /dev/null 2>&1 -l' + name\r
-        try:\r
-            fdout, outfile =  tempfile.mkstemp()\r
-            fd = os.popen(cmd)\r
-            trace = fd.read()\r
-            err = fd.close()\r
-        finally:\r
-            try:\r
-                os.unlink(outfile)\r
-            except OSError, e:\r
-                if e.errno != errno.ENOENT:\r
-                    raise\r
-        res = re.search(expr, trace)\r
-        if not res:\r
-            return None\r
-        return res.group(0)\r
-\r
-    def _findLib_ld(name):\r
-        expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name\r
-        res = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read())\r
-        if not res:\r
-            # Hm, this works only for libs needed by the python executable.\r
-            cmd = 'ldd %s 2>/dev/null' % sys.executable\r
-            res = re.search(expr, os.popen(cmd).read())\r
-            if not res:\r
-                return None\r
-        return res.group(0)\r
-\r
-    def _get_soname(f):\r
-        cmd = "objdump -p -j .dynamic 2>/dev/null " + f\r
-        res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())\r
-        if not res:\r
-            return None\r
-        return res.group(1)\r
-\r
-    def find_library(name):\r
-        lib = _findLib_ld(name) or _findLib_gcc(name)\r
-        if not lib:\r
-            return None\r
-        return _get_soname(lib)\r
-\r
-################################################################\r
-# test code\r
-\r
-def test():\r
-    from ctypes import cdll\r
-    if os.name == "nt":\r
-        print cdll.msvcrt\r
-        print cdll.load("msvcrt")\r
-        print find_library("msvcrt")\r
-\r
-    if os.name == "posix":\r
-        # find and load_version\r
-        print find_library("m")\r
-        print find_library("c")\r
-        print find_library("bz2")\r
-\r
-        # getattr\r
-##        print cdll.m\r
-##        print cdll.bz2\r
-\r
-        # load\r
-        if sys.platform == "darwin":\r
-            print cdll.LoadLibrary("libm.dylib")\r
-            print cdll.LoadLibrary("libcrypto.dylib")\r
-            print cdll.LoadLibrary("libSystem.dylib")\r
-            print cdll.LoadLibrary("System.framework/System")\r
-        else:\r
-            print cdll.LoadLibrary("libm.so")\r
-            print cdll.LoadLibrary("libcrypt.so")\r
-            print find_library("crypt")\r
-\r
-if __name__ == "__main__":\r
-    test()\r
+import sys, os
+import ctypes
+
+# find_library(name) returns the pathname of a library, or None.
+if os.name == "nt":
+    def find_library(name):
+        # See MSDN for the REAL search order.
+        for directory in os.environ['PATH'].split(os.pathsep):
+            fname = os.path.join(directory, name)
+            if os.path.exists(fname):
+                return fname
+            if fname.lower().endswith(".dll"):
+                continue
+            fname = fname + ".dll"
+            if os.path.exists(fname):
+                return fname
+        return None
+
+if os.name == "ce":
+    # search path according to MSDN:
+    # - absolute path specified by filename
+    # - The .exe launch directory
+    # - the Windows directory
+    # - ROM dll files (where are they?)
+    # - OEM specified search path: HKLM\Loader\SystemPath
+    def find_library(name):
+        return name
+
+if os.name == "posix" and sys.platform == "darwin":
+    from ctypes.macholib.dyld import dyld_find as _dyld_find
+    def find_library(name):
+        possible = ['lib%s.dylib' % name,
+                    '%s.dylib' % name,
+                    '%s.framework/%s' % (name, name)]
+        for name in possible:
+            try:
+                return _dyld_find(name)
+            except ValueError:
+                continue
+        return None
+
+elif os.name == "posix":
+    # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
+    import re, tempfile
+
+    def _findLib_gcc(name):
+        expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name
+        cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \
+              '$CC -Wl,-t -o /dev/null 2>&1 -l' + name
+        try:
+            fdout, outfile =  tempfile.mkstemp()
+            fd = os.popen(cmd)
+            trace = fd.read()
+            err = fd.close()
+        finally:
+            try:
+                os.unlink(outfile)
+            except OSError, e:
+                if e.errno != errno.ENOENT:
+                    raise
+        res = re.search(expr, trace)
+        if not res:
+            return None
+        return res.group(0)
+
+    def _findLib_ld(name):
+        expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name
+        res = re.search(expr, os.popen('/sbin/ldconfig -p 2>/dev/null').read())
+        if not res:
+            # Hm, this works only for libs needed by the python executable.
+            cmd = 'ldd %s 2>/dev/null' % sys.executable
+            res = re.search(expr, os.popen(cmd).read())
+            if not res:
+                return None
+        return res.group(0)
+
+    def _get_soname(f):
+        cmd = "objdump -p -j .dynamic 2>/dev/null " + f
+        res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read())
+        if not res:
+            return None
+        return res.group(1)
+
+    def find_library(name):
+        lib = _findLib_ld(name) or _findLib_gcc(name)
+        if not lib:
+            return None
+        return _get_soname(lib)
+
+################################################################
+# test code
+
+def test():
+    from ctypes import cdll
+    if os.name == "nt":
+        print cdll.msvcrt
+        print cdll.load("msvcrt")
+        print find_library("msvcrt")
+
+    if os.name == "posix":
+        # find and load_version
+        print find_library("m")
+        print find_library("c")
+        print find_library("bz2")
+
+        # getattr
+##        print cdll.m
+##        print cdll.bz2
+
+        # load
+        if sys.platform == "darwin":
+            print cdll.LoadLibrary("libm.dylib")
+            print cdll.LoadLibrary("libcrypto.dylib")
+            print cdll.LoadLibrary("libSystem.dylib")
+            print cdll.LoadLibrary("System.framework/System")
+        else:
+            print cdll.LoadLibrary("libm.so")
+            print cdll.LoadLibrary("libcrypt.so")
+            print find_library("crypt")
+
+if __name__ == "__main__":
+    test()