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