deluge/setup.py

575 lines
19 KiB
Python
Raw Normal View History

2011-05-21 12:00:59 +00:00
#!/usr/bin/env python
#
2007-07-04 08:24:30 +00:00
# setup.py
#
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
# 2009 Damien Churchill <damoxc@gmail.com>
2007-07-04 08:24:30 +00:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2008-08-08 05:59:07 +00:00
# the Free Software Foundation; either version 3, or (at your option)
2007-07-04 08:24:30 +00:00
# any later version.
2008-07-14 20:42:11 +00:00
#
2007-07-04 08:24:30 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2007-07-13 01:34:18 +00:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2007-07-04 08:24:30 +00:00
# GNU General Public License for more details.
2008-07-14 20:42:11 +00:00
#
2007-07-04 08:24:30 +00:00
# You should have received a copy of the GNU General Public License
2007-07-13 01:34:18 +00:00
# along with this program. If not, write to:
2007-07-04 08:24:30 +00:00
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
2007-07-13 01:34:18 +00:00
# Boston, MA 02110-1301, USA.
2007-07-04 08:24:30 +00:00
#
try:
from setuptools import setup, find_packages, Extension
except ImportError:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup, find_packages, Extension
2008-07-10 04:40:13 +00:00
import glob
import sys
2007-07-04 08:24:30 +00:00
from distutils import cmd, sysconfig
2007-09-16 01:24:08 +00:00
from distutils.command.build import build as _build
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.clean import clean as _clean
2009-07-22 23:52:18 +00:00
try:
from sphinx.setup_command import BuildDoc
except ImportError:
class BuildDoc(object):
pass
2008-07-10 04:40:13 +00:00
import msgfmt
import os
2008-07-10 04:40:13 +00:00
import platform
2007-07-04 08:24:30 +00:00
python_version = platform.python_version()[0:3]
2008-02-03 01:04:26 +00:00
def windows_check():
2008-10-23 11:27:37 +00:00
return platform.system() in ('Windows', 'Microsoft')
2008-02-03 01:04:26 +00:00
def osx_check():
2008-10-23 11:27:37 +00:00
return platform.system() == "Darwin"
if not os.environ.has_key("CC"):
os.environ["CC"] = "gcc"
if not os.environ.has_key("CXX"):
os.environ["CXX"] = "gcc"
2008-07-14 20:42:11 +00:00
if not os.environ.has_key("CPP"):
os.environ["CPP"] = "g++"
2008-07-14 20:42:11 +00:00
2007-07-04 08:24:30 +00:00
# The libtorrent extension
_extra_compile_args = [
2008-04-16 03:52:08 +00:00
"-D_FILE_OFFSET_BITS=64",
2008-05-20 06:23:48 +00:00
"-DNDEBUG",
2008-07-10 04:40:13 +00:00
"-DTORRENT_USE_OPENSSL=1",
"-DBOOST_FILESYSTEM_VERSION=2",
2008-07-10 04:40:13 +00:00
"-O2",
2008-02-03 01:04:26 +00:00
]
2008-02-03 01:12:46 +00:00
2008-02-03 01:04:26 +00:00
if windows_check():
2008-07-14 20:42:11 +00:00
_extra_compile_args += [
2008-02-03 01:04:26 +00:00
"-D__USE_W32_SOCKETS",
2008-07-10 04:40:13 +00:00
"-D_WIN32_WINNT=0x0500",
2008-02-03 01:04:26 +00:00
"-D_WIN32",
2008-07-10 04:40:13 +00:00
"-DWIN32_LEAN_AND_MEAN",
2008-02-03 01:04:26 +00:00
"-DBOOST_ALL_NO_LIB",
"-DBOOST_THREAD_USE_LIB",
2008-07-10 04:40:13 +00:00
"-DBOOST_WINDOWS",
"-DBOOST_WINDOWS_API",
"-DWIN32",
"-DUNICODE",
"-D_UNICODE",
"-D_SCL_SECURE_NO_WARNINGS",
"/O2",
"/Ob2",
"/W3",
2008-07-10 04:40:13 +00:00
"/GR",
"/MD",
"/wd4675",
2008-07-10 04:40:13 +00:00
"/Zc:wchar_t",
"/Zc:forScope",
2008-12-26 04:52:44 +00:00
"/EHsc",
"-c",
2008-02-03 01:04:26 +00:00
]
2008-02-03 01:12:46 +00:00
else:
_extra_compile_args += ["-Wno-missing-braces"]
2008-07-14 20:42:11 +00:00
def remove_from_cflags(flags):
if not windows_check():
keys = ["OPT", "CFLAGS"]
if python_version == '2.5':
keys = ["CFLAGS"]
for key in keys:
cv_opt = sysconfig.get_config_vars()[key]
for flag in flags:
cv_opt = cv_opt.replace(flag, " ")
sysconfig.get_config_vars()[key] = " ".join(cv_opt.split())
removals = ["-Wstrict-prototypes"]
remove_from_cflags(removals)
2008-02-03 01:12:46 +00:00
2008-02-03 03:24:36 +00:00
_library_dirs = [
]
_include_dirs = [
2007-07-13 01:34:18 +00:00
'./libtorrent',
'./libtorrent/include',
'./libtorrent/include/libtorrent'
2007-07-04 08:24:30 +00:00
]
2008-02-03 01:04:26 +00:00
if windows_check():
2008-07-05 00:25:04 +00:00
_include_dirs += ['./win32/include','./win32/include/openssl', './win32/include/zlib']
_library_dirs += ['./win32/lib']
2008-02-03 09:05:55 +00:00
_libraries = [
2008-07-10 04:40:13 +00:00
'advapi32',
'boost_filesystem-vc-mt-1_37',
'boost_date_time-vc-mt-1_37',
'boost_iostreams-vc-mt-1_37',
'boost_python-vc-mt-1_37',
'boost_system-vc-mt-1_37',
'boost_thread-vc-mt-1_37',
2008-07-10 04:40:13 +00:00
'gdi32',
2008-12-29 03:43:50 +00:00
'libeay32',
'ssleay32',
2008-07-10 04:40:13 +00:00
'ws2_32',
2008-02-03 01:04:26 +00:00
'wsock32',
2008-07-10 04:40:13 +00:00
'zlib'
2008-02-03 01:04:26 +00:00
]
2008-02-03 01:12:46 +00:00
else:
_include_dirs += [
'/usr/include/python' + python_version,
sysconfig.get_config_var("INCLUDEDIR")
]
for include in os.environ.get("INCLUDEDIR", "").split(":"):
2009-04-30 16:15:09 +00:00
_include_dirs.append(include)
_library_dirs += [sysconfig.get_config_var("LIBDIR"), '/opt/local/lib']
if osx_check():
_include_dirs += [
'/opt/local/include/boost-1_35',
'/opt/local/include/boost-1_36',
'/sw/include/boost-1_35',
'/sw/include/boost'
]
2008-02-03 22:50:06 +00:00
_libraries = [
2008-02-03 09:05:55 +00:00
'boost_filesystem',
'boost_date_time',
'boost_iostreams',
2008-07-10 04:40:13 +00:00
'boost_python',
'boost_thread',
2008-02-03 09:05:55 +00:00
'pthread',
2008-02-03 05:12:47 +00:00
'ssl',
'z'
]
2008-11-06 19:12:11 +00:00
2008-10-23 08:13:08 +00:00
if not windows_check():
dynamic_lib_extension = ".so"
if osx_check():
dynamic_lib_extension = ".dylib"
_lib_extensions = ['-mt', '-mt_1_39', '-mt-1_38', '-mt-1_37', '-mt-1_36', '-mt-1_35']
2008-11-06 19:12:11 +00:00
# Modify the libs if necessary for systems with only -mt boost libs
2008-10-23 08:13:08 +00:00
for lib in _libraries:
if lib[:6] == "boost_":
for lib_prefix in _library_dirs:
for lib_suffix in _lib_extensions:
# If there is a -mt version use that
if os.path.exists(os.path.join(lib_prefix, "lib" + lib + lib_suffix + dynamic_lib_extension)):
_libraries[_libraries.index(lib)] = lib + lib_suffix
lib = lib + lib_suffix
break
2008-11-06 19:12:11 +00:00
2007-07-09 02:50:20 +00:00
_sources = glob.glob("./libtorrent/src/*.cpp") + \
glob.glob("./libtorrent/src/*.c") + \
2007-07-13 01:34:18 +00:00
glob.glob("./libtorrent/src/kademlia/*.cpp") + \
glob.glob("./libtorrent/bindings/python/src/*.cpp")
2007-07-04 08:24:30 +00:00
# Remove some files from the source that aren't needed
2008-12-01 01:43:19 +00:00
_source_removals = ["mapped_storage.cpp", "memdebug.cpp"]
2008-12-10 10:00:21 +00:00
to_remove = []
for source in _sources:
for rem in _source_removals:
if rem in source:
2008-12-10 10:00:21 +00:00
to_remove.append(source)
for rem in to_remove:
_sources.remove(rem)
2007-07-04 08:24:30 +00:00
_ext_modules = []
2008-11-30 01:11:26 +00:00
# Check for a system libtorrent and if found, then do not build the libtorrent extension
build_libtorrent = True
try:
from deluge._libtorrent import lt
2008-11-30 01:11:26 +00:00
except ImportError:
build_libtorrent = True
else:
build_libtorrent = False
2008-11-30 01:11:26 +00:00
if build_libtorrent:
got_libtorrent = False
if not os.path.exists("libtorrent"):
import subprocess
if subprocess.call(['./get_libtorrent.sh']) > 0:
got_libtorrent = False
else:
got_libtorrent = True
else:
got_libtorrent = True
if got_libtorrent:
# There isn't a system libtorrent library, so let's build the one included with deluge
libtorrent = Extension(
'libtorrent',
extra_compile_args = _extra_compile_args,
include_dirs = _include_dirs,
libraries = _libraries,
library_dirs = _library_dirs,
sources = _sources
)
_ext_modules = [libtorrent]
2007-07-04 08:24:30 +00:00
2007-09-16 01:24:08 +00:00
class build_trans(cmd.Command):
description = 'Compile .po files into .mo files'
2008-11-29 01:22:29 +00:00
user_options = [
('build-lib', None, "lib build folder"),
('develop-mode', 'D', 'Compile translations in develop mode(into deluge/i18n')
2008-11-29 01:22:29 +00:00
]
boolean_options = ['develop_mode']
2008-11-29 01:22:29 +00:00
2007-09-16 01:24:08 +00:00
def initialize_options(self):
2008-11-29 01:22:29 +00:00
self.build_lib = None
self.develop_mode = False
2007-09-16 01:24:08 +00:00
def finalize_options(self):
2008-11-29 01:22:29 +00:00
self.set_undefined_options('build', ('build_lib', 'build_lib'))
2007-09-16 01:24:08 +00:00
def run(self):
po_dir = os.path.join(os.path.dirname(__file__), 'deluge/i18n/')
if self.develop_mode:
basedir = po_dir
else:
basedir = os.path.join(self.build_lib, 'deluge', 'i18n')
if not windows_check():
# creates the translated desktop file
INTLTOOL_MERGE='intltool-merge'
INTLTOOL_MERGE_OPTS='--utf8 --quiet --desktop-style'
desktop_in='deluge/ui/data/share/applications/deluge.desktop.in'
desktop_data='deluge/ui/data/share/applications/deluge.desktop'
print('Creating desktop file: %s' % desktop_data)
os.system('C_ALL=C ' + '%s '*5 % (INTLTOOL_MERGE, INTLTOOL_MERGE_OPTS, \
po_dir, desktop_in, desktop_data))
print('Compiling po files from %s...' % po_dir),
2007-09-16 01:24:08 +00:00
for path, names, filenames in os.walk(po_dir):
for f in filenames:
uptoDate = False
2007-09-16 01:24:08 +00:00
if f.endswith('.po'):
lang = f[:len(f) - 3]
src = os.path.join(path, f)
dest_path = os.path.join(basedir, lang, 'LC_MESSAGES')
2007-09-16 01:24:08 +00:00
dest = os.path.join(dest_path, 'deluge.mo')
if not os.path.exists(dest_path):
os.makedirs(dest_path)
if not os.path.exists(dest):
sys.stdout.write('%s, ' % lang)
sys.stdout.flush()
2007-09-16 01:24:08 +00:00
msgfmt.make(src, dest)
else:
src_mtime = os.stat(src)[8]
dest_mtime = os.stat(dest)[8]
if src_mtime > dest_mtime:
sys.stdout.write('%s, ' % lang)
sys.stdout.flush()
2007-09-16 01:24:08 +00:00
msgfmt.make(src, dest)
else:
uptoDate = True
if uptoDate:
sys.stdout.write(' po files already upto date. ')
sys.stdout.write('\b\b \nFinished compiling translation files. \n')
2007-09-16 01:24:08 +00:00
class build_plugins(cmd.Command):
description = "Build plugins into .eggs"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Build the plugin eggs
PLUGIN_PATH = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH):
if os.path.exists(os.path.join(path, "setup.py")):
os.system("cd " + path + "&& " + sys.executable + " setup.py bdist_egg -d ..")
class develop_plugins(cmd.Command):
description = "install plugin's in 'development mode'"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Build the plugin eggs
PLUGIN_PATH = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH):
if os.path.exists(os.path.join(path, "setup.py")):
os.system("cd " + path + "&& " + sys.executable + " setup.py develop")
class egg_info_plugins(cmd.Command):
description = "create a distribution's .egg-info directory"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Build the plugin eggs
PLUGIN_PATH = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH):
if os.path.exists(os.path.join(path, "setup.py")):
os.system("cd " + path + "&& " + sys.executable + " setup.py egg_info")
class build_docs(BuildDoc):
def run(self):
class FakeModule(object):
def __init__(self, *args, **kwargs): pass
def __call__(self, *args, **kwargs):
return FakeModule()
def __getattr__(self, key):
return FakeModule()
def __setattr__(self, key, value):
self.__dict__[key] = value
old_import = __builtins__.__import__
def new_import(name, globals={}, locals={}, fromlist=[], level=-1):
try:
return old_import(name, globals, locals, fromlist, level)
except ImportError:
return FakeModule()
2009-08-11 23:05:13 +00:00
except Exception, e:
print "Skipping Exception: ", e
return FakeModule()
__builtins__.__import__ = new_import
BuildDoc.run(self)
2007-09-16 01:24:08 +00:00
class build(_build):
sub_commands = [('build_trans', None), ('build_plugins', None)] + _build.sub_commands
2007-09-16 01:24:08 +00:00
def run(self):
# Run all sub-commands (at least those that need to be run)
2007-09-16 01:24:08 +00:00
_build.run(self)
class build_debug(build):
sub_commands = [x for x in build.sub_commands if x[0] != 'build_ext'] + [('build_ext_debug', None)]
class build_ext_debug(_build_ext):
def run(self):
if not self.distribution.ext_modules:
return _build_ext.run(self)
lt_ext = None
for ext in self.distribution.ext_modules:
if ext.name == 'libtorrent':
lt_ext = ext
if not lt_ext:
return _build_ext.run(self)
lt_ext.extra_compile_args.remove('-DNDEBUG')
lt_ext.extra_compile_args.remove('-O2')
lt_ext.extra_compile_args.append('-g')
remove_from_cflags(["-DNDEBUG", "-O2"])
return _build_ext.run(self)
class clean_plugins(cmd.Command):
description = "Cleans the plugin folders"
user_options = [
('all', 'a', "remove all build output, not just temporary by-products")
]
boolean_options = ['all']
def initialize_options(self):
self.all = None
def finalize_options(self):
self.set_undefined_options('clean', ('all', 'all'))
def run(self):
print("Cleaning the plugin's folders..")
PLUGIN_PATH = "deluge/plugins/*"
for path in glob.glob(PLUGIN_PATH):
if os.path.exists(os.path.join(path, "setup.py")):
c = "cd " + path + "&& " + sys.executable + " setup.py clean"
if self.all:
c += " -a"
os.system(c)
# Delete the .eggs
if path[-4:] == ".egg":
print("Deleting %s" % path)
os.remove(path)
EGG_INFO_DIR_PATH = "deluge/plugins/*/*.egg-info"
for path in glob.glob(EGG_INFO_DIR_PATH):
# Delete the .egg-info's directories
if path[-9:] == ".egg-info":
print("Deleting %s" % path)
for fpath in os.listdir(path):
os.remove(os.path.join(path, fpath))
os.removedirs(path)
class clean(_clean):
sub_commands = _clean.sub_commands + [('clean_plugins', None)]
def run(self):
# Run all sub-commands (at least those that need to be run)
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
_clean.run(self)
2007-09-16 01:24:08 +00:00
cmdclass = {
'build': build,
'build_trans': build_trans,
'build_plugins': build_plugins,
'build_docs': build_docs,
'build_debug': build_debug,
'build_ext_debug': build_ext_debug,
'clean_plugins': clean_plugins,
'clean': clean,
'develop_plugins': develop_plugins,
'egg_info_plugins': egg_info_plugins
2007-09-16 01:24:08 +00:00
}
# Data files to be installed to the system
_data_files = [
('share/icons/scalable/apps', ['deluge/ui/data/icons/scalable/apps/deluge.svg']),
('share/icons/hicolor/128x128/apps', ['deluge/ui/data/icons/hicolor/128x128/apps/deluge.png']),
('share/icons/hicolor/16x16/apps', ['deluge/ui/data/icons/hicolor/16x16/apps/deluge.png']),
('share/icons/hicolor/192x192/apps', ['deluge/ui/data/icons/hicolor/192x192/apps/deluge.png']),
('share/icons/hicolor/22x22/apps', ['deluge/ui/data/icons/hicolor/22x22/apps/deluge.png']),
('share/icons/hicolor/24x24/apps', ['deluge/ui/data/icons/hicolor/24x24/apps/deluge.png']),
('share/icons/hicolor/256x256/apps', ['deluge/ui/data/icons/hicolor/256x256/apps/deluge.png']),
('share/icons/hicolor/32x32/apps', ['deluge/ui/data/icons/hicolor/32x32/apps/deluge.png']),
('share/icons/hicolor/36x36/apps', ['deluge/ui/data/icons/hicolor/36x36/apps/deluge.png']),
('share/icons/hicolor/48x48/apps', ['deluge/ui/data/icons/hicolor/48x48/apps/deluge.png']),
('share/icons/hicolor/64x64/apps', ['deluge/ui/data/icons/hicolor/64x64/apps/deluge.png']),
('share/icons/hicolor/72x72/apps', ['deluge/ui/data/icons/hicolor/72x72/apps/deluge.png']),
('share/icons/hicolor/96x96/apps', ['deluge/ui/data/icons/hicolor/96x96/apps/deluge.png']),
('share/pixmaps', ['deluge/ui/data/pixmaps/deluge.png', 'deluge/ui/data/pixmaps/deluge.xpm']),
('share/man/man1', [
'docs/man/deluge.1',
'docs/man/deluged.1',
'docs/man/deluge-gtk.1',
'docs/man/deluge-web.1',
'docs/man/deluge-console.1'])
]
if not windows_check():
2011-07-30 03:56:48 +00:00
_data_files.append(('share/applications', ['deluge/ui/data/share/applications/deluge.desktop']))
2010-10-31 09:18:09 +00:00
entry_points = {
"console_scripts": [
"deluge-console = deluge.ui.console:start",
"deluge-web = deluge.ui.web:start",
"deluged = deluge.main:start_daemon"
],
"gui_scripts": [
"deluge = deluge.main:start_ui",
"deluge-gtk = deluge.ui.gtkui:start"
]
}
if windows_check():
2010-10-31 10:13:22 +00:00
entry_points["console_scripts"].append("deluge-debug = deluge.main:start_ui")
2010-10-31 09:18:09 +00:00
2007-07-04 08:24:30 +00:00
# Main setup
setup(
name = "deluge",
2010-05-05 21:46:27 +00:00
version = "1.3.900",
fullname = "Deluge Bittorrent Client",
description = "Bittorrent Client",
2009-10-04 23:19:34 +00:00
author = "Andrew Resch, Damien Churchill",
author_email = "andrewresch@gmail.com, damoxc@gmail.com",
keywords = "torrent bittorrent p2p fileshare filesharing",
long_description = """Deluge is a bittorrent client that utilizes a
2009-05-05 19:07:05 +00:00
daemon/client model. There are various user interfaces available for
2009-05-05 19:04:53 +00:00
Deluge such as the GTKui, the webui and a console ui. Deluge uses
libtorrent in it's backend to handle the bittorrent protocol.""",
url = "http://deluge-torrent.org",
license = "GPLv3",
cmdclass = cmdclass,
data_files = _data_files,
2008-07-10 04:40:13 +00:00
ext_package = "deluge",
ext_modules = _ext_modules,
2008-07-14 20:42:11 +00:00
package_data = {"deluge": ["ui/gtkui/glade/*.glade",
"ui/gtkui/glade/*.ui",
"ui/data/pixmaps/*.png",
"ui/data/pixmaps/*.svg",
"ui/data/pixmaps/*.ico",
"ui/data/pixmaps/*.gif",
"ui/data/pixmaps/flags/*.png",
"plugins/*.egg",
"i18n/*/LC_MESSAGES/*.mo",
"ui/web/gettext.js",
"ui/web/index.html",
"ui/web/css/*.css",
"ui/web/icons/*.png",
"ui/web/images/*.gif",
"ui/web/images/*.png",
"ui/web/js/*.js",
"ui/web/js/*/*.js",
"ui/web/js/*/.order",
"ui/web/js/*/*/*.js",
"ui/web/js/*/*/.order",
"ui/web/render/*.html",
"ui/web/themes/css/*.css",
"ui/web/themes/images/*/*.gif",
"ui/web/themes/images/*/*.png",
"ui/web/themes/images/*/*/*.gif",
"ui/web/themes/images/*/*/*.png"
]},
packages = find_packages(exclude=["plugins", "docs", "tests"]),
namespace_packages = ["deluge", "deluge.plugins"],
2010-10-31 09:18:09 +00:00
entry_points = entry_points
2008-07-10 04:40:13 +00:00
)