| 1 |
# -*- mode: python -*- |
| 2 |
import os |
| 3 |
|
| 4 |
from PyInstaller.utils.hooks import ( |
| 5 |
collect_data_files, |
| 6 |
collect_submodules, |
| 7 |
copy_metadata, |
| 8 |
) |
| 9 |
|
| 10 |
datas = [] |
| 11 |
binaries = [] |
| 12 |
hiddenimports = ['pygame', 'ifaddr'] |
| 13 |
|
| 14 |
# Collect Meta Data |
| 15 |
datas += copy_metadata('deluge', recursive=True) |
| 16 |
datas += copy_metadata('service-identity', recursive=True) |
| 17 |
|
| 18 |
# Add Deluge Hidden Imports |
| 19 |
hiddenimports += collect_submodules('deluge') |
| 20 |
|
| 21 |
# Add stdlib as Hidden Imports. |
| 22 |
# This is filtered list that excludes some common examples or stuff not useful in |
| 23 |
# plugins (such as tty, mailbox, turtledemo etc.). |
| 24 |
# It is safe to assume that 90% of that list would already be included anyway. |
| 25 |
stdlib = [ |
| 26 |
'string', |
| 27 |
're', |
| 28 |
'unicodedata', |
| 29 |
'struct', |
| 30 |
'codecs', |
| 31 |
'datetime', |
| 32 |
'zoneinfo', |
| 33 |
'calendar', |
| 34 |
'collections', |
| 35 |
'array', |
| 36 |
'weakref', |
| 37 |
'types', |
| 38 |
'copy', |
| 39 |
'enum', |
| 40 |
'numbers', |
| 41 |
'math', |
| 42 |
'cmath', |
| 43 |
'decimal', |
| 44 |
'fractions', |
| 45 |
'random', |
| 46 |
'statistics', |
| 47 |
'itertools', |
| 48 |
'functools', |
| 49 |
'operator', |
| 50 |
'pathlib', |
| 51 |
'fileinput', |
| 52 |
'stat', |
| 53 |
'tempfile', |
| 54 |
'glob', |
| 55 |
'fnmatch', |
| 56 |
'shutil', |
| 57 |
'pickle', |
| 58 |
'copyreg', |
| 59 |
'shelve', |
| 60 |
'marshal', |
| 61 |
'dom', |
| 62 |
'sqlite3', |
| 63 |
'zlib', |
| 64 |
'gzip', |
| 65 |
'bz2', |
| 66 |
'lzma', |
| 67 |
'csv', |
| 68 |
'hashlib', |
| 69 |
'hmac', |
| 70 |
'secrets', |
| 71 |
'os', |
| 72 |
'io', |
| 73 |
'time', |
| 74 |
'logging', |
| 75 |
'platform', |
| 76 |
'errno', |
| 77 |
'queue', |
| 78 |
'socket', |
| 79 |
'ssl', |
| 80 |
'email', |
| 81 |
'json', |
| 82 |
'mimetypes', |
| 83 |
'base64', |
| 84 |
'binhex', |
| 85 |
'binascii', |
| 86 |
'quopri', |
| 87 |
'uu', |
| 88 |
'html', |
| 89 |
'xml', |
| 90 |
'urllib', |
| 91 |
'http', |
| 92 |
'ftplib', |
| 93 |
'smtplib', |
| 94 |
'uuid', |
| 95 |
'xmlrpc.client', |
| 96 |
'ipaddress', |
| 97 |
'locale', |
| 98 |
'sys', |
| 99 |
] |
| 100 |
for module in stdlib: |
| 101 |
hiddenimports += collect_submodules(module, filter=lambda name: 'test' not in name) |
| 102 |
|
| 103 |
# Add Hidden Imports for Plugins |
| 104 |
hiddenimports += collect_submodules('twisted', filter=lambda name: 'test' not in name) |
| 105 |
datas += copy_metadata('twisted', recursive=True) |
| 106 |
|
| 107 |
# Copy UI/Plugin and translation files to where pyinstaller expects |
| 108 |
package_data = collect_data_files('deluge') |
| 109 |
datas += package_data |
| 110 |
# Workaround for Console UI files not being included in package data |
| 111 |
datas += [('../../deluge/ui/console', 'deluge/ui/console')] |
| 112 |
|
| 113 |
icon = [src for src, dest in package_data if src.endswith('deluge.ico')][0] |
| 114 |
|
| 115 |
# List of executables to produce |
| 116 |
executables = { |
| 117 |
'deluge-script.pyw': {'name': 'deluge', 'console': False, 'gtk': True}, |
| 118 |
'deluge-gtk-script.pyw': {'name': 'deluge-gtk', 'console': False, 'gtk': True}, |
| 119 |
'deluge-debug-script.py': {'name': 'deluge-debug', 'console': True, 'gtk': True}, |
| 120 |
'deluge-console-script.py': { |
| 121 |
'name': 'deluge-console', |
| 122 |
'console': True, |
| 123 |
'gtk': False, |
| 124 |
}, |
| 125 |
'deluged-script.pyw': {'name': 'deluged', 'console': False, 'gtk': False}, |
| 126 |
'deluged-debug-script.py': {'name': 'deluged-debug', 'console': True, 'gtk': False}, |
| 127 |
'deluge-web-debug-script.py': { |
| 128 |
'name': 'deluge-web-debug', |
| 129 |
'console': True, |
| 130 |
'gtk': False, |
| 131 |
}, |
| 132 |
'deluge-web-script.pyw': {'name': 'deluge-web', 'console': False, 'gtk': False}, |
| 133 |
} |
| 134 |
|
| 135 |
analysis = {} |
| 136 |
exe = {} |
| 137 |
coll = [] |
| 138 |
|
| 139 |
# Perform analysis |
| 140 |
for e, d in executables.items(): |
| 141 |
runtime_hooks = [] |
| 142 |
if d['gtk']: |
| 143 |
runtime_hooks += [os.path.join(SPECPATH, 'pyi_rth_gtk_csd.py')] |
| 144 |
|
| 145 |
analysis[e] = Analysis( |
| 146 |
[os.path.abspath(os.path.join(HOMEPATH, os.pardir, os.pardir, 'Scripts', e))], |
| 147 |
pathex=[], |
| 148 |
binaries=binaries, |
| 149 |
datas=datas, |
| 150 |
hiddenimports=hiddenimports, |
| 151 |
hookspath=[], |
| 152 |
hooksconfig={}, |
| 153 |
runtime_hooks=runtime_hooks, |
| 154 |
excludes=[], |
| 155 |
win_no_prefer_redirects=False, |
| 156 |
win_private_assemblies=False, |
| 157 |
cipher=None, |
| 158 |
noarchive=False, |
| 159 |
) |
| 160 |
|
| 161 |
# Executable |
| 162 |
for e, d in executables.items(): |
| 163 |
exe[e] = EXE( |
| 164 |
PYZ(analysis[e].pure, analysis[e].zipped_data, cipher=None), |
| 165 |
analysis[e].scripts, |
| 166 |
[], |
| 167 |
exclude_binaries=True, |
| 168 |
name=d['name'], |
| 169 |
debug=False, |
| 170 |
bootloader_ignore_signals=False, |
| 171 |
strip=False, |
| 172 |
upx=True, |
| 173 |
icon=icon, |
| 174 |
console=d['console'], |
| 175 |
disable_windowed_traceback=False, |
| 176 |
target_arch=None, |
| 177 |
codesign_identity=None, |
| 178 |
entitlements_file=None, |
| 179 |
) |
| 180 |
|
| 181 |
# Collect |
| 182 |
for e, d in executables.items(): |
| 183 |
coll += exe[e], analysis[e].binaries, analysis[e].zipfiles, analysis[e].datas |
| 184 |
|
| 185 |
COLLECT(*coll, strip=False, upx=True, upx_exclude=[], name='Deluge') |