From 8c25375e04ba0e128bf75bc8d145c14ff0976837 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 1 Dec 2012 13:41:58 +0100 Subject: [PATCH 1/2] Fix issue when mounted dmg is still in use by OSX Finder. --- osx/macosx-builder.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/osx/macosx-builder.py b/osx/macosx-builder.py index 54ac745..b9652f5 100644 --- a/osx/macosx-builder.py +++ b/osx/macosx-builder.py @@ -113,6 +113,8 @@ build process you can specify different make targets import os import plistlib +import signal +import subprocess import sys from shutil import copy, rmtree from subprocess import Popen, PIPE @@ -591,10 +593,22 @@ class MacosxBuilder(object): u'Could not copy the background image, dmg creation failed.' ) + print 10 * 'A' self.adjust_dmg_view(os.path.basename(dmg_volume_path)) - # Unmount dmg file. + + ## Unmount dmg file. self._print('... unmounting the dmg.') + # Sometimes it could happen that OSX Finder is blocking umount. + # We need to find this process and kill it. + try: + output = subprocess.check_output(['fuser', dmg_volume_path]) + blocking_proc_pid = int(output.strip().split()[0]) + if blocking_proc_pid: + os.kill(int(blocking_proc_pid), signal.SIGKILL) + except: + self._print('... failed to kill process using %s' % dmg_volume_path) + # Unmount dmg file. self._run_command([self.hdiutil, 'detach', dmg_volume_path], 'Could not unmount the dmg file, dmg creation failed.' ) @@ -639,11 +653,9 @@ class MacosxBuilder(object): f.close() result = p.returncode if (result != 0): - self._print('Adjusting dmg view failed.') - sys.exit(1) + self._print('Adjusting dmg view failed (non-zero exit code).') except (IOError, OSError): self._print('Adjusting dmg view failed.') - sys.exit(1) def main(self): """ From 74f18abbe6543fba4d22d4e18ab0218ffd90e792 Mon Sep 17 00:00:00 2001 From: Martin Zibricky Date: Sat, 1 Dec 2012 14:23:08 +0100 Subject: [PATCH 2/2] Fix issue with missing link to /Applications dir in dmg and applescript cleanup. --- osx/applescript-adjust-dmg-view.master | 17 ++++------------- osx/macosx-builder.py | 15 +++++++++------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/osx/applescript-adjust-dmg-view.master b/osx/applescript-adjust-dmg-view.master index abd8b7e..4b0ae12 100755 --- a/osx/applescript-adjust-dmg-view.master +++ b/osx/applescript-adjust-dmg-view.master @@ -13,22 +13,13 @@ on run set arrangement of theViewOptions to not arranged set icon size of theViewOptions to 128 set background picture of theViewOptions to file ".background:installer-background.png" - if not exists file "Applications" then - make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"} - end if - delay 1 set position of item "%s" of container window to {160, 200} - set position of item ".Trashes" of container window to {100, 500} - set position of item ".background" of container window to {200, 500} - set position of item ".DS_Store" of container window to {400, 500} set position of item "Applications" of container window to {550, 200} - if exists file ".VolumeIcon.icns" then - set position of item ".VolumeIcon.icns" of container window to {500, 500} - end if + set position of item ".background" of container window to {100, 500} + set position of item ".DS_Store" of container window to {200, 500} set position of item ".fseventsd" of container window to {300, 500} - if exists POSIX file ".SymAVx86QSFile" then - set position of item ".SymAVx86QSFile" of container window to {600, 500} - end if + set position of item ".Trashes" of container window to {400, 500} + set position of item ".VolumeIcon.icns" of container window to {500, 500} open close update without registering applications diff --git a/osx/macosx-builder.py b/osx/macosx-builder.py index b9652f5..ef25dd8 100644 --- a/osx/macosx-builder.py +++ b/osx/macosx-builder.py @@ -581,6 +581,10 @@ class MacosxBuilder(object): self._run_command(['SetFile', '-a', 'C', dmg_volume_path], 'Could not set dmg icon attributes.') + # Create symlink in dmg pointing to the /Applications directory on OS X. + self._print('... Creating symlink to /Applications.') + os.symlink('/Applications', os.path.join(dmg_volume_path, 'Applications')) + # Set dmg background. Requires running Mac OS X gui. # TODO: better formatting and code refactoring if not self.args.devel: @@ -593,20 +597,19 @@ class MacosxBuilder(object): u'Could not copy the background image, dmg creation failed.' ) - print 10 * 'A' self.adjust_dmg_view(os.path.basename(dmg_volume_path)) - ## Unmount dmg file. self._print('... unmounting the dmg.') # Sometimes it could happen that OSX Finder is blocking umount. # We need to find this process and kill it. try: - output = subprocess.check_output(['fuser', dmg_volume_path]) - blocking_proc_pid = int(output.strip().split()[0]) - if blocking_proc_pid: + output = subprocess.check_output(['fuser', dmg_volume_path]).strip() + if output: + blocking_proc_pid = int(output.split()[0]) os.kill(int(blocking_proc_pid), signal.SIGKILL) - except: + except Exception as e: + print str(e) self._print('... failed to kill process using %s' % dmg_volume_path) # Unmount dmg file. self._run_command([self.hdiutil, 'detach', dmg_volume_path],