Add missing whitespace to make pep8 happy
[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
30     def __init__(self, name, path):
31         self.name = name
32         self.path = path
33
34     @staticmethod
35     def find_module(name, path=None):
36         modname = name.split('.')[-1]
37         for part in path or sys.path:
38             full = os.path.join(part, '.libs', modname + '.la')
39             if os.path.exists(full):
40                 return LibToolImporter(name, full)
41
42     def load_module(self, name):
43         realpath = extract_libtool(self.path)
44         mod = imp.load_module(name, open(realpath), realpath,
45                               ('.so', 'rb', 3))
46         return mod
47
48
49 def install_libtoolimporter():
50     sys.meta_path.append(LibToolImporter)
51
52
53 def uninstall_libtoolimporter():
54     sys.meta_path.remove(LibToolImporter)