Remove leftover raise SystemExit.
[platform/upstream/gobject-introspection.git] / giscanner / libtoolimporter.py
1 # -*- Mode: Python -*-
2 # GObject-Introspection - a framework for introspecting GObject libraries
3 # Copyright (C) 2008  Johan Dahlin
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
19 #
20
21 import imp
22 import os
23 import sys
24
25 from .utils import extract_libtool
26
27
28 class LibToolImporter(object):
29     def __init__(self, name, path):
30         self.name = name
31         self.path = path
32
33     @staticmethod
34     def find_module(name, path=None):
35         modname = name.split('.')[-1]
36         for part in path or sys.path:
37             full = os.path.join(part, '.libs', modname + '.la')
38             if os.path.exists(full):
39                 return LibToolImporter(name, full)
40
41     def load_module(self, name):
42         realpath = extract_libtool(self.path)
43         mod = imp.load_module(name, open(realpath), realpath,
44                               ('.so', 'rb', 3))
45         return mod
46
47 def install_libtoolimporter():
48     sys.meta_path.append(LibToolImporter)
49
50 def uninstall_libtoolimporter():
51     sys.meta_path.remove(LibToolImporter)