Refactoring: Simplify code adjusting dmg view in osx build.

This commit is contained in:
Martin Zibricky 2012-06-25 01:09:46 +02:00
parent 57441ec741
commit d5e908f6ee
2 changed files with 22 additions and 63 deletions

View File

@ -1,34 +1,6 @@
on saveImageWithItselfAsIcon(icon_image_file)
-- save icon_image_file with itself as icon
set icon_image_file_string to icon_image_file as string
tell application "Image Events"
launch
set icon_image to open file icon_image_file_string
save icon_image with icon
close icon_image
end tell
end saveImageWithItselfAsIcon
on CopyOrPaste(i, cv)
tell application "Finder"
activate
set infoWindow to open information window of i
set infoWindowName to name of infoWindow
end tell
tell application "System Events" to tell process "Finder" to tell window infoWindowName
keystroke tab -- select icon button
keystroke (cv & "w") using command down (* (copy or paste) + close window *)
end tell -- window 1 then process Finder then System Events
end CopyOrPaste
on run
set icon_image_file to POSIX file "%s" as alias
set dmg_file to POSIX file "/Volumes/%s" as alias
my saveImageWithItselfAsIcon(icon_image_file)
-- wait for virus scanner
delay 2
-- my copyIconOfTo(icon_image_file, dmg_file)
tell application "Finder"
tell disk "%s"

View File

@ -555,24 +555,6 @@ class MacosxBuilder(object):
u'Could not copy app bundle, dmg creation failed.'
)
# Set dmg background. Requires running Mac OS X gui.
# TODO: better formatting and code refactoring
if not self.args.devel:
self._print('... Setting the background image.')
os.mkdir(os.path.join(dmg_volume_path, '.background'))
self._run_command(['cp', self.dmg_background_img,
os.path.join(dmg_volume_path,
'.background/installer-background.png')],
u'Could not copy the background image, dmg creation failed.'
)
self.adjust_package_view({'openlp_dmg_icon_file':
self.dmg_background_img,'openlp_appname': 'OpenLP' },
os.path.join(self.script_path,
'applescript-adjustview-10-6.master'))
# Set icon for dmg file.
# http://endrift.com/blog/2010/06/14/dmg-files-volume-icons-cli/
self._print('... Setting the dmg icon.')
@ -587,6 +569,20 @@ class MacosxBuilder(object):
self._run_command(['SetFile', '-a', 'C', dmg_volume_path],
'Could not set dmg icon attributes.')
# Set dmg background. Requires running Mac OS X gui.
# TODO: better formatting and code refactoring
if not self.args.devel:
self._print('... Setting the background image.')
os.mkdir(os.path.join(dmg_volume_path, '.background'))
self._run_command(['cp', self.dmg_background_img,
os.path.join(dmg_volume_path,
'.background/installer-background.png')],
u'Could not copy the background image, dmg creation failed.'
)
self.adjust_dmg_view(os.path.basename(dmg_volume_path))
# Unmount dmg file.
self._print('... unmounting the dmg.')
self._run_command([self.hdiutil, 'detach', dmg_volume_path],
@ -623,29 +619,20 @@ class MacosxBuilder(object):
self.dmg_file = compressed_dmg
def adjust_package_view(self, settings, adjustview_scriptname):
#logging.info('[%s] making adjustments to the view...', script_name)
def adjust_dmg_view(self, dmg_volume_name):
try:
f = open(adjustview_scriptname)
# TODO: Use only one applescript file. Remove one for osx 10.5.
f = open(os.path.join(self.script_path,
'applescript-adjustview-10-6.master'))
p = Popen(["osascript"], stdin=PIPE)
p.communicate(f.read() % (
settings['openlp_dmg_icon_file'],
settings['openlp_appname'],
settings['openlp_appname'],
settings['openlp_appname']))
p.communicate(f.read() % (dmg_volume_name, 'OpenLP'))
f.close()
result = p.returncode
if (result != 0):
#logging.error('[%s] could not adjust the view, dmg creation \
# failed!', script_name)
self._print('Adjusting dmg view failed.')
sys.exit(1)
except IOError, e:
#logging.error('[%s] could not adjust the view (%s), dmg creation \
# failed!', script_name, e)
sys.exit(1)
except OSError, e:
#logging.error('[%s] could not adjust the view (%s), dmg creation \
# failed!', script_name, e)
except (IOError, OSError):
self._print('Adjusting dmg view failed.')
sys.exit(1)
def main(self):