1
|
1 |
# Copyright (C) 2005, Giovanni Bajo
|
|
2 |
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or
|
|
5 |
# modify it under the terms of the GNU General Public License
|
|
6 |
# as published by the Free Software Foundation; either version 2
|
|
7 |
# of the License, or (at your option) any later version.
|
|
8 |
#
|
|
9 |
# In addition to the permissions in the GNU General Public License, the
|
|
10 |
# authors give you unlimited permission to link or embed the compiled
|
|
11 |
# version of this file into combinations with other programs, and to
|
|
12 |
# distribute those combinations without any restriction coming from the
|
|
13 |
# use of this file. (The General Public License restrictions do apply in
|
|
14 |
# other respects; for example, they cover modification of the file, and
|
|
15 |
# distribution when not linked into a combine executable.)
|
|
16 |
#
|
|
17 |
# This program is distributed in the hope that it will be useful,
|
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 |
# GNU General Public License for more details.
|
|
21 |
#
|
|
22 |
# You should have received a copy of the GNU General Public License
|
|
23 |
# along with this program; if not, write to the Free Software
|
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
25 |
|
|
26 |
import os, sys, iu, imp
|
|
27 |
class Win32ImportDirector(iu.ImportDirector):
|
|
28 |
def __init__(self):
|
|
29 |
self.path = sys.path[0] # since I run as a hook, sys.path probably hasn't been mucked with
|
|
30 |
if hasattr(sys, 'version_info'):
|
|
31 |
self.suffix = '%d%d'%(sys.version_info[0],sys.version_info[1])
|
|
32 |
else:
|
|
33 |
self.suffix = '%s%s' % (sys.version[0], sys.version[2])
|
|
34 |
def getmod(self, nm):
|
|
35 |
fnm = os.path.join(self.path, nm+self.suffix+'.dll')
|
|
36 |
try:
|
|
37 |
fp = open(fnm, 'rb')
|
|
38 |
except:
|
|
39 |
return None
|
|
40 |
else:
|
|
41 |
mod = imp.load_module(nm, fp, fnm, ('.dll', 'rb', imp.C_EXTENSION))
|
|
42 |
mod.__file__ = fnm
|
|
43 |
return mod
|
|
44 |
sys.importManager.metapath.insert(1, Win32ImportDirector())
|