Commits

Radomir Dopieralski  committed 95e51bb

Make the game work from a single exe file created with py2exe

  • Participants
  • Parent commits ba2f26e

Comments (0)

Files changed (2)

File jelly/resource.py

 # -*- coding: utf-8 -*-
 
 import pkgutil
+import os
 import tempfile
+import shutil
 try:
     import cStringIO as StringIO
 except ImportError:
         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
 
 # -*- 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',
                 'optparse',
                 'calendar',
                 'pickle',
+                'email',
+                '_ssl',
             ]
         },
     },
+    data_files = [
+        ("jelly", glob.glob("jelly/*.png") + glob.glob("jelly/*.ttf")),
+    ],
     windows = [
         {
             'script': "run_jelly.py",