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