forked from alierenaltindag/TinyTask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
249 lines (204 loc) · 7.7 KB
/
build.py
File metadata and controls
249 lines (204 loc) · 7.7 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env python3
import os
import sys
import shutil
import platform
import subprocess
from pathlib import Path
def get_platform():
if sys.platform.startswith('win'):
return 'windows'
elif sys.platform.startswith('linux'):
return 'linux'
else:
raise SystemError('Unsupported platform')
def clean_build_dirs():
"""Clean build and dist directories"""
dirs_to_clean = ['build', 'dist']
for dir_name in dirs_to_clean:
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
# Also clean spec files
for spec_file in Path('.').glob('*.spec'):
spec_file.unlink()
def build_portable():
"""Build portable version"""
platform_name = get_platform()
clean_build_dirs()
# Build command with all options
cmd = [
'pyinstaller',
'--clean',
'--onefile',
'--windowed',
'--name=TinyTask',
f'--icon=icon.svg',
'--noconfirm',
'--add-data=src/ui:ui',
'--add-data=src/utils:utils',
'--add-data=src/models:models',
'--paths=src',
'src/main.py'
]
# Run PyInstaller
subprocess.run(cmd, check=True)
# Rename the output file based on platform
source_file = 'dist/TinyTask'
if platform_name == 'windows':
source_file += '.exe'
target_file = 'TinyTask-portable-windows.exe'
else:
target_file = 'TinyTask-portable-linux'
# Remove target file if it exists
if os.path.exists(target_file):
if os.path.isdir(target_file):
shutil.rmtree(target_file)
else:
os.remove(target_file)
shutil.move(source_file, target_file)
print(f"Created portable executable: {target_file}")
# Make the Linux binary executable
if platform_name == 'linux':
os.chmod(target_file, 0o755)
# Clean up build directories
clean_build_dirs()
def create_windows_installer():
"""Create Windows installer using NSIS"""
# First build the portable executable
build_portable()
# Create NSIS script
nsis_script = '''
!include "MUI2.nsh"
!include "FileFunc.nsh"
Name "TinyTask"
OutFile "TinyTask-Setup.exe"
InstallDir "$PROGRAMFILES\\TinyTask"
RequestExecutionLevel admin
!define MUI_ABORTWARNING
!define MUI_ICON "icon.svg"
!define MUI_UNICON "icon.svg"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite on
File "TinyTask-portable-windows.exe"
Rename "$INSTDIR\\TinyTask-portable-windows.exe" "$INSTDIR\\TinyTask.exe"
CreateDirectory "$SMPROGRAMS\\TinyTask"
CreateShortCut "$SMPROGRAMS\\TinyTask\\TinyTask.lnk" "$INSTDIR\\TinyTask.exe"
CreateShortCut "$DESKTOP\\TinyTask.lnk" "$INSTDIR\\TinyTask.exe"
WriteUninstaller "$INSTDIR\\uninstall.exe"
; Write registry keys for uninstall
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask" "DisplayName" "TinyTask"
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask" "UninstallString" "$INSTDIR\\uninstall.exe"
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask" "DisplayIcon" "$INSTDIR\\TinyTask.exe"
WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask" "Publisher" "Ali Eren Altındağ"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask" "EstimatedSize" "$0"
SectionEnd
Section "Uninstall"
Delete "$INSTDIR\\TinyTask.exe"
Delete "$INSTDIR\\uninstall.exe"
Delete "$SMPROGRAMS\\TinyTask\\TinyTask.lnk"
Delete "$DESKTOP\\TinyTask.lnk"
RMDir "$SMPROGRAMS\\TinyTask"
RMDir "$INSTDIR"
DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\TinyTask"
SectionEnd
'''
with open('installer.nsi', 'w') as f:
f.write(nsis_script)
# Run NSIS compiler
subprocess.run(['makensis', 'installer.nsi'], check=True)
print("Created Windows installer: TinyTask-Setup.exe")
def create_linux_installer():
"""Create Linux .deb package"""
# First build the portable executable
build_portable()
# Setup .deb package structure
package_name = "tinytask"
version = "1.0.0"
arch = "amd64"
maintainer = "Ali Eren Altındağ <alierenaltindaag@gmail.com>"
# Create package directory structure
package_root = f"{package_name}_{version}_{arch}"
os.makedirs(f"{package_root}/DEBIAN", exist_ok=True)
os.makedirs(f"{package_root}/usr/local/bin", exist_ok=True)
os.makedirs(f"{package_root}/usr/share/applications", exist_ok=True)
os.makedirs(f"{package_root}/usr/share/icons/hicolor/scalable/apps", exist_ok=True)
# Create control file
control_content = f'''Package: {package_name}
Version: {version}
Architecture: {arch}
Maintainer: {maintainer}
Description: TinyTask - Macro Recorder
A lightweight macro recorder for mouse and keyboard actions.
Records and plays back mouse movements, clicks, and keyboard inputs.
Priority: optional
Section: utils
'''
with open(f"{package_root}/DEBIAN/control", 'w') as f:
f.write(control_content)
# Copy executable
shutil.copy2("TinyTask-portable-linux", f"{package_root}/usr/local/bin/tinytask")
os.chmod(f"{package_root}/usr/local/bin/tinytask", 0o755)
# Copy icon
shutil.copy2("icon.svg", f"{package_root}/usr/share/icons/hicolor/scalable/apps/tinytask.svg")
# Create .desktop file
desktop_content = '''[Desktop Entry]
Name=TinyTask
Comment=Record and play mouse and keyboard macros
Exec=/usr/local/bin/tinytask
Icon=tinytask
Terminal=false
Type=Application
Categories=Utility;
Keywords=macro;record;automation;
'''
with open(f"{package_root}/usr/share/applications/tinytask.desktop", 'w') as f:
f.write(desktop_content)
# Build .deb package
subprocess.run(['dpkg-deb', '--build', '--root-owner-group', package_root], check=True)
print(f"Created Linux installer: {package_root}.deb")
def build_installer():
"""Build installer version"""
platform_name = get_platform()
if platform_name == 'windows':
try:
create_windows_installer()
except subprocess.CalledProcessError:
print("Error: NSIS is required to create Windows installer.")
print("Please install NSIS (https://nsis.sourceforge.io/)")
sys.exit(1)
else:
try:
create_linux_installer()
except subprocess.CalledProcessError:
print("Error: dpkg-deb is required to create Linux installer.")
print("Please install dpkg-deb (sudo apt-get install dpkg)")
sys.exit(1)
def main():
if len(sys.argv) < 2:
print("Usage: python build.py [portable|installer|all]")
sys.exit(1)
build_type = sys.argv[1].lower()
if build_type == 'portable':
build_portable()
elif build_type == 'installer':
build_installer()
elif build_type == 'all':
build_portable()
build_installer()
else:
print("Invalid build type. Use: portable, installer, or all")
sys.exit(1)
if __name__ == '__main__':
main()