2015-08-26 15:53:21 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2015 Calum Lind <calumlind@gmail.com>
|
|
|
|
# Copyright (C) 2010 Damien Churchill <damoxc@gmail.com>
|
|
|
|
# Copyright (C) 2009-2010 Andrew Resch <andrewresch@gmail.com>
|
|
|
|
# Copyright (C) 2009 Jesper Lund <mail@jesperlund.com>
|
|
|
|
#
|
|
|
|
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
|
|
|
# the additional special exception to link portions of this program with the OpenSSL library.
|
|
|
|
# See LICENSE for more details.
|
|
|
|
#
|
2018-10-25 14:02:53 +00:00
|
|
|
# isort:skip_file
|
2015-10-23 23:58:14 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-09-19 14:43:21 +00:00
|
|
|
import glob
|
|
|
|
import os
|
2015-08-24 11:39:25 +00:00
|
|
|
import re
|
2010-10-29 09:11:40 +00:00
|
|
|
import shutil
|
2014-09-19 14:43:21 +00:00
|
|
|
import sys
|
|
|
|
|
2018-10-25 14:02:53 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
import bbfreeze
|
2015-07-15 22:09:49 +00:00
|
|
|
import gtk
|
2015-08-24 11:39:25 +00:00
|
|
|
from win32verstamp import stamp
|
2012-11-22 23:22:34 +00:00
|
|
|
|
2015-07-15 22:09:49 +00:00
|
|
|
import deluge.common
|
|
|
|
|
2015-08-24 14:54:19 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
class VersionInfo(object):
|
2018-10-02 14:39:51 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
version,
|
|
|
|
internalname=None,
|
|
|
|
originalfilename=None,
|
|
|
|
comments=None,
|
|
|
|
company=None,
|
|
|
|
description=None,
|
|
|
|
_copyright=None,
|
|
|
|
trademarks=None,
|
|
|
|
product=None,
|
|
|
|
dll=False,
|
|
|
|
debug=False,
|
|
|
|
verbose=True,
|
|
|
|
):
|
2016-11-03 21:26:46 +00:00
|
|
|
parts = version.split('.')
|
2015-08-24 11:39:25 +00:00
|
|
|
while len(parts) < 4:
|
2016-11-03 21:26:46 +00:00
|
|
|
parts.append('0')
|
|
|
|
self.version = '.'.join(parts)
|
2015-08-24 14:54:19 +00:00
|
|
|
self.internal_name = internalname
|
|
|
|
self.original_filename = originalfilename
|
2015-08-24 11:39:25 +00:00
|
|
|
self.comments = comments
|
|
|
|
self.company = company
|
|
|
|
self.description = description
|
2015-10-23 23:58:14 +00:00
|
|
|
self.copyright = _copyright
|
2015-08-24 11:39:25 +00:00
|
|
|
self.trademarks = trademarks
|
|
|
|
self.product = product
|
|
|
|
self.dll = dll
|
|
|
|
self.debug = debug
|
|
|
|
self.verbose = verbose
|
|
|
|
|
2016-11-16 22:18:18 +00:00
|
|
|
|
2015-08-26 15:53:21 +00:00
|
|
|
DEBUG = False
|
2016-11-03 21:26:46 +00:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1].lower() == 'debug':
|
2015-08-26 15:53:21 +00:00
|
|
|
DEBUG = True
|
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
# Get build_version from installed deluge.
|
2012-11-22 23:22:34 +00:00
|
|
|
build_version = deluge.common.get_version()
|
2013-07-10 03:46:38 +00:00
|
|
|
python_path = os.path.dirname(sys.executable)
|
2016-11-03 21:26:46 +00:00
|
|
|
if python_path.endswith('Scripts'):
|
2013-07-10 03:46:38 +00:00
|
|
|
python_path = python_path[:-8]
|
2016-11-03 21:26:46 +00:00
|
|
|
gtk_root = os.path.join(gtk.__path__[0], '..', 'runtime')
|
|
|
|
build_dir = os.path.join('build-win32', 'deluge-bbfreeze-' + build_version)
|
2015-08-26 15:53:21 +00:00
|
|
|
|
|
|
|
if DEBUG:
|
2016-11-03 21:26:46 +00:00
|
|
|
print('Python Path: %s' % python_path)
|
|
|
|
print('Gtk Path: %s' % gtk_root)
|
|
|
|
print('bbfreeze Output Path: %s' % build_dir)
|
2015-08-26 15:53:21 +00:00
|
|
|
|
2016-11-03 21:26:46 +00:00
|
|
|
print('Freezing Deluge %s...' % build_version)
|
2015-08-26 15:53:21 +00:00
|
|
|
# Disable printing to console for bbfreezing.
|
|
|
|
if not DEBUG:
|
2016-11-03 21:26:46 +00:00
|
|
|
sys.stdout = open(os.devnull, 'w')
|
2015-08-24 11:39:25 +00:00
|
|
|
|
|
|
|
# Include python modules not picked up automatically by bbfreeze.
|
2018-10-02 14:39:51 +00:00
|
|
|
includes = (
|
|
|
|
'libtorrent',
|
|
|
|
'cairo',
|
|
|
|
'pangocairo',
|
|
|
|
'atk',
|
|
|
|
'pango',
|
|
|
|
'twisted.internet.utils',
|
|
|
|
'gio',
|
|
|
|
'gzip',
|
|
|
|
'email.mime.multipart',
|
|
|
|
'email.mime.text',
|
|
|
|
'_cffi_backend',
|
|
|
|
)
|
2016-11-03 21:26:46 +00:00
|
|
|
excludes = ('numpy', 'OpenGL', 'psyco', 'win32ui', 'unittest')
|
2012-04-18 12:15:52 +00:00
|
|
|
|
2015-08-24 14:54:19 +00:00
|
|
|
|
2012-11-22 23:22:34 +00:00
|
|
|
def recipe_gtk_override(mf):
|
2015-08-24 14:54:19 +00:00
|
|
|
# Override bbfreeze function so that it includes all gtk libraries
|
|
|
|
# in the installer so users don't require a separate GTK+ installation.
|
2012-11-22 23:22:34 +00:00
|
|
|
return True
|
2016-11-16 22:18:18 +00:00
|
|
|
|
|
|
|
|
2012-11-22 23:22:34 +00:00
|
|
|
bbfreeze.recipes.recipe_gtk_and_friends = recipe_gtk_override
|
|
|
|
|
2016-05-19 16:18:34 +00:00
|
|
|
# Workaround for "ImportError: The 'packaging' package is required" with setuptools > 18.8.
|
|
|
|
# (https://github.com/pypa/setuptools/issues/517)
|
2018-10-02 14:39:51 +00:00
|
|
|
bbfreeze.recipes.recipe_pkg_resources = bbfreeze.recipes.include_whole_package(
|
|
|
|
'pkg_resources'
|
|
|
|
)
|
2016-05-19 16:18:34 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
fzr = bbfreeze.Freezer(build_dir, includes=includes, excludes=excludes)
|
|
|
|
fzr.include_py = False
|
2018-10-02 14:39:51 +00:00
|
|
|
fzr.setIcon(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(deluge.common.__file__), 'ui', 'data', 'pixmaps', 'deluge.ico'
|
|
|
|
)
|
|
|
|
)
|
2015-08-24 11:39:25 +00:00
|
|
|
|
|
|
|
# TODO: Can/should we grab the script list from setup.py entry_points somehow.
|
|
|
|
|
|
|
|
# Hide cmd console popup for these console entries force gui_script True.
|
2016-11-03 21:26:46 +00:00
|
|
|
force_gui = ['deluge-web', 'deluged']
|
2015-09-13 21:47:31 +00:00
|
|
|
|
|
|
|
for force_script in force_gui:
|
2016-11-03 21:26:46 +00:00
|
|
|
script_path = os.path.join(python_path, 'Scripts', force_script + '-script.py')
|
|
|
|
shutil.copy(script_path, script_path.replace('script', 'debug-script'))
|
2015-09-13 21:47:31 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
script_list = []
|
2016-11-03 21:26:46 +00:00
|
|
|
for script in glob.glob(os.path.join(python_path, 'Scripts\\deluge*-script.py*')):
|
2015-08-24 11:39:25 +00:00
|
|
|
# Copy the scripts to remove the '-script' suffix before adding to freezer.
|
2016-11-03 21:26:46 +00:00
|
|
|
new_script = script.replace('-script', '')
|
2015-08-24 11:39:25 +00:00
|
|
|
shutil.copy(script, new_script)
|
|
|
|
|
2015-08-26 15:53:21 +00:00
|
|
|
gui_script = False
|
2015-08-24 11:39:25 +00:00
|
|
|
script_splitext = os.path.splitext(os.path.basename(new_script))
|
2016-11-03 21:26:46 +00:00
|
|
|
if script_splitext[1] == '.pyw' or script_splitext[0] in force_gui:
|
2015-08-24 11:39:25 +00:00
|
|
|
gui_script = True
|
|
|
|
try:
|
|
|
|
fzr.addScript(new_script, gui_only=gui_script)
|
|
|
|
script_list.append(new_script)
|
2015-10-23 23:58:14 +00:00
|
|
|
except Exception:
|
2015-08-24 11:39:25 +00:00
|
|
|
os.remove(script)
|
|
|
|
|
|
|
|
# Start the freezing process.
|
|
|
|
fzr()
|
|
|
|
|
|
|
|
# Clean up the duplicated scripts.
|
|
|
|
for script in script_list:
|
|
|
|
os.remove(script)
|
2010-10-29 09:11:40 +00:00
|
|
|
|
2015-09-17 08:56:58 +00:00
|
|
|
# Exclude files which are already included in GTK or Windows. Also exclude unneeded pygame dlls.
|
2018-10-02 14:39:51 +00:00
|
|
|
excludeDlls = (
|
|
|
|
'MSIMG32.dll',
|
|
|
|
'MSVCR90.dll',
|
|
|
|
'MSVCP90.dll',
|
|
|
|
'MSVCR120.dll',
|
|
|
|
'POWRPROF.dll',
|
|
|
|
'DNSAPI.dll',
|
|
|
|
'USP10.dll',
|
|
|
|
'MPR.dll',
|
|
|
|
'jpeg.dll',
|
|
|
|
'libfreetype-6.dll',
|
|
|
|
'libpng12-0.dll',
|
|
|
|
'libtiff.dll',
|
|
|
|
'SDL_image.dll',
|
|
|
|
'SDL_ttf.dll',
|
|
|
|
)
|
2015-10-23 23:58:14 +00:00
|
|
|
for exclude_dll in excludeDlls:
|
2015-08-26 15:53:21 +00:00
|
|
|
try:
|
2015-10-23 23:58:14 +00:00
|
|
|
os.remove(os.path.join(build_dir, exclude_dll))
|
2015-08-26 15:53:21 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Re-enable printing.
|
|
|
|
if not DEBUG:
|
|
|
|
sys.stdout = sys.__stdout__
|
2012-11-22 23:22:34 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
# Copy gtk locale files.
|
2012-11-22 23:22:34 +00:00
|
|
|
gtk_locale = os.path.join(gtk_root, 'share/locale')
|
|
|
|
locale_include_list = ['gtk20.mo', 'locale.alias']
|
2014-09-19 18:10:09 +00:00
|
|
|
|
|
|
|
|
2015-10-23 23:58:14 +00:00
|
|
|
def ignored_files(adir, ignore_filenames):
|
2012-11-22 23:22:34 +00:00
|
|
|
return [
|
2018-10-02 14:39:51 +00:00
|
|
|
ignore_file
|
|
|
|
for ignore_file in ignore_filenames
|
|
|
|
if not os.path.isdir(os.path.join(adir, ignore_file))
|
|
|
|
and ignore_file not in locale_include_list
|
2014-09-19 18:10:09 +00:00
|
|
|
]
|
2016-11-16 22:18:18 +00:00
|
|
|
|
|
|
|
|
2018-10-02 14:39:51 +00:00
|
|
|
shutil.copytree(
|
|
|
|
gtk_locale, os.path.join(build_dir, 'share/locale'), ignore=ignored_files
|
|
|
|
)
|
2012-11-22 23:22:34 +00:00
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
# Copy gtk theme files.
|
2012-11-22 23:22:34 +00:00
|
|
|
theme_include_list = [
|
2016-11-03 21:26:46 +00:00
|
|
|
[gtk_root, 'share/icons/hicolor/index.theme'],
|
|
|
|
[gtk_root, 'lib/gtk-2.0/2.10.0/engines'],
|
|
|
|
[gtk_root, 'share/themes/MS-Windows'],
|
|
|
|
['DelugeStart Theme', 'lib/gtk-2.0/2.10.0/engines/libmurrine.dll'],
|
|
|
|
['DelugeStart Theme', 'share/themes/DelugeStart'],
|
2018-06-01 14:35:19 +00:00
|
|
|
['DelugeStart Theme', 'etc/gtk-2.0/gtkrc'],
|
2014-09-19 18:10:09 +00:00
|
|
|
]
|
2013-02-22 16:34:34 +00:00
|
|
|
for path_root, path in theme_include_list:
|
|
|
|
full_path = os.path.join(path_root, path)
|
2012-11-22 23:22:34 +00:00
|
|
|
if os.path.isdir(full_path):
|
2015-08-24 11:39:25 +00:00
|
|
|
shutil.copytree(full_path, os.path.join(build_dir, path))
|
2012-11-22 23:22:34 +00:00
|
|
|
else:
|
2015-08-24 11:39:25 +00:00
|
|
|
dst_dir = os.path.join(build_dir, os.path.dirname(path))
|
2012-11-22 23:22:34 +00:00
|
|
|
try:
|
|
|
|
os.makedirs(dst_dir)
|
2015-10-23 23:58:14 +00:00
|
|
|
except OSError:
|
2012-11-22 23:22:34 +00:00
|
|
|
pass
|
|
|
|
shutil.copy(full_path, dst_dir)
|
|
|
|
|
2015-08-26 15:53:21 +00:00
|
|
|
# Add version information to exe files.
|
|
|
|
for script in script_list:
|
2016-11-03 21:26:46 +00:00
|
|
|
script_exe = os.path.splitext(os.path.basename(script))[0] + '.exe'
|
2015-08-26 15:53:21 +00:00
|
|
|
# Don't add to dev build versions.
|
|
|
|
if not re.search('[a-zA-Z_-]', build_version):
|
2018-10-02 14:39:51 +00:00
|
|
|
versionInfo = VersionInfo(
|
|
|
|
build_version,
|
|
|
|
description='Deluge Bittorrent Client',
|
|
|
|
company='Deluge Team',
|
|
|
|
product='Deluge',
|
|
|
|
_copyright='Deluge Team',
|
|
|
|
)
|
2015-08-26 15:53:21 +00:00
|
|
|
stamp(os.path.join(build_dir, script_exe), versionInfo)
|
|
|
|
|
2015-08-24 11:39:25 +00:00
|
|
|
# Copy version info to file for nsis script.
|
2015-08-26 15:53:21 +00:00
|
|
|
with open('VERSION.tmp', 'w') as ver_file:
|
2016-11-03 22:37:00 +00:00
|
|
|
ver_file.write('build_version = "%s"' % build_version)
|
2015-09-10 13:24:32 +00:00
|
|
|
|
|
|
|
# Create the install and uninstall file list for NSIS.
|
|
|
|
filedir_list = []
|
|
|
|
for root, dirnames, filenames in os.walk(build_dir):
|
|
|
|
dirnames.sort()
|
|
|
|
filenames.sort()
|
2018-10-02 14:39:51 +00:00
|
|
|
filedir_list.append((root[len(build_dir) :], filenames))
|
2015-09-10 13:24:32 +00:00
|
|
|
|
|
|
|
with open('install_files.nsh', 'w') as f:
|
|
|
|
f.write('; Files to install\n')
|
|
|
|
for dirname, files in filedir_list:
|
|
|
|
if not dirname:
|
|
|
|
dirname = os.sep
|
|
|
|
f.write('\nSetOutPath "$INSTDIR%s"\n' % dirname)
|
|
|
|
for filename in files:
|
|
|
|
f.write('File "${BBFREEZE_DIR}%s"\n' % os.path.join(dirname, filename))
|
|
|
|
|
|
|
|
with open('uninstall_files.nsh', 'w') as f:
|
|
|
|
f.write('; Files to uninstall\n')
|
|
|
|
for dirname, files in reversed(filedir_list):
|
|
|
|
f.write('\n')
|
|
|
|
if not dirname:
|
|
|
|
dirname = os.sep
|
|
|
|
for filename in files:
|
|
|
|
f.write('Delete "$INSTDIR%s"\n' % os.path.join(dirname, filename))
|
|
|
|
f.write('RMDir "$INSTDIR%s"\n' % dirname)
|