mirror of
https://github.com/fergalmoran/picard.git
synced 2026-01-09 10:03:59 +00:00
361 lines
12 KiB
Python
Executable File
361 lines
12 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import glob
|
|
import os.path
|
|
import sys
|
|
from ConfigParser import RawConfigParser
|
|
from distutils import log
|
|
from distutils.command.build import build
|
|
from distutils.command.config import config as ConfigCommand
|
|
from distutils.core import setup, Command, Extension
|
|
from distutils.dep_util import newer
|
|
from distutils.dist import Distribution
|
|
from picard import __version__
|
|
|
|
|
|
if sys.version_info < (2, 4):
|
|
print "*** You need Python 2.4 or higher to use Picard."
|
|
|
|
|
|
defaults = {
|
|
'build': {
|
|
'with-directshow': 'False',
|
|
'with-avcodec': 'False',
|
|
'with-gstreamer': 'False',
|
|
'with-quicktime': 'False',
|
|
'with-libofa': 'False',
|
|
},
|
|
'avcodec': {'cflags': '', 'libs': ''},
|
|
'directshow': {'cflags': '', 'libs': ''},
|
|
'gstreamer': {'cflags': '', 'libs': ''},
|
|
'quicktime': {'cflags': '', 'libs': ''},
|
|
'libofa': {'cflags': '', 'libs': ''},
|
|
}
|
|
config = RawConfigParser()
|
|
for section, values in defaults.items():
|
|
config.add_section(section)
|
|
for option, value in values.items():
|
|
config.set(section, option, value)
|
|
config.read(['build.cfg'])
|
|
|
|
|
|
ext_modules = [
|
|
Extension('picard.util.astrcmp', sources=['picard/util/astrcmp.cpp']),
|
|
]
|
|
|
|
if config.getboolean('build', 'with-libofa'):
|
|
ext_modules.append(
|
|
Extension('picard.musicdns.ofa', sources=['picard/musicdns/ofa.c'],
|
|
extra_compile_args=config.get('libofa', 'cflags').split(),
|
|
extra_link_args=config.get('libofa', 'libs').split()))
|
|
|
|
if config.getboolean('build', 'with-directshow'):
|
|
ext_modules.append(
|
|
Extension('picard.musicdns.directshow',
|
|
sources=['picard/musicdns/directshow.cpp'],
|
|
extra_compile_args=config.get('directshow', 'cflags').split(),
|
|
extra_link_args=config.get('directshow', 'libs').split()))
|
|
|
|
if config.getboolean('build', 'with-quicktime'):
|
|
ext_modules.append(
|
|
Extension('picard.musicdns.quicktime',
|
|
sources=['picard/musicdns/quicktime.c'],
|
|
extra_compile_args=config.get('quicktime', 'cflags').split(),
|
|
extra_link_args=config.get('quicktime', 'libs').split()))
|
|
|
|
if config.getboolean('build', 'with-avcodec'):
|
|
ext_modules.append(
|
|
Extension('picard.musicdns.avcodec',
|
|
sources=['picard/musicdns/avcodec.c'],
|
|
extra_compile_args=config.get('avcodec', 'cflags').split(),
|
|
extra_link_args=config.get('avcodec', 'libs').split()))
|
|
|
|
if config.getboolean('build', 'with-gstreamer'):
|
|
ext_modules.append(
|
|
Extension('picard.musicdns.gstreamer',
|
|
sources=['picard/musicdns/gstreamer.c'],
|
|
extra_compile_args=config.get('gstreamer', 'cflags').split(),
|
|
extra_link_args=config.get('gstreamer', 'libs').split()))
|
|
|
|
|
|
class cmd_test(Command):
|
|
description = "run automated tests"
|
|
user_options = [
|
|
("tests=", None, "list of tests to run (default all)"),
|
|
("verbosity=", "v", "verbosity"),
|
|
]
|
|
|
|
def initialize_options(self):
|
|
self.tests = []
|
|
self.verbosity = 1
|
|
|
|
def finalize_options(self):
|
|
if self.tests:
|
|
self.tests = self.tests.split(",")
|
|
if self.verbosity:
|
|
self.verbosity = int(self.verbosity)
|
|
|
|
def run(self):
|
|
import os.path
|
|
import glob
|
|
import unittest
|
|
|
|
names = []
|
|
for filename in glob.glob("test/test_*.py"):
|
|
name = os.path.splitext(os.path.basename(filename))[0]
|
|
if not self.tests or name in self.tests:
|
|
names.append("test." + name)
|
|
|
|
tests = unittest.defaultTestLoader.loadTestsFromNames(names)
|
|
t = unittest.TextTestRunner(verbosity=self.verbosity)
|
|
t.run(tests)
|
|
|
|
|
|
class cmd_build_locales(Command):
|
|
description = 'build locale files'
|
|
user_options = [
|
|
('build-dir=', 'd', "directory to build to"),
|
|
('inplace', 'i', "ignore build-lib and put compiled locales into the 'locale' directory"),
|
|
]
|
|
|
|
def initialize_options(self):
|
|
self.build_dir = None
|
|
self.inplace = 0
|
|
|
|
def finalize_options (self):
|
|
self.set_undefined_options('build', ('build_locales', 'build_dir'))
|
|
self.locales = self.distribution.locales
|
|
|
|
def run(self):
|
|
for domain, locale, po in self.locales:
|
|
if self.inplace:
|
|
path = os.path.join('locale', locale, 'LC_MESSAGES')
|
|
else:
|
|
path = os.path.join(self.build_dir, locale, 'LC_MESSAGES')
|
|
mo = os.path.join(path, '%s.mo' % domain)
|
|
self.mkpath(path)
|
|
self.spawn(['msgfmt', '-o', mo, po])
|
|
|
|
Distribution.locales = None
|
|
|
|
|
|
class cmd_build(build):
|
|
|
|
user_options = build.user_options + [
|
|
('build-locales=', 'd', "build directory for locale files"),
|
|
]
|
|
|
|
sub_commands = build.sub_commands + [
|
|
('build_locales', None),
|
|
]
|
|
|
|
def initialize_options(self):
|
|
build.initialize_options(self)
|
|
self.build_locales = None
|
|
|
|
def finalize_options(self):
|
|
build.finalize_options(self)
|
|
if self.build_locales is None:
|
|
self.build_locales = os.path.join(self.build_base, 'locale')
|
|
|
|
|
|
class cmd_build_ui(Command):
|
|
description = "build Qt UI files and resources"
|
|
user_options = []
|
|
|
|
def initialize_options(self):
|
|
pass
|
|
|
|
def finalize_options(self):
|
|
pass
|
|
|
|
def run(self):
|
|
from PyQt4 import uic
|
|
for uifile in glob.glob("ui/*.ui"):
|
|
pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0]
|
|
pyfile = os.path.join("picard", "ui", pyfile)
|
|
if newer(uifile, pyfile):
|
|
log.info("compiling %s -> %s", uifile, pyfile)
|
|
uic.compileUi(uifile, file(pyfile, "w"), gettext=True)
|
|
qrcfile = os.path.join("resources", "picard.qrc")
|
|
pyfile = os.path.join("picard", "resources.py")
|
|
build_resources = False
|
|
if newer("resources/picard.qrc", pyfile):
|
|
build_resources = True
|
|
for datafile in glob.glob("resources/images/*.*"):
|
|
if newer(datafile, pyfile):
|
|
build_resources = True
|
|
break
|
|
if build_resources:
|
|
log.info("compiling %s -> %s", qrcfile, pyfile)
|
|
os.system("pyrcc4 %s -o %s" % (qrcfile, pyfile))
|
|
|
|
|
|
class cmd_clean_ui(Command):
|
|
description = "clean up compiled Qt UI files and resources"
|
|
user_options = []
|
|
|
|
def initialize_options(self):
|
|
pass
|
|
|
|
def finalize_options(self):
|
|
pass
|
|
|
|
def run(self):
|
|
from PyQt4 import uic
|
|
for uifile in glob.glob("ui/*.ui"):
|
|
pyfile = "ui_%s.py" % os.path.splitext(os.path.basename(uifile))[0]
|
|
pyfile = os.path.join("picard", "ui", pyfile)
|
|
try:
|
|
os.unlink(pyfile)
|
|
log.info("removing %s", pyfile)
|
|
except OSError:
|
|
log.warn("'%s' does not exist -- can't clean it", pyfile)
|
|
pyfile = os.path.join("picard", "resources.py")
|
|
try:
|
|
os.unlink(pyfile)
|
|
log.info("removing %s", pyfile)
|
|
except OSError:
|
|
log.warn("'%s' does not exist -- can't clean it", pyfile)
|
|
|
|
|
|
class cmd_config(ConfigCommand):
|
|
|
|
def initialize_options(self):
|
|
ConfigCommand.initialize_options(self)
|
|
|
|
def run(self):
|
|
print 'checking for pkg-config...',
|
|
have_pkgconfig = False
|
|
if os.system('pkg-config --version >%s 2>%s' % (os.path.devnull, os.path.devnull)) == 0:
|
|
print 'yes'
|
|
have_pkgconfig = True
|
|
else:
|
|
print 'no'
|
|
|
|
print 'checking for libofa...',
|
|
if have_pkgconfig:
|
|
self.pkgconfig_check_module('libofa', 'libofa')
|
|
else:
|
|
print 'no (FIXME: add non-pkg-config check)'
|
|
config.set('build', 'with-libofa', False)
|
|
|
|
print 'checking for libavcodec/libavformat...',
|
|
if have_pkgconfig:
|
|
self.pkgconfig_check_module('avcodec', 'libavcodec libavformat')
|
|
else:
|
|
print 'no (FIXME: add non-pkg-config check)'
|
|
config.set('build', 'with-avcodec', False)
|
|
|
|
print 'checking for gstreamer-0.10...',
|
|
if have_pkgconfig:
|
|
self.pkgconfig_check_module('gstreamer', 'gstreamer-0.10')
|
|
else:
|
|
print 'no (FIXME: add non-pkg-config check)'
|
|
config.set('build', 'with-gstreamer', False)
|
|
|
|
print 'checking for directshow...',
|
|
if sys.platform == 'win32':
|
|
print 'yes'
|
|
config.set('build', 'with-directshow', True)
|
|
config.set('directshow', 'cflags', '')
|
|
config.set('directshow', 'libs', 'strmiids.lib')
|
|
else:
|
|
print 'no'
|
|
config.set('build', 'with-directshow', False)
|
|
|
|
print 'saving build.cfg'
|
|
config.write(file('build.cfg', 'wt'))
|
|
|
|
|
|
def pkgconfig_exists(self, module):
|
|
if os.system('pkg-config --exists %s' % module) == 0:
|
|
return True
|
|
|
|
def pkgconfig_cflags(self, module):
|
|
pkgcfg = os.popen('pkg-config --cflags %s' % module)
|
|
ret = pkgcfg.readline().strip()
|
|
pkgcfg.close()
|
|
return ret
|
|
|
|
def pkgconfig_libs(self, module):
|
|
pkgcfg = os.popen('pkg-config --libs %s' % module)
|
|
ret = pkgcfg.readline().strip()
|
|
pkgcfg.close()
|
|
return ret
|
|
|
|
def pkgconfig_check_module(self, name, module):
|
|
print '(pkg-config)',
|
|
if self.pkgconfig_exists(module):
|
|
print 'yes'
|
|
config.set('build', 'with-' + name, True)
|
|
config.set(name, 'cflags', self.pkgconfig_cflags(module))
|
|
config.set(name, 'libs', self.pkgconfig_libs(module))
|
|
else:
|
|
print 'no'
|
|
config.set('build', 'with-' + name, False)
|
|
|
|
|
|
args = {
|
|
'name': 'picard',
|
|
'version': __version__,
|
|
'description': 'The next generation MusicBrainz tagger',
|
|
'url': 'http://wiki.musicbrainz.org/PicardTagger',
|
|
'package_dir': {'picard': 'picard'},
|
|
'packages': ('picard', 'picard.browser', 'picard.musicdns',
|
|
'picard.plugins', 'picard.formats',
|
|
'picard.formats.mutagenext', 'picard.ui',
|
|
'picard.ui.options', 'picard.util'),
|
|
'locales': [('picard', os.path.split(po)[1][:-3], po) for po in glob.glob('po/*.po')],
|
|
'ext_modules': ext_modules,
|
|
'data_files': [],
|
|
'cmdclass': {
|
|
'test': cmd_test,
|
|
'build': cmd_build,
|
|
'build_locales': cmd_build_locales,
|
|
'build_ui': cmd_build_ui,
|
|
'clean_ui': cmd_clean_ui,
|
|
'config': cmd_config,
|
|
},
|
|
}
|
|
|
|
def generate_file(infilename, outfilename, variables):
|
|
f = file(infilename, "rt")
|
|
content = f.read()
|
|
f.close()
|
|
content = content % variables
|
|
f = file(outfilename, "wt")
|
|
f.write(content)
|
|
f.close()
|
|
|
|
try:
|
|
from py2exe.build_exe import py2exe
|
|
class bdist_nsis(py2exe):
|
|
def run(self):
|
|
generate_file('scripts/picard.py2exe.in', 'scripts/picard', {})
|
|
self.distribution.data_files.append(
|
|
("", ["discid.dll", "libfftw3-3.dll", "libofa.dll"]))
|
|
|
|
py2exe.run(self)
|
|
|
|
print "*** creating the NSIS setup script ***"
|
|
pathname = "installer/picard-setup.nsi"
|
|
generate_file(pathname + ".in", pathname,
|
|
{'name': 'MusicBrainz Picard',
|
|
'version': __version__})
|
|
|
|
print "*** compiling the NSIS setup script ***"
|
|
from ctypes import windll
|
|
windll.shell32.ShellExecuteA(0, "compile", pathname, None, None, 0)
|
|
|
|
args['cmdclass']['bdist_nsis'] = bdist_nsis
|
|
args['windows'] = [{
|
|
'script': 'scripts/picard',
|
|
'icon_resources': [(1, 'picard.ico')],
|
|
}]
|
|
|
|
except ImportError:
|
|
pass
|
|
|
|
setup(**args)
|