mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
Fix uninstalled usage with python 2.6. Fixes #576546
Also imports submodules as mentionned by Philippe Normand.
This commit is contained in:
parent
b25600a8f7
commit
1cd54e6d45
4 changed files with 127 additions and 86 deletions
|
@ -21,12 +21,11 @@
|
|||
#
|
||||
# Author: David I. Lehn <dlehn@users.sourceforge.net>
|
||||
|
||||
__gstltihooks_used__ = False
|
||||
try:
|
||||
import gstltihooks
|
||||
__gstltihooks_used__ = True
|
||||
except:
|
||||
pass
|
||||
import gstlibtoolimporter
|
||||
gstlibtoolimporter.install()
|
||||
except ImportError:
|
||||
gstlibtoolimporter = None
|
||||
|
||||
import sys
|
||||
|
||||
|
@ -155,7 +154,6 @@ class Fraction(Value):
|
|||
def __float__(self):
|
||||
return float(self.num) / float(self.denom)
|
||||
|
||||
import sys
|
||||
try:
|
||||
dlsave = sys.getdlopenflags()
|
||||
from DLFCN import RTLD_GLOBAL, RTLD_LAZY
|
||||
|
@ -220,10 +218,11 @@ if locals().has_key("message_new_buffering"):
|
|||
# with other people's module importers
|
||||
# it also clears out the module completely as if it were never loaded,
|
||||
# so that if anyone else imports gstltihooks the hooks get installed
|
||||
if __gstltihooks_used__:
|
||||
gstltihooks.uninstall()
|
||||
__gstltihooks_used__ = False
|
||||
del gstltihooks
|
||||
if gstlibtoolimporter is not None:
|
||||
import audio
|
||||
import pbutils
|
||||
import tag
|
||||
import video
|
||||
gstlibtoolimporter.uninstall()
|
||||
import sys
|
||||
del sys.modules['gstltihooks']
|
||||
|
||||
del sys.modules["gstlibtoolimporter"]
|
||||
|
|
112
gstlibtoolimporter.py
Normal file
112
gstlibtoolimporter.py
Normal file
|
@ -0,0 +1,112 @@
|
|||
# -*- Mode: Python -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
#
|
||||
# gst-python
|
||||
# Copyright (C) 2009 Alessandro Decina <alessandro.decina@collbora.co.uk>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Library General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Library General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Library General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author: Alessandro Decina <alessandro.decina@collabora.co.uk>
|
||||
|
||||
# importer for uninstalled setup, see PEP
|
||||
# http://www.python.org/dev/peps/pep-0302/
|
||||
|
||||
import os
|
||||
import sys
|
||||
import imp
|
||||
|
||||
class Loader(object):
|
||||
def __init__(self, fileobj, filename, description):
|
||||
self.fileobj = fileobj
|
||||
self.filename = filename
|
||||
self.description = description
|
||||
|
||||
def find_real_filename(self):
|
||||
dlname = None
|
||||
installed = False
|
||||
for line in self.fileobj:
|
||||
if len(line) > 7 and line[:7] == 'dlname=':
|
||||
dlname = line[8:-2]
|
||||
elif len(line) > 10 and line[:10] == 'installed=':
|
||||
installed = line[10:-1] == 'yes'
|
||||
|
||||
if not dlname:
|
||||
return None
|
||||
|
||||
if installed or os.path.dirname(self.filename).endswith('.libs'):
|
||||
filename = os.path.join(os.path.dirname(self.filename), dlname)
|
||||
else:
|
||||
filename = os.path.join(os.path.dirname(self.filename), '.libs', dlname)
|
||||
|
||||
return filename
|
||||
|
||||
def load_module(self, name):
|
||||
try:
|
||||
module = sys.modules[name]
|
||||
self.fileobj.close()
|
||||
|
||||
return module
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
filename = self.find_real_filename()
|
||||
self.fileobj.close()
|
||||
if filename is None:
|
||||
raise ImportError("No module named %s" % name)
|
||||
|
||||
fileobj = file(filename, 'rb')
|
||||
|
||||
module = imp.new_module(name)
|
||||
sys.modules[name] = module
|
||||
|
||||
imp.load_module(name, fileobj, filename, self.description)
|
||||
fileobj.close()
|
||||
|
||||
return module
|
||||
|
||||
class Importer(object):
|
||||
def find_module(self, name, path=None):
|
||||
if path is None:
|
||||
path = sys.path
|
||||
|
||||
for directory in path:
|
||||
fileobj, filename, description = self.find_libtool_module(name, directory)
|
||||
if fileobj is not None:
|
||||
return Loader(fileobj, filename, description)
|
||||
|
||||
return None
|
||||
|
||||
def find_libtool_module(self, name, directory):
|
||||
name = name.split(".")[-1]
|
||||
absname = os.path.join(directory, name)
|
||||
for suffix in ('.la', '.module.la'):
|
||||
filename = absname + suffix
|
||||
try:
|
||||
fileobj = file(filename, 'rb')
|
||||
except IOError:
|
||||
continue
|
||||
|
||||
return fileobj, filename, (suffix, 'rb', imp.C_EXTENSION)
|
||||
|
||||
return None, None, None
|
||||
|
||||
importer = Importer()
|
||||
|
||||
def install():
|
||||
sys.meta_path.append(importer)
|
||||
|
||||
def uninstall():
|
||||
sys.meta_path.remove(importer)
|
|
@ -1,71 +0,0 @@
|
|||
# -*- Mode: Python -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
# ltihooks.py: python import hooks that understand libtool libraries.
|
||||
# Copyright (C) 2000 James Henstridge.
|
||||
# renamed to gstltihooks.py so it does not accidentally get imported by
|
||||
# an installed copy of gtk
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import os, ihooks
|
||||
|
||||
class LibtoolHooks(ihooks.Hooks):
|
||||
def get_suffixes(self):
|
||||
"""Like normal get_suffixes, but adds .la suffixes to list"""
|
||||
ret = ihooks.Hooks.get_suffixes(self)
|
||||
ret.insert(0, ('module.la', 'rb', 3))
|
||||
ret.insert(0, ('.la', 'rb', 3))
|
||||
return ret
|
||||
|
||||
def load_dynamic(self, name, filename, file=None):
|
||||
"""Like normal load_dynamic, but treat .la files specially"""
|
||||
if len(filename) > 3 and filename[-3:] == '.la':
|
||||
fp = open(filename, 'r')
|
||||
dlname = ''
|
||||
installed = 1
|
||||
line = fp.readline()
|
||||
while line:
|
||||
# dlname: the name that we can dlopen
|
||||
if len(line) > 7 and line[:7] == 'dlname=':
|
||||
dlname = line[8:-2]
|
||||
# installed: whether it's already installed
|
||||
elif len(line) > 10 and line[:10] == 'installed=':
|
||||
installed = line[10:-1] == 'yes'
|
||||
line = fp.readline()
|
||||
fp.close()
|
||||
if dlname:
|
||||
if installed:
|
||||
filename = os.path.join(os.path.dirname(filename),
|
||||
dlname)
|
||||
else:
|
||||
# if .libs already there, don't need to add it again
|
||||
if os.path.dirname(filename).endswith('.libs'):
|
||||
filename = os.path.join(os.path.dirname(filename),
|
||||
dlname)
|
||||
else:
|
||||
filename = os.path.join(os.path.dirname(filename),
|
||||
'.libs', dlname)
|
||||
return ihooks.Hooks.load_dynamic(self, name, filename, file)
|
||||
|
||||
importer = ihooks.ModuleImporter()
|
||||
importer.set_hooks(LibtoolHooks())
|
||||
|
||||
def install():
|
||||
importer.install()
|
||||
def uninstall():
|
||||
importer.uninstall()
|
||||
|
||||
install()
|
|
@ -89,10 +89,11 @@ except ImportError:
|
|||
file = gst.pbutils.__file__
|
||||
assert file.startswith(path), 'bad gst.pbutils path: %s' % file
|
||||
|
||||
# testhelper needs gstltihooks
|
||||
import gstltihooks
|
||||
# testhelper needs gstlibtoolimporter
|
||||
import gstlibtoolimporter
|
||||
gstlibtoolimporter.install()
|
||||
import testhelper
|
||||
gstltihooks.uninstall()
|
||||
gstlibtoolimporter.uninstall()
|
||||
|
||||
_stderr = None
|
||||
|
||||
|
|
Loading…
Reference in a new issue