[vlc-commits] Fix undefined del. Move lib loading to function.
Geoff Salmon
git at videolan.org
Tue Sep 13 17:24:04 CEST 2011
vlc/python | branch: master | Geoff Salmon <geoff.salmon at gmail.com> | Sun Aug 14 11:47:18 2011 -0400| [ed5d74f985d4c6914ea42a4ae4f994cfab16a5b8] | committer: Olivier Aubert
Fix undefined del. Move lib loading to function.
Moves the library loading code to a separate function so that it doesn't need to
delete unwanted globals.
Signed-off-by: Olivier Aubert <olivier.aubert at liris.cnrs.fr>
> http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=ed5d74f985d4c6914ea42a4ae4f994cfab16a5b8
---
header.py | 125 +++++++++++++++++++++++++++++++------------------------------
1 files changed, 63 insertions(+), 62 deletions(-)
diff --git a/header.py b/header.py
index 15ea345..c47f76d 100755
--- a/header.py
+++ b/header.py
@@ -52,69 +52,70 @@ build_date = '' # build time stamp and __version__, see generate.py
# instanciated.
_internal_guard = object()
- # Used on win32 and MacOS in override.py
-plugin_path = None
-
-if sys.platform.startswith('linux'):
- p = find_library('vlc')
- try:
- dll = ctypes.CDLL(p)
- except OSError: # may fail
- dll = ctypes.CDLL('libvlc.so.5')
-
-elif sys.platform.startswith('win'):
- p = find_library('libvlc.dll')
- if p is None:
- try: # some registry settings
- import _winreg as w # leaner than win32api, win32con
- for r in w.HKEY_LOCAL_MACHINE, w.HKEY_CURRENT_USER:
- try:
- r = w.OpenKey(r, 'Software\\VideoLAN\\VLC')
- plugin_path, _ = w.QueryValueEx(r, 'InstallDir')
- w.CloseKey(r)
- break
- except w.error:
- pass
- del r, w
- except ImportError: # no PyWin32
- pass
- if plugin_path is None:
- # try some standard locations.
- for p in ('Program Files\\VideoLan\\', 'VideoLan\\',
- 'Program Files\\', ''):
- p = 'C:\\' + p + 'VLC\\libvlc.dll'
- if os.path.exists(p):
- plugin_path = os.path.dirname(p)
- break
- if plugin_path is not None: # try loading
- p = os.getcwd()
- os.chdir(plugin_path)
- # if chdir failed, this will raise an exception
- dll = ctypes.CDLL('libvlc.dll')
- # restore cwd after dll has been loaded
- os.chdir(p)
- else: # may fail
- dll = ctypes.CDLL('libvlc.dll')
+def find_lib():
+ dll = None
+ plugin_path = None
+ if sys.platform.startswith('linux'):
+ p = find_library('vlc')
+ try:
+ dll = ctypes.CDLL(p)
+ except OSError: # may fail
+ dll = ctypes.CDLL('libvlc.so.5')
+ elif sys.platform.startswith('win'):
+ p = find_library('libvlc.dll')
+ if p is None:
+ try: # some registry settings
+ import _winreg as w # leaner than win32api, win32con
+ for r in w.HKEY_LOCAL_MACHINE, w.HKEY_CURRENT_USER:
+ try:
+ r = w.OpenKey(r, 'Software\\VideoLAN\\VLC')
+ plugin_path, _ = w.QueryValueEx(r, 'InstallDir')
+ w.CloseKey(r)
+ break
+ except w.error:
+ pass
+ except ImportError: # no PyWin32
+ pass
+ if plugin_path is None:
+ # try some standard locations.
+ for p in ('Program Files\\VideoLan\\', 'VideoLan\\',
+ 'Program Files\\', ''):
+ p = 'C:\\' + p + 'VLC\\libvlc.dll'
+ if os.path.exists(p):
+ plugin_path = os.path.dirname(p)
+ break
+ if plugin_path is not None: # try loading
+ p = os.getcwd()
+ os.chdir(plugin_path)
+ # if chdir failed, this will raise an exception
+ dll = ctypes.CDLL('libvlc.dll')
+ # restore cwd after dll has been loaded
+ os.chdir(p)
+ else: # may fail
+ dll = ctypes.CDLL('libvlc.dll')
+ else:
+ plugin_path = os.path.dirname(p)
+ dll = ctypes.CDLL(p)
+
+ elif sys.platform.startswith('darwin'):
+ # FIXME: should find a means to configure path
+ d = '/Applications/VLC.app/Contents/MacOS/'
+ p = d + 'lib/libvlc.dylib'
+ if os.path.exists(p):
+ dll = ctypes.CDLL(p)
+ d += 'modules'
+ if os.path.isdir(d):
+ plugin_path = d
+ else: # hope, some PATH is set...
+ dll = ctypes.CDLL('libvlc.dylib')
+
else:
- plugin_path = os.path.dirname(p)
- dll = ctypes.CDLL(p)
- del p, u
-
-elif sys.platform.startswith('darwin'):
- # FIXME: should find a means to configure path
- d = '/Applications/VLC.app/Contents/MacOS/'
- p = d + 'lib/libvlc.dylib'
- if os.path.exists(p):
- dll = ctypes.CDLL(p)
- d += 'modules'
- if os.path.isdir(d):
- plugin_path = d
- else: # hope, some PATH is set...
- dll = ctypes.CDLL('libvlc.dylib')
- del d, p
-
-else:
- raise NotImplementedError('%s: %s not supported' % (sys.argv[0], sys.platform))
+ raise NotImplementedError('%s: %s not supported' % (sys.argv[0], sys.platform))
+
+ return (dll, plugin_path)
+
+# plugin_path used on win32 and MacOS in override.py
+dll, plugin_path = find_lib()
class VLCException(Exception):
"""Exception raised by libvlc methods.
More information about the vlc-commits
mailing list