-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_sql_backup.spec
More file actions
157 lines (137 loc) · 4.44 KB
/
Copy pathpython_sql_backup.spec
File metadata and controls
157 lines (137 loc) · 4.44 KB
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
"""
PyInstaller spec file for python_sql_backup.
This enhanced spec file supports cross-platform building for Windows, macOS, and Linux
with various CPU architectures.
"""
import os
import sys
import platform
import subprocess
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
# Determine the current platform
current_platform = platform.system().lower()
if current_platform == 'darwin':
current_platform = 'macos'
elif current_platform == 'windows':
current_platform = 'windows'
else:
current_platform = 'linux'
# Block cipher for encryption (None = no encryption)
block_cipher = None
# Define additional binary dependencies based on platform
binaries = []
# Add Python shared library for Linux
if current_platform == 'linux':
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
# Try to find Python library using ldconfig
try:
ldconfig_output = subprocess.check_output(['ldconfig', '-p']).decode()
for line in ldconfig_output.splitlines():
if f'libpython{python_version}.so' in line:
lib_path = line.split('=>')[-1].strip()
if os.path.exists(lib_path):
binaries.append((lib_path, '.'))
break
except:
pass
# If ldconfig didn't work, try common locations
if not binaries:
lib_paths = [
f"/usr/lib/libpython{python_version}.so",
f"/usr/lib/aarch64-linux-gnu/libpython{python_version}.so",
f"/usr/lib/python{python_version}/config-{python_version}-aarch64-linux-gnu/libpython{python_version}.so",
f"/usr/lib/x86_64-linux-gnu/libpython{python_version}.so",
f"/usr/local/lib/libpython{python_version}.so",
os.path.join(sys.prefix, 'lib', f'libpython{python_version}.so'),
]
# Add current Python's lib directory
python_lib_dir = os.path.dirname(os.path.realpath(sys.executable))
lib_paths.append(os.path.join(python_lib_dir, '..', 'lib', f'libpython{python_version}.so'))
for lib_path in lib_paths:
if os.path.exists(lib_path):
binaries.append((lib_path, '.'))
break
# Define data files to include
data_files = [
('config.ini.example', 'config.ini.example'),
('README.md', 'README.md'),
]
# Add icons if they exist
icon_paths = {
'windows': os.path.join('resources', 'icon.ico'),
'macos': os.path.join('resources', 'icon.icns'),
}
for platform_name, icon_path in icon_paths.items():
if os.path.exists(icon_path):
data_files.append((icon_path, icon_path))
# Hidden imports to ensure all necessary modules are included
hidden_imports = [
'mysql.connector',
'configparser',
'click',
'tabulate',
'colorama',
'tqdm',
'typing',
'pathlib',
]
# Add all submodules from our package
hidden_imports.extend(collect_submodules('python_sql_backup'))
# Create the Analysis object
a = Analysis(
['python_sql_backup/__main__.py'],
pathex=[os.path.abspath(os.getcwd())],
binaries=binaries,
datas=data_files,
hiddenimports=hidden_imports,
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
# Create the PYZ archive
pyz = PYZ(
a.pure,
a.zipped_data,
cipher=block_cipher
)
# Platform-specific options for the executable
exe_args = {
'name': 'python-sql-backup',
'debug': False,
'bootloader_ignore_signals': False,
'strip': False,
'upx': True,
'console': True,
}
# Add platform-specific icon if available
if current_platform == 'windows' and os.path.exists(icon_paths['windows']):
exe_args['icon'] = icon_paths['windows']
elif current_platform == 'macos' and os.path.exists(icon_paths['macos']):
exe_args['icon'] = icon_paths['macos']
# Create mode-specific targets based on the build mode
# Onefile mode: Single executable file
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
**exe_args,
)
# For macOS, create a .app bundle
if current_platform == 'macos':
app = BUNDLE(
exe,
name='python-sql-backup.app',
icon=icon_paths['macos'] if os.path.exists(icon_paths['macos']) else None,
bundle_identifier='com.mysql.backup',
info_plist={
'CFBundleShortVersionString': '1.0.0',
'NSHighResolutionCapable': 'True',
},
)