srcanamdw/codescanner/pyinstaller/support/rthooks/opengl.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
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
# This program is free software; you can redistribute it and/or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
# modify it under the terms of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
# as published by the Free Software Foundation; either version 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# of the License, or (at your option) any later version.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
# In addition to the permissions in the GNU General Public License, the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
# authors give you unlimited permission to link or embed the compiled
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
# version of this file into combinations with other programs, and to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
# distribute those combinations without any restriction coming from the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
# use of this file. (The General Public License restrictions do apply in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
# other respects; for example, they cover modification of the file, and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
# distribution when not linked into a combine executable.)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
# This program is distributed in the hope that it will be useful,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
# GNU General Public License for more details.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
# You should have received a copy of the GNU General Public License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
# along with this program; if not, write to the Free Software
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
# PyOpenGL (specifically, OpenGL.__init__) reads a "version" text file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
# containing the version number to export it as OpenGL.__version__. When
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
# packaging with PyInstaller, the 'version' file does not exist, and importing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
# PyOpenGL results in an IOError.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
# The (convoluted) solution is to override Python's builtin "open" with our
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
# own function which detects when "version" is opened and returns some fake
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
# content stream (through cStringIO).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
__realopen__ = open
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
def myopen(fn, *args):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
    import os
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
    lastdir = os.path.basename(os.path.dirname(fn))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
    if os.path.basename(fn) == "version" and os.path.splitext(lastdir)[1] == ".pyz":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
        import cStringIO
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
        # Restore original open, since we're almost done
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
        __builtins__.__dict__["open"] = __realopen__
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
        # Report a fake revision number. Anything would do since it's not
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
        # used by the library, but it needs to be made of four numbers
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
        # separated by dots.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
        return cStringIO.StringIO("0.0.0.0")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
    return __realopen__(fn, *args)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
__builtins__.__dict__["open"] = myopen