import os, shutil
import psyco
psyco.full()

# remove old py2exe directories if present
print 'Removing leftover py2exe directories...'
py2exeDirs = ('dist', 'build')
for dir in os.listdir('.'):
    if os.path.isdir(dir):
        if dir in py2exeDirs:
            shutil.rmtree(dir)
            print dir + ' removed'
# run setup (to make program distributable) & py2exe (to compile to a compressed .exe)
os.system('python setup.py py2exe -c')

# UPX (to compress files further)
exts = ('.exe', '.dll', '.pyd')
for file in os.listdir('./dist'):
    if os.path.isfile('./dist/' + file):
        if os.path.splitext(file)[1] in exts:
            os.system('"C:\Program Files\upx125w\upx.exe" --best --crp-ms=999999 --nrv2d ./dist/' + file)

# NSIS (to make compressed installer/uninstaller)
os.system('"C:\Program Files\NSIS\makensis.exe" /PAUSE setup.nsi')
