Mercurial > jelly
changeset 40:95e51bb34486
Make the game work from a single exe file created with py2exe
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 17 Mar 2012 20:19:41 +0100 |
| parents | ba2f26eb60be |
| children | a3b46f7817a8 |
| files | jelly/resource.py setup.py |
| diffstat | 2 files changed, 38 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/jelly/resource.py Sat Mar 17 13:02:34 2012 +0100 +++ b/jelly/resource.py Sat Mar 17 20:19:41 2012 +0100 @@ -2,7 +2,9 @@ # -*- coding: utf-8 -*- import pkgutil +import os import tempfile +import shutil try: import cStringIO as StringIO except ImportError: @@ -40,14 +42,20 @@ return FONT_CACHE[filename, size] except KeyError: # XXX the "right" way causes segmentation fault - # f = StringIO.StringIO(pkgutil.get_data('jelly', filename)) - with tempfile.NamedTemporaryFile() as f: - data = pkgutil.get_data('jelly', filename) - f.write(data) - f.seek(0) - print f.name - - font = pygame.font.Font(f.name, size) + f = StringIO.StringIO(pkgutil.get_data('jelly', filename)) + tmpdir = tempfile.mkdtemp() + fname = os.path.join(tmpdir, filename) + try: + with open(fname, 'wb') as f: + data = pkgutil.get_data('jelly', filename) + f.write(data) + font = pygame.font.Font(fname, size) + finally: + try: + os.remove(fname) + os.rmdir(tmpdir) + except: + pass FONT_CACHE[filename, size] = font return font
--- a/setup.py Sat Mar 17 13:02:34 2012 +0100 +++ b/setup.py Sat Mar 17 20:19:41 2012 +0100 @@ -2,18 +2,28 @@ # -*- coding: utf-8 -*- from setuptools import setup +import os +import glob try: import py2exe except ImportError: pass +else: + origIsSystemDLL = py2exe.build_exe.isSystemDLL + def isSystemDLL(pathname): + if os.path.basename(pathname).lower() in ( + "libfreetype-6.dll", "sdl_ttf.dll", "libogg-0.dll"): + return 0 + return origIsSystemDLL(pathname) + py2exe.build_exe.isSystemDLL = isSystemDLL -origIsSystemDLL = py2exe.build_exe.isSystemDLL # save the orginal before we edit it -def isSystemDLL(pathname): - # checks if the freetype and ogg dll files are being included - if os.path.basename(pathname).lower() in ("libfreetype-6.dll", "libogg-0.dll","sdl_ttf.dll"): # "sdl_ttf.dll" added by arit. - return 0 - return origIsSystemDLL(pathname) # return the orginal function -py2exe.build_exe.isSystemDLL = isSystemDLL + orig_byte_compile = py2exe.build_exe.byte_compile + def byte_compile(*args, **kwargs): + files = orig_byte_compile(*args, **kwargs) + files.extend(os.path.abspath(d) for d in glob.glob("jelly/*.png")) + files.extend(os.path.abspath(d) for d in glob.glob("jelly/*.ttf")) + return files + py2exe.build_exe.byte_compile = byte_compile setup( name='jelly', @@ -42,9 +52,14 @@ 'optparse', 'calendar', 'pickle', + 'email', + '_ssl', ] }, }, + data_files = [ + ("jelly", glob.glob("jelly/*.png") + glob.glob("jelly/*.ttf")), + ], windows = [ { 'script': "run_jelly.py",
