1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#!/usr/bin/env python
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
import pykversion
import sys
import glob
from pykenv import *
# patch distutils if it can't cope with the "classifiers" or
# "download_url" keywords
if sys.version < '2.2.3':
from distutils.dist import DistributionMetadata
DistributionMetadata.classifiers = None
DistributionMetadata.download_url = None
gotPy2exe = 0
if env == ENV_WINDOWS:
# On Windows, we use py2exe to build a binary executable. But we
# don't require it, since even without it it's still possible to
# use distutils to install pykaraoke as a standard Python module.
try:
import py2exe
gotPy2exe = True
except ImportError:
pass
# These are the data file that should be installed for all systems,
# including Windows.
data_files = [
('share/pykaraoke/icons',
['icons/audio_16.png',
'icons/folder_close_16.png',
'icons/folder_open_16.png',
'icons/microphone.ico',
'icons/pykaraoke.xpm',
'icons/splash.jpg']),
('share/pykaraoke/fonts', [
'fonts/DejaVuSans.ttf',
'fonts/DejaVuSansCondensed.ttf',
'fonts/DejaVuSansCondensed-Bold.ttf',
])]
# These data files only make sense on Unix-like systems.
if env != ENV_WINDOWS:
data_files += [
('bin', ['install/pykaraoke',
'install/pykaraoke_mini',
'install/pycdg',
'install/pykar',
'install/pympg']),
('share/applications', ['install/pykaraoke.desktop',
'install/pykaraoke_mini.desktop'])]
# These are the basic keyword arguments we will pass to distutil's
# setup() function.
cmdclass = {}
setupArgs = {
'name' : "pykaraoke",
'version' : pykversion.PYKARAOKE_VERSION_STRING,
'description' : 'PyKaraoke = CD+G/MPEG/KAR Karaoke Player',
'maintainer' : 'Kelvin Lawson',
'maintainer_email' : 'kelvin@kibosh.org',
'url' : 'http://www.kibosh.org/pykaraoke',
'license' : 'LGPL',
'long_description' : 'PyKaraoke - CD+G/MPEG/KAR Karaoke Player',
'py_modules' : [ "pycdgAux", "pycdg", "pykaraoke_mini",
"pykaraoke", "pykar", "pykconstants",
"pykdb", "pykenv", "pykmanager",
"pykplayer", "pykversion", "pympg" ],
'ext_modules' : [Extension("_pycdgAux", ["_pycdgAux.c"],
libraries = ['SDL'])],
'data_files' : data_files,
'cmdclass' : cmdclass,
'classifiers' : ['Development Status :: 5 - Production/Stable',
'Environment :: X11 Applications',
'Environment :: Win32 (MS Windows)',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python',
'Topic :: Games/Entertainment',
'Topic :: Multimedia :: Sound/Audio :: Players'],
}
# Let's extend build_ext so we can allow the user to specify
# explicitly the location of the SDL installation (or we can try to
# guess where it might be.)
class my_build_ext(build_ext):
user_options = build_ext.user_options
user_options += [('sdl-location=', None,
"Specify the path to the SDL source directory, assuming sdl_location/include and sdl_location/lib exist beneath that. (Otherwise, use --include-dirs and --library-dirs.)"),
]
def initialize_options(self):
build_ext.initialize_options(self)
self.sdl_location = None
def finalize_options(self):
build_ext.finalize_options(self)
if self.sdl_location is None:
# The default SDL location. This is useful only if your
# SDL source is installed under a common root, with
# sdl_loc/include and sdl_loc/lib directories beneath that
# root. This is the standard way that SDL is distributed
# on Windows, but not on Unix. For a different
# configuration, just specify --include-dirs and
# --library-dirs separately.
if env == ENV_WINDOWS:
# For a default location on Windows, look around for SDL
# in the current directory.
sdl_dirs = glob.glob('SDL*')
# Sort them in order, so that the highest-numbered version
# will (probably) fall to the end.
sdl_dirs.sort()
for dir in sdl_dirs:
if os.path.isdir(os.path.join(dir, 'include')):
self.sdl_location = dir
if self.sdl_location is not None:
# Now append the system paths.
self.include_dirs.append(os.path.join(self.sdl_location, 'include'))
self.library_dirs.append(os.path.join(self.sdl_location, 'lib'))
# Also put the lib dir on the PATH, so py2exe can find SDL.dll.
if env == ENV_WINDOWS:
libdir = os.path.join(self.sdl_location, 'lib')
os.environ["PATH"] = '%s;%s' % (libdir, os.environ["PATH"])
cmdclass['build_ext'] = my_build_ext
# On Windows, we might want to build an installer. This means
# subclassing from py2exe to add new behavior.
if gotPy2exe:
class BuildInstaller(py2exe.build_exe.py2exe):
user_options = py2exe.build_exe.py2exe.user_options
user_options += [('makensis=', None,
"path to makensis.exe, the NSIS compiler."),
]
def initialize_options(self):
py2exe.build_exe.py2exe.initialize_options(self)
self.makensis = None
def finalize_options(self):
py2exe.build_exe.py2exe.finalize_options(self)
if self.makensis is None:
try:
import win32api
self.makensis = win32api.FindExecutable('makensis')
except:
# Default path for makensis. This is where it gets
# installed by default.
self.makensis = os.path.join(os.environ['ProgramFiles'], 'NSIS\\makensis')
def run(self):
# Make sure the dist directory doesn't exist already--make
# the user delete it first if it does. (This is safer
# than calling rm_rf() on it, in case the user has
# specified '/' or some equally foolish directory as the
# dist directory.)
if os.path.exists(self.dist_dir):
print "Error, the directory %s already exists." % (self.dist_dir)
print "Please remove it before starting this script."
sys.exit(1)
# Build the .exe files, etc.
py2exe.build_exe.py2exe.run(self)
# Now run NSIS to build the installer.
cmd = '"%(makensis)s" /DVERSION=%(version)s install\\windows_installer.nsi' % {
'makensis' : self.makensis,
'version' : pykversion.PYKARAOKE_VERSION_STRING,
}
print cmd
os.system(cmd)
# Now that we've got an installer, we can empty the dist
# dir again.
self.rm_rf(self.dist_dir)
def rm_rf(self, dirname):
"""Recursively removes a directory's contents."""
if os.path.isdir(dirname):
for root, dirs, files in os.walk(dirname, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
os.rmdir(dirname)
cmdclass['nsis'] = BuildInstaller
# tell py2exe what the front end applications are.
setupArgs['windows'] = [
{ "script": "pykaraoke.py",
"icon_resources" : [(0, "icons\\microphone.ico")],
},
{ "script": "pykaraoke_mini.py",
"icon_resources" : [(0, "icons\\microphone.ico")],
},
]
setup(**setupArgs)
|