"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

import sys
sys.path.append('/Volumes/shared/ab/renpy/')

from distutils.core import setup
import py2app

APP = [ "launcher.py" ]
DATA_FILES = []
OPTIONS = {
	'optimize': 2,
	'iconfile': "/Users/tom/mac/launcher.icns", 
	'argv_emulation': True,
	'excludes' : [ 
             'dotblas',
             '_dotblas',
             '_numpy',
             'multiarray',
             'Numeric',
             'readline',
             'pygame.sndarray',
             'pygame.surfarray',
             'doctest',
             '_ssl',
             'macpath',
             'ntpath',
             'os2emxpath',
             "locale",
             "_locale",
             "gettext",
	     "OpenGL",
	],
	'graph' : True,
	}

setup(
    name="Ren'Py Launcher",
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

import os
import zipfile
pydir = "dist/Ren'Py Launcher.app/Contents/Resources/lib/python2.5"

oldzip = zipfile.ZipFile(pydir + "/site-packages.zip")
newzip = zipfile.ZipFile(pydir + "/new-site-packages.zip", "w", zipfile.ZIP_DEFLATED)

encoding_exceptions = [
	'encodings.',
	'encodings/encodings',
	'encodings/aliases',
	'encodings/codecs',
	'encodings/types',
	'encodings/__init__',
	'encodings/ascii',
	'encodings/utf_8',
	'encodings/zlib_codec',
	'encodings/unicode_escape',
	'encodings/string_escape',
	'encodings/raw_unicode_escape',
	'encodings/mbcs',
	]

for n in oldzip.namelist():
	if n.startswith("renpy"):
		continue
	if n.startswith("_codecs_"):
		continue
	if n.startswith("unicodedata"):
		continue
	
	if n.startswith("encodings"):
		for e in encoding_exceptions:
			print n, e
			if n.startswith(e):
				break
		else:
			continue

	newzip.writestr(n, oldzip.read(n))

newzip.close()
oldzip.close()
	
os.rename(pydir + "/new-site-packages.zip", pydir + "/site-packages.zip")

for fn in os.listdir(pydir + "/lib-dynload"):
	if fn.startswith("_codecs_") or fn.startswith("unicodedata"):
		fn = pydir + "/lib-dynload/" + fn
		os.unlink(fn)

