-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dmg.py
executable file
·113 lines (90 loc) · 3.81 KB
/
build_dmg.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
#!/usr/bin/env python3
import os
import sys
import subprocess
import shutil
import tempfile
from pathlib import Path
def install_from_dmg(dmg_path):
print("\nInstalling to Applications...")
try:
# Mount the DMG
mount_process = subprocess.run(["hdiutil", "attach", str(dmg_path)],
capture_output=True, text=True)
# Find the mount point
mount_point = None
for line in mount_process.stdout.split('\n'):
if '/Volumes/' in line:
mount_point = line.split('\t')[-1].strip()
break
if not mount_point:
print("Error: Could not find mount point")
return False
# Find the .app in the mounted DMG
app_name = "CDDA Launcher.app"
source_app = Path(mount_point) / app_name
target_app = Path("/Applications") / app_name
# Remove existing installation if present
if target_app.exists():
print("Removing previous installation...")
shutil.rmtree(target_app)
# Copy the app to Applications
print("Copying to Applications...")
shutil.copytree(source_app, target_app, symlinks=True)
# Unmount the DMG
subprocess.run(["hdiutil", "detach", mount_point], check=True)
print("Installation complete!")
return True
except Exception as e:
print(f"Error during installation: {str(e)}")
return False
def create_dmg():
# Get the directory containing this script
script_dir = Path(__file__).parent.absolute()
# Create a temporary directory for DMG creation
with tempfile.TemporaryDirectory() as temp_dir:
print("Creating clean app bundle...")
# First build the app, skipping installation
subprocess.run([sys.executable, "build_app.py", "--skip-install"], check=True)
# Find the app in the current directory
app_name = "CDDA Launcher.app"
source_app = script_dir / app_name
temp_app = Path(temp_dir) / app_name
if not source_app.exists():
print(f"Error: Could not find {app_name} in the current directory")
print(f"Looking in: {source_app}")
print("Current directory contents:")
for item in script_dir.iterdir():
print(f" {item.name}")
return
# Copy the fresh app to temp directory
shutil.copytree(source_app, temp_app)
print("Creating DMG...")
# Create DMG name with version
dmg_name = "CDDA_Launcher_1.0.0.dmg" # You can update version as needed
dmg_path = script_dir / dmg_name
# Remove existing DMG if it exists
if dmg_path.exists():
dmg_path.unlink()
# Calculate required size (app size + 10MB buffer)
app_size = sum(f.stat().st_size for f in temp_app.rglob('*') if f.is_file())
dmg_size = str(int((app_size + 10*1024*1024) / 1024 / 1024))+"m"
# Create DMG directly (without temporary DMG)
subprocess.run([
"hdiutil", "create",
"-size", dmg_size,
"-srcfolder", str(temp_dir),
"-volname", "CDDA Launcher",
"-fs", "HFS+",
"-format", "UDZO",
"-imagekey", "zlib-level=9",
str(dmg_path)
], check=True)
print(f"DMG created successfully at: {dmg_path}")
print("\nThis DMG is clean and ready for distribution!")
# Ask about installation
response = input("\nWould you like to install the app to Applications? (y/n): ")
if response.lower() == 'y':
install_from_dmg(dmg_path)
if __name__ == "__main__":
create_dmg()