2009-12-30 16:34:41 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-12-30
|
2015-01-03 21:30:57 +00:00
|
|
|
# Copyright 2015 Hardcoded Software (http://www.hardcoded.net)
|
2014-10-05 20:31:16 +00:00
|
|
|
#
|
2015-01-03 21:33:16 +00:00
|
|
|
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
|
2014-10-05 20:31:16 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2015-01-03 21:33:16 +00:00
|
|
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
2009-12-30 16:34:41 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path as op
|
2010-04-07 10:56:43 +00:00
|
|
|
import compileall
|
2010-02-09 14:52:09 +00:00
|
|
|
import shutil
|
2011-01-11 15:21:36 +00:00
|
|
|
import json
|
2012-04-07 15:21:38 +00:00
|
|
|
from argparse import ArgumentParser
|
2013-03-24 16:02:41 +00:00
|
|
|
import platform
|
2014-04-18 17:22:04 +00:00
|
|
|
import glob
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2011-09-22 13:32:09 +00:00
|
|
|
from hscommon.plat import ISWINDOWS, ISLINUX
|
2014-10-13 19:08:59 +00:00
|
|
|
from hscommon.build import (
|
|
|
|
add_to_pythonpath, print_and_do, copy_packages, build_debian_changelog,
|
2012-06-20 17:09:42 +00:00
|
|
|
copy_qt_plugins, get_module_version, filereplace, copy, setup_package_argparser,
|
2014-10-13 19:08:59 +00:00
|
|
|
package_cocoa_app_in_dmg, copy_all, find_in_path
|
|
|
|
)
|
2010-02-09 14:42:48 +00:00
|
|
|
|
2012-04-07 15:21:38 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = ArgumentParser()
|
2012-06-20 17:09:42 +00:00
|
|
|
setup_package_argparser(parser)
|
|
|
|
return parser.parse_args()
|
2012-04-07 15:21:38 +00:00
|
|
|
|
2012-06-20 17:09:42 +00:00
|
|
|
def package_cocoa(edition, args):
|
2010-02-09 14:42:48 +00:00
|
|
|
app_path = {
|
2012-07-29 16:59:39 +00:00
|
|
|
'se': 'build/dupeGuru.app',
|
|
|
|
'me': 'build/dupeGuru ME.app',
|
|
|
|
'pe': 'build/dupeGuru PE.app',
|
2010-02-09 14:42:48 +00:00
|
|
|
}[edition]
|
2012-06-20 17:09:42 +00:00
|
|
|
package_cocoa_app_in_dmg(app_path, '.', args)
|
2010-02-09 14:42:48 +00:00
|
|
|
|
2010-04-08 10:17:03 +00:00
|
|
|
def package_windows(edition, dev):
|
2011-09-22 13:32:09 +00:00
|
|
|
if not ISWINDOWS:
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Qt packaging only works under Windows.")
|
2010-02-09 14:42:48 +00:00
|
|
|
return
|
2014-04-18 17:22:04 +00:00
|
|
|
from cx_Freeze import setup, Executable
|
2014-04-21 14:00:53 +00:00
|
|
|
from PyQt5.QtCore import QLibraryInfo
|
2010-02-09 14:42:48 +00:00
|
|
|
add_to_pythonpath('.')
|
2011-01-13 10:56:46 +00:00
|
|
|
app_version = get_module_version('core_{}'.format(edition))
|
2010-10-05 08:48:07 +00:00
|
|
|
distdir = 'dist'
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2010-10-05 08:48:07 +00:00
|
|
|
if op.exists(distdir):
|
|
|
|
shutil.rmtree(distdir)
|
2014-10-05 20:31:16 +00:00
|
|
|
|
2010-04-08 10:17:03 +00:00
|
|
|
if not dev:
|
|
|
|
# Copy qt plugins
|
2014-04-18 17:22:04 +00:00
|
|
|
plugin_dest = distdir
|
2010-04-08 10:17:03 +00:00
|
|
|
plugin_names = ['accessible', 'codecs', 'iconengines', 'imageformats']
|
|
|
|
copy_qt_plugins(plugin_names, plugin_dest)
|
2014-04-18 17:22:04 +00:00
|
|
|
|
2014-10-13 19:08:59 +00:00
|
|
|
# Since v4.2.3, cx_freeze started to falsely include tkinter in the package. We exclude it
|
|
|
|
# explicitly because of that.
|
2014-04-18 17:22:04 +00:00
|
|
|
options = {
|
|
|
|
'build_exe': {
|
|
|
|
'includes': 'atexit',
|
|
|
|
'excludes': ['tkinter'],
|
|
|
|
'bin_excludes': ['icudt51', 'icuin51.dll', 'icuuc51.dll'],
|
|
|
|
'icon': 'images\\dg{0}_logo.ico'.format(edition),
|
|
|
|
'include_msvcr': True,
|
|
|
|
},
|
|
|
|
'install_exe': {
|
|
|
|
'install_dir': 'dist',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
executables = [
|
|
|
|
Executable(
|
|
|
|
'run.py',
|
|
|
|
base='Win32GUI',
|
|
|
|
targetDir=distdir,
|
|
|
|
targetName={'se': 'dupeGuru', 'me': 'dupeGuru ME', 'pe': 'dupeGuru PE'}[edition] + '.exe',
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
setup(
|
|
|
|
script_args=['install'],
|
|
|
|
options=options,
|
|
|
|
executables=executables
|
|
|
|
)
|
|
|
|
|
2014-04-21 14:00:53 +00:00
|
|
|
print("Removing useless files")
|
2014-04-18 17:22:04 +00:00
|
|
|
# Debug info that cx_freeze brings in.
|
|
|
|
for fn in glob.glob(op.join(distdir, '*', '*.pdb')):
|
|
|
|
os.remove(fn)
|
2014-04-21 14:00:53 +00:00
|
|
|
print("Copying forgotten DLLs")
|
|
|
|
qtlibpath = QLibraryInfo.location(QLibraryInfo.LibrariesPath)
|
|
|
|
shutil.copy(op.join(qtlibpath, 'libEGL.dll'), distdir)
|
|
|
|
shutil.copy(find_in_path('msvcp110.dll'), distdir)
|
|
|
|
print("Copying the rest")
|
2011-01-13 10:56:46 +00:00
|
|
|
help_path = op.join('build', 'help')
|
2011-11-30 16:06:08 +00:00
|
|
|
print("Copying {} to dist\\help".format(help_path))
|
2010-10-05 08:48:07 +00:00
|
|
|
shutil.copytree(help_path, op.join(distdir, 'help'))
|
2011-11-30 16:06:08 +00:00
|
|
|
locale_path = op.join('build', 'locale')
|
|
|
|
print("Copying {} to dist\\locale".format(locale_path))
|
|
|
|
shutil.copytree(locale_path, op.join(distdir, 'locale'))
|
2010-02-09 14:42:48 +00:00
|
|
|
|
|
|
|
# AdvancedInstaller.com has to be in your PATH
|
|
|
|
# this is so we don'a have to re-commit installer.aip at every version change
|
2014-04-18 17:22:04 +00:00
|
|
|
installer_file = 'installer.aip'
|
2013-03-24 16:02:41 +00:00
|
|
|
installer_path = op.join('qt', edition, installer_file)
|
2010-10-05 08:48:07 +00:00
|
|
|
shutil.copy(installer_path, 'installer_tmp.aip')
|
2011-01-13 10:56:46 +00:00
|
|
|
print_and_do('AdvancedInstaller.com /edit installer_tmp.aip /SetVersion %s' % app_version)
|
2010-02-09 14:42:48 +00:00
|
|
|
print_and_do('AdvancedInstaller.com /build installer_tmp.aip -force')
|
|
|
|
os.remove('installer_tmp.aip')
|
2010-10-05 08:48:07 +00:00
|
|
|
if op.exists('installer_tmp.back.aip'):
|
|
|
|
os.remove('installer_tmp.back.aip')
|
2009-12-30 16:34:41 +00:00
|
|
|
|
2013-09-22 13:38:52 +00:00
|
|
|
def copy_files_to_package(destpath, packages, with_so):
|
|
|
|
# when with_so is true, we keep .so files in the package, and otherwise, we don't. We need this
|
|
|
|
# flag because when building debian src pkg, we *don't* want .so files (they're compiled later)
|
|
|
|
# and when we're packaging under Arch, we're packaging a binary package, so we want them.
|
2013-04-14 21:21:08 +00:00
|
|
|
if op.exists(destpath):
|
|
|
|
shutil.rmtree(destpath)
|
|
|
|
os.makedirs(destpath)
|
|
|
|
shutil.copy('run.py', op.join(destpath, 'run.py'))
|
2013-09-22 13:38:52 +00:00
|
|
|
extra_ignores = ['*.so'] if not with_so else None
|
|
|
|
copy_packages(packages, destpath, extra_ignores=extra_ignores)
|
2013-04-14 21:21:08 +00:00
|
|
|
os.remove(op.join(destpath, 'qt', 'run_template.py')) # It doesn't belong in the package.
|
|
|
|
shutil.copytree(op.join('build', 'help'), op.join(destpath, 'help'))
|
|
|
|
shutil.copytree(op.join('build', 'locale'), op.join(destpath, 'locale'))
|
|
|
|
compileall.compile_dir(destpath)
|
|
|
|
|
2012-10-26 14:23:50 +00:00
|
|
|
def package_debian_distribution(edition, distribution):
|
2011-01-13 10:56:46 +00:00
|
|
|
app_version = get_module_version('core_{}'.format(edition))
|
2012-10-26 14:23:50 +00:00
|
|
|
version = '{}~{}'.format(app_version, distribution)
|
2010-04-07 10:56:43 +00:00
|
|
|
ed = lambda s: s.format(edition)
|
2012-10-26 14:23:50 +00:00
|
|
|
destpath = op.join('build', 'dupeguru-{0}-{1}'.format(edition, version))
|
2010-04-07 10:56:43 +00:00
|
|
|
srcpath = op.join(destpath, 'src')
|
2014-10-05 20:31:16 +00:00
|
|
|
packages = ['hscommon', 'core', ed('core_{0}'), 'qtlib', 'qt', 'send2trash']
|
2010-07-14 09:40:46 +00:00
|
|
|
if edition == 'me':
|
|
|
|
packages.append('hsaudiotag')
|
2013-09-22 13:38:52 +00:00
|
|
|
copy_files_to_package(srcpath, packages, with_so=False)
|
2012-07-11 16:22:00 +00:00
|
|
|
if edition == 'pe':
|
|
|
|
os.mkdir(op.join(destpath, 'modules'))
|
|
|
|
copy_all(op.join('core_pe', 'modules', '*.*'), op.join(destpath, 'modules'))
|
|
|
|
copy(op.join('qt', 'pe', 'modules', 'block.c'), op.join(destpath, 'modules', 'block_qt.c'))
|
2014-04-19 21:48:48 +00:00
|
|
|
copy(op.join('pkg', 'debian', 'build_pe_modules.py'), op.join(destpath, 'build_pe_modules.py'))
|
2012-06-16 14:35:23 +00:00
|
|
|
debdest = op.join(destpath, 'debian')
|
2014-04-19 21:48:48 +00:00
|
|
|
debskel = op.join('pkg', 'debian')
|
2012-06-16 14:35:23 +00:00
|
|
|
os.makedirs(debdest)
|
2014-04-19 21:48:48 +00:00
|
|
|
debopts = json.load(open(op.join(debskel, ed('{}.json'))))
|
2012-07-11 19:07:29 +00:00
|
|
|
for fn in ['compat', 'copyright', 'dirs', 'rules']:
|
2014-04-19 21:48:48 +00:00
|
|
|
copy(op.join(debskel, fn), op.join(debdest, fn))
|
|
|
|
filereplace(op.join(debskel, 'control'), op.join(debdest, 'control'), **debopts)
|
|
|
|
filereplace(op.join(debskel, 'Makefile'), op.join(destpath, 'Makefile'), **debopts)
|
|
|
|
filereplace(op.join(debskel, 'dupeguru.desktop'), op.join(debdest, ed('dupeguru_{}.desktop')), **debopts)
|
2011-01-13 11:23:21 +00:00
|
|
|
changelogpath = op.join('help', ed('changelog_{}'))
|
2012-06-16 14:35:23 +00:00
|
|
|
changelog_dest = op.join(debdest, 'changelog')
|
|
|
|
project_name = debopts['pkgname']
|
2010-04-07 10:56:43 +00:00
|
|
|
from_version = {'se': '2.9.2', 'me': '5.7.2', 'pe': '1.8.5'}[edition]
|
2014-10-13 19:08:59 +00:00
|
|
|
build_debian_changelog(
|
|
|
|
changelogpath, changelog_dest, project_name, from_version=from_version,
|
|
|
|
distribution=distribution
|
|
|
|
)
|
2010-04-07 10:56:43 +00:00
|
|
|
shutil.copy(op.join('images', ed('dg{0}_logo_128.png')), srcpath)
|
|
|
|
os.chdir(destpath)
|
2012-10-26 14:23:50 +00:00
|
|
|
cmd = "dpkg-buildpackage -S"
|
2012-07-11 20:21:40 +00:00
|
|
|
os.system(cmd)
|
2012-10-26 14:23:50 +00:00
|
|
|
os.chdir('../..')
|
|
|
|
|
|
|
|
def package_debian(edition):
|
2013-04-14 21:21:08 +00:00
|
|
|
print("Packaging for Ubuntu")
|
2014-10-26 16:18:49 +00:00
|
|
|
for distribution in ['trusty', 'utopic']:
|
2012-10-26 14:23:50 +00:00
|
|
|
package_debian_distribution(edition, distribution)
|
2010-04-07 10:56:43 +00:00
|
|
|
|
2013-04-14 21:21:08 +00:00
|
|
|
def package_arch(edition):
|
|
|
|
# For now, package_arch() will only copy the source files into build/. It copies less packages
|
|
|
|
# than package_debian because there are more python packages available in Arch (so we don't
|
|
|
|
# need to include them).
|
|
|
|
print("Packaging for Arch")
|
|
|
|
ed = lambda s: s.format(edition)
|
2013-04-14 21:37:01 +00:00
|
|
|
srcpath = op.join('build', ed('dupeguru-{}-arch'))
|
2014-10-05 20:31:16 +00:00
|
|
|
packages = ['hscommon', 'core', ed('core_{0}'), 'qtlib', 'qt', 'send2trash']
|
2013-04-14 21:21:08 +00:00
|
|
|
if edition == 'me':
|
|
|
|
packages.append('hsaudiotag')
|
2013-09-22 13:38:52 +00:00
|
|
|
copy_files_to_package(srcpath, packages, with_so=True)
|
2013-04-14 21:39:13 +00:00
|
|
|
shutil.copy(op.join('images', ed('dg{}_logo_128.png')), srcpath)
|
2014-04-19 21:48:48 +00:00
|
|
|
debopts = json.load(open(op.join('pkg', 'arch', ed('{}.json'))))
|
|
|
|
filereplace(op.join('pkg', 'arch', 'dupeguru.desktop'), op.join(srcpath, ed('dupeguru-{}.desktop')), **debopts)
|
2013-04-14 21:21:08 +00:00
|
|
|
|
2013-05-05 14:47:43 +00:00
|
|
|
def package_source_tgz(edition):
|
2013-12-21 17:13:26 +00:00
|
|
|
if not op.exists('deps'):
|
|
|
|
print("Downloading PyPI dependencies")
|
2014-01-26 14:41:15 +00:00
|
|
|
print_and_do('./download_deps.sh')
|
2013-12-21 17:13:26 +00:00
|
|
|
print("Creating git archive")
|
2013-05-05 14:47:43 +00:00
|
|
|
app_version = get_module_version('core_{}'.format(edition))
|
2013-12-21 17:13:26 +00:00
|
|
|
name = 'dupeguru-{}-src-{}.tar'.format(edition, app_version)
|
2013-05-05 14:47:43 +00:00
|
|
|
dest = op.join('build', name)
|
2013-06-23 13:36:44 +00:00
|
|
|
print_and_do('git archive -o {} HEAD'.format(dest))
|
2013-12-21 17:13:26 +00:00
|
|
|
print("Adding dependencies and wrapping up")
|
|
|
|
print_and_do('tar -rf {} deps'.format(dest))
|
|
|
|
print_and_do('gzip {}'.format(dest))
|
2013-05-05 14:47:43 +00:00
|
|
|
|
2009-12-30 16:34:41 +00:00
|
|
|
def main():
|
2012-04-07 15:21:38 +00:00
|
|
|
args = parse_args()
|
2011-01-11 15:21:36 +00:00
|
|
|
conf = json.load(open('conf.json'))
|
2009-12-30 16:34:41 +00:00
|
|
|
edition = conf['edition']
|
|
|
|
ui = conf['ui']
|
|
|
|
dev = conf['dev']
|
2013-05-05 14:47:43 +00:00
|
|
|
if args.src_pkg:
|
|
|
|
print("Creating source package for dupeGuru {}".format(edition.upper()))
|
|
|
|
package_source_tgz(edition)
|
|
|
|
return
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Packaging dupeGuru {0} with UI {1}".format(edition.upper(), ui))
|
2009-12-30 16:34:41 +00:00
|
|
|
if ui == 'cocoa':
|
2012-06-20 17:09:42 +00:00
|
|
|
package_cocoa(edition, args)
|
2009-12-30 16:34:41 +00:00
|
|
|
elif ui == 'qt':
|
2011-09-22 13:32:09 +00:00
|
|
|
if ISWINDOWS:
|
2010-04-08 10:17:03 +00:00
|
|
|
package_windows(edition, dev)
|
2011-09-22 13:32:09 +00:00
|
|
|
elif ISLINUX:
|
2014-10-17 19:58:45 +00:00
|
|
|
if not args.arch_pkg:
|
|
|
|
distname, _, _ = platform.dist()
|
|
|
|
else:
|
|
|
|
distname = 'arch'
|
2013-04-14 21:21:08 +00:00
|
|
|
if distname == 'arch':
|
|
|
|
package_arch(edition)
|
|
|
|
else:
|
|
|
|
package_debian(edition)
|
2010-04-07 10:56:43 +00:00
|
|
|
else:
|
2010-08-11 14:39:06 +00:00
|
|
|
print("Qt packaging only works under Windows or Linux.")
|
2009-12-30 16:34:41 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2010-04-07 10:56:43 +00:00
|
|
|
main()
|
2014-10-17 19:58:45 +00:00
|
|
|
|