forked from arsenetar/dupeguru
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.py
219 lines (199 loc) · 8.29 KB
/
package.py
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
215
216
217
218
# Copyright 2016 Hardcoded Software (http://www.hardcoded.net)
#
# This software is licensed under the "GPLv3" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.gnu.org/licenses/gpl-3.0.html
import os
import os.path as op
import compileall
import shutil
import json
from argparse import ArgumentParser
import platform
import glob
from hscommon.plat import ISOSX, ISWINDOWS, ISLINUX
from hscommon.build import (
print_and_do, copy_packages, build_debian_changelog,
get_module_version, filereplace, copy, setup_package_argparser,
package_cocoa_app_in_dmg, copy_all,
add_to_pythonpath, copy_qt_plugins, find_in_path
)
def parse_args():
parser = ArgumentParser()
setup_package_argparser(parser)
return parser.parse_args()
def package_cocoa(args):
app_path = 'build/dupeGuru.app'
package_cocoa_app_in_dmg(app_path, '.', args)
def package_windows():
if not ISWINDOWS:
print("Qt packaging only works under Windows.")
return
from cx_Freeze import setup, Executable
from PyQt5.QtCore import QLibraryInfo
add_to_pythonpath('.')
app_version = get_module_version('core')
distdir = 'dist'
if op.exists(distdir):
shutil.rmtree(distdir)
plugin_dest = distdir
plugin_names = ['accessible', 'codecs', 'iconengines', 'imageformats']
copy_qt_plugins(plugin_names, plugin_dest)
# Since v4.2.3, cx_freeze started to falsely include tkinter in the package. We exclude it
# explicitly because of that.
options = {
'build_exe': {
'includes': 'atexit',
'excludes': ['tkinter'],
'bin_excludes': ['icudt51', 'icuin51.dll', 'icuuc51.dll'],
#'icon': 'images\\dgse_logo.ico',
'include_msvcr': True,
},
'install_exe': {
'install_dir': 'dist',
}
}
executables = [
Executable(
'run.py',
base='Win32GUI',
#targetDir=distdir,
icon='images\\dgse_logo.ico',
targetName='dupeGuru.exe'
)
]
setup(
script_args=['install'],
options=options,
executables=executables
)
print("Removing useless files")
# Debug info that cx_freeze brings in.
for fn in glob.glob(op.join(distdir, '*', '*.pdb')):
os.remove(fn)
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)
#AK: added this as cxfreeze is not picking it up
shutil.copy(find_in_path('sqlite3.dll'), distdir)
print("Copying the rest")
help_path = op.join('build', 'help')
print("Copying {} to dist\\help".format(help_path))
shutil.copytree(help_path, op.join(distdir, 'help'))
locale_path = op.join('build', 'locale')
print("Copying {} to dist\\locale".format(locale_path))
shutil.copytree(locale_path, op.join(distdir, 'locale'))
# NSIS has to be in your PATH for this to work
versionlist = app_version.split('.') if len(app_version) >= 5 else '0.0.0'
versionparams = '/DVERSIONMAJOR={} /DVERSIONMINOR={} /DVERSIONBUILD={}'.format(versionlist[0], versionlist[1], versionlist[2])
nsis_cmd = 'makensis ' + versionparams + ' scripts/dupeguru.nsi'
print_and_do(nsis_cmd)
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.
if op.exists(destpath):
shutil.rmtree(destpath)
os.makedirs(destpath)
shutil.copy('run.py', op.join(destpath, 'run.py'))
extra_ignores = ['*.so'] if not with_so else None
copy_packages(packages, destpath, extra_ignores=extra_ignores)
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)
def package_debian_distribution(distribution):
app_version = get_module_version('core')
version = '{}~{}'.format(app_version, distribution)
destpath = op.join('build', 'dupeguru-{}'.format(version))
srcpath = op.join(destpath, 'src')
packages = [
'hscommon', 'core', 'qtlib', 'qt', 'send2trash', 'hsaudiotag'
]
copy_files_to_package(srcpath, packages, with_so=False)
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'))
copy(op.join('pkg', 'debian', 'build_pe_modules.py'), op.join(destpath, 'build_pe_modules.py'))
debdest = op.join(destpath, 'debian')
debskel = op.join('pkg', 'debian')
os.makedirs(debdest)
debopts = json.load(open(op.join(debskel, 'dupeguru.json')))
for fn in ['compat', 'copyright', 'dirs', 'rules']:
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, 'dupeguru.desktop'), **debopts)
changelogpath = op.join('help', 'changelog')
changelog_dest = op.join(debdest, 'changelog')
project_name = debopts['pkgname']
from_version = '2.9.2'
build_debian_changelog(
changelogpath, changelog_dest, project_name, from_version=from_version,
distribution=distribution
)
shutil.copy(op.join('images', 'dgse_logo_128.png'), srcpath)
os.chdir(destpath)
cmd = "dpkg-buildpackage -S"
os.system(cmd)
os.chdir('../..')
def package_debian():
print("Packaging for Ubuntu")
for distribution in ['trusty', 'xenial']:
package_debian_distribution(distribution)
def package_arch():
# 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")
srcpath = op.join('build', 'dupeguru-arch')
packages = [
'hscommon', 'core', 'qtlib', 'qt', 'send2trash', 'hsaudiotag',
]
copy_files_to_package(srcpath, packages, with_so=True)
shutil.copy(op.join('images', 'dgse_logo_128.png'), srcpath)
debopts = json.load(open(op.join('pkg', 'arch', 'dupeguru.json')))
filereplace(op.join('pkg', 'arch', 'dupeguru.desktop'), op.join(srcpath, 'dupeguru.desktop'), **debopts)
def package_source_tgz():
print("Creating git archive")
app_version = get_module_version('core')
name = 'dupeguru-src-{}.tar'.format(app_version)
base_path = os.getcwd()
build_path = op.join(base_path, 'build')
dest = op.join(build_path, name)
print_and_do('git archive -o {} HEAD'.format(dest))
# Now, we need to include submodules
SUBMODULES = ['hscommon', 'qtlib', 'cocoalib']
for submodule in SUBMODULES:
print("Adding submodule {} to archive".format(submodule))
os.chdir(submodule)
archive_path = op.join(build_path, '{}.tar'.format(submodule))
print_and_do('git archive -o {} --prefix {}/ HEAD'.format(archive_path, submodule))
os.chdir(base_path)
print_and_do('tar -A {} -f {}'.format(archive_path, dest))
print_and_do('gzip {}'.format(dest))
def main():
args = parse_args()
ui = 'cocoa' if ISOSX else 'qt'
if args.src_pkg:
print("Creating source package for dupeGuru")
package_source_tgz()
return
print("Packaging dupeGuru with UI {}".format(ui))
if ui == 'cocoa':
package_cocoa(args)
elif ui == 'qt':
if ISWINDOWS:
package_windows()
elif ISLINUX:
if not args.arch_pkg:
distname, _, _ = platform.dist()
else:
distname = 'arch'
if distname == 'arch':
package_arch()
else:
package_debian()
if __name__ == '__main__':
main()