2015-04-24 08:35:14 +00:00
|
|
|
import os
|
2018-10-30 23:41:31 +00:00
|
|
|
import sys
|
|
|
|
import imp
|
2015-04-15 17:57:43 +00:00
|
|
|
|
2018-10-30 23:41:31 +00:00
|
|
|
class GstOverrideImport:
|
|
|
|
def find_module(self, fullname, path=None):
|
|
|
|
if fullname in ('gi.overrides.Gst', 'gi.overrides._gi_gst'):
|
|
|
|
return self
|
|
|
|
return None
|
2017-07-25 20:18:26 +00:00
|
|
|
|
2018-10-30 23:41:31 +00:00
|
|
|
def load_module(self, name):
|
|
|
|
if name in sys.modules:
|
|
|
|
return sys.modules[name]
|
2015-04-15 17:57:43 +00:00
|
|
|
|
2018-10-30 23:41:31 +00:00
|
|
|
fp, pathname, description = imp.find_module(name.split('.')[-1], [
|
|
|
|
os.environ.get('GST_OVERRIDE_SRC_PATH'),
|
|
|
|
os.environ.get('GST_OVERRIDE_BUILD_PATH'),
|
|
|
|
])
|
2015-04-24 08:35:14 +00:00
|
|
|
|
2018-10-30 23:41:31 +00:00
|
|
|
try:
|
|
|
|
module = imp.load_module(name, fp, pathname, description)
|
|
|
|
finally:
|
|
|
|
if fp:
|
|
|
|
fp.close()
|
|
|
|
sys.modules[name] = module
|
|
|
|
return module
|
2016-11-03 14:49:15 +00:00
|
|
|
|
2018-10-31 16:02:24 +00:00
|
|
|
if sys.version_info.major >= 3:
|
|
|
|
sys.meta_path.insert(0, GstOverrideImport())
|
|
|
|
else:
|
|
|
|
import gi.overrides
|
|
|
|
|
|
|
|
gi.overrides.__path__.append(os.environ.get('GST_OVERRIDE_SRC_PATH'))
|
|
|
|
gi.overrides.__path__.append(os.environ.get('GST_OVERRIDE_BUILD_PATH'))
|