11# -*- mode: python -*-
22import sys
3+ import platform
34import os .path as os_path
5+ import shutil
46import simplejson as json
7+ import subprocess
58
69os_type = sys .platform
710block_cipher = None
@@ -11,9 +14,31 @@ def libModule(module, source, dest):
1114 m = __import__ (module )
1215 module_path = os_path .dirname (m .__file__ )
1316 del m
14- print ("libModule %s" % str (( os_path . join (module_path , source ), dest )) )
17+ print (f "libModule { ( os . path . join (module_path , source ), dest ) } " )
1518 return ( os_path .join (module_path , source ), dest )
1619
20+ def is_tool (prog ):
21+ for dir in os .environ ['PATH' ].split (os .pathsep ):
22+ if os .path .exists (os .path .join (dir , prog )):
23+ try :
24+ subprocess .call ([os .path .join (dir , prog )],
25+ stdout = subprocess .PIPE ,
26+ stderr = subprocess .STDOUT )
27+ except (OSError , e ):
28+ return False
29+ return True
30+ return False
31+
32+ # Set this to True if codesigning macOS bundles. Requires an Apple issued developer ID certificate.
33+ code_sign = False
34+ codesigner = 'fuzzbawls@pivx.org'
35+
36+ # detect CPU architecture
37+ cpu_arch = platform .processor ()
38+ if os_type == 'darwin' :
39+ if cpu_arch == 'arm' : cpu_arch = 'arm64'
40+ if cpu_arch == 'i386' : cpu_arch = 'x86_64'
41+
1742# look for version string
1843version_str = ''
1944with open (os_path .join (base_dir , 'src' , 'version.txt' )) as version_file :
@@ -88,14 +113,23 @@ exe = EXE(pyz,
88113 strip = False ,
89114 upx = False ,
90115 console = False ,
91- icon = os_path .join (base_dir , 'img' , 'spmt.%s' % ('icns' if os_type == 'darwin' else 'ico' )) )
116+ target_arch = f'{ cpu_arch } ' ,
117+ entitlements_file = 'contrib/macdeploy/entitlements.plist' ,
118+ codesign_identity = f'{ codesigner if code_sign == True else "" } ' ,
119+ icon = os_path .join (base_dir , 'img' , f'spmt.{ "icns" if os_type == "darwin" else "ico" } ' ))
92120
93121if os_type == 'darwin' :
94122 app = BUNDLE (exe ,
95123 name = 'pet4l.app' ,
96124 icon = os_path .join (base_dir , 'img' , 'spmt.icns' ),
97- bundle_identifier = None ,
98- info_plist = {'NSHighResolutionCapable' : 'True' })
125+ bundle_identifier = 'io.pivx.pet4l' ,
126+ info_plist = {
127+ 'NSHighResolutionCapable' : 'True' ,
128+ 'CFBundleVersion' : version_str ,
129+ 'CFBundleShortVersionString' : version_str ,
130+ 'NSPrincipalClass' : 'NSApplication' ,
131+ 'LSApplicationCategoryType' : 'public.app-category.finance'
132+ })
99133
100134
101135# Prepare bundles
@@ -104,37 +138,66 @@ app_path = os_path.join(dist_path, 'app')
104138os .chdir (dist_path )
105139
106140if os_type == 'win32' :
107- os .chdir (base_dir )
108- # Rename dist Dir
109- dist_path_win = os_path .join (base_dir , 'PET4L-v' + version_str + '-Win64' )
110- os .rename (dist_path , dist_path_win )
111- # Create NSIS compressed installer
112- print ('Creating Windows installer (requires NSIS)' )
113- os .system ('\" c:\\ program files (x86)\\ NSIS\\ makensis.exe\" %s' % os .path .join (base_dir , 'setup.nsi' ))
141+ os .chdir (base_dir )
142+ # Rename dist Dir
143+ dist_path_win = os_path .join (base_dir , f'PET4L-v{ version_str } -Win64' )
144+ if os_path .exists (dist_path_win ):
145+ shutil .rmtree (dist_path_win )
146+ os .rename (dist_path , dist_path_win )
147+ # Check for NSIS
148+ prog_path = os .environ ["ProgramFiles(x86)" ]
149+ nsis_bin = os_path .join (prog_path , "NSIS" , "makensis.exe" )
150+ if os_path .exists (nsis_bin ):
151+ # Create NSIS compressed installer
152+ print ('Creating Windows installer' )
153+ os .system (f'"{ nsis_bin } " { os_path .join (base_dir , "setup.nsi" )} ' )
154+ else :
155+ print ('NSIS not found, cannot build windows installer.' )
114156
115157if os_type == 'linux' :
116- os .chdir (base_dir )
117- # Rename dist Dir
118- dist_path_linux = os_path .join (base_dir , 'PET4L-v' + version_str + '-gnu_linux' )
119- os .rename (dist_path , dist_path_linux )
120- # Compress dist Dir
121- print ('Compressing Linux App Folder' )
122- os .system ('tar -zcvf %s -C %s %s' % ('PET4L-v' + version_str + '-x86_64-gnu_linux.tar.gz' ,
123- base_dir , 'PET4L-v' + version_str + '-gnu_linux' ))
158+ os .chdir (base_dir )
159+ # Rename dist Dir
160+ dist_path_linux = os_path .join (base_dir , f'PET4L-v{ version_str } -{ cpu_arch } -gnu_linux' )
161+ if os_path .exists (dist_path_linux ):
162+ shutil .rmtree (dist_path_linux )
163+ os .rename (dist_path , dist_path_linux )
164+ # Compress dist Dir
165+ print ('Compressing Linux App Folder' )
166+ os .system (f'tar -zcvf PET4L-v{ version_str } -{ cpu_arch } -gnu_linux.tar.gz -C { base_dir } PET4L-v{ version_str } -{ cpu_arch } -gnu_linux' )
124167
125168if os_type == 'darwin' :
126169 os .chdir (base_dir )
127170 # Rename dist Dir
128- dist_path_mac = os_path .join (base_dir , 'PET4L-v' + version_str + '-MacOSX' )
171+ dist_path_mac = os_path .join (base_dir , f'PET4L-v{ version_str } -{ cpu_arch } -MacOS' )
172+ if os_path .exists (dist_path_mac ):
173+ shutil .rmtree (dist_path_mac )
129174 os .rename (dist_path , dist_path_mac )
130175 # Remove 'app' folder
131- print ("Removin 'app' folder" )
176+ print ("Removing 'app' folder" )
132177 os .chdir (dist_path_mac )
133178 os .system ('rm -rf app' )
134179 os .chdir (base_dir )
135180 # Compress dist Dir
136181 print ('Compressing Mac App Folder' )
137- os .system ('tar -zcvf %s -C %s %s' % ('PET4L-v' + version_str + '-MacOSX.tar.gz' ,
138- base_dir , 'PET4L-v' + version_str + '-MacOSX' ))
139-
140-
182+ os .system (f'tar -zcvf PET4L-v{ version_str } -{ cpu_arch } -MacOS.tar.gz -C { base_dir } PET4L-v{ version_str } -{ cpu_arch } -MacOS' )
183+
184+ # dmg image creation uses the node.js appdmg package
185+ if is_tool ("appdmg" ):
186+ # Prepare dmg
187+ print ("Preparing distribution dmg installer" )
188+ os .chdir (dist_path_mac )
189+ with open (os_path .join (base_dir , 'contrib/macdeploy' , 'appdmg.json.in' )) as conf :
190+ confdata = conf .read ()
191+ confdata = confdata .replace ('%version%' , version_str )
192+ confdata = confdata .replace ('%signer%' , f'{ codesigner if code_sign == True else "" } ' )
193+ with open ('appdmg.json' , 'w' ) as newconf :
194+ newconf .write (confdata )
195+
196+ os .system (f'sed \" s/PACKAGE_NAME/PET4L { version_str } /\" < \" ../contrib/macdeploy/background.svg\" | rsvg-convert -f png -d 72 -p 72 | convert - background.tiff@2x.png' )
197+ os .system ('convert background.tiff@2x.png -resize 500x320 background.tiff.png' )
198+ os .system ('tiffutil -cathidpicheck background.tiff.png background.tiff@2x.png -out background.tiff' )
199+ os .remove ('background.tiff.png' )
200+ os .system (f'appdmg appdmg.json ../PET4L-v{ version_str } -{ cpu_arch } -MacOS.dmg' )
201+ os .remove ('background.tiff@2x.png' )
202+ else :
203+ print ("appdmg not found, skipping DMG creation" )
0 commit comments