def buildDMG(self):
# remove DMG if it already exists
if os.path.exists(self.dmgName):
os.unlink(self.dmgName)
tmpDir = os.path.join(self.buildDir, 'tmp')
if os.path.exists(tmpDir):
dir_util.remove_tree(tmpDir, verbose=1)
self.mkpath(tmpDir)
# move the app bundle into a separate folder since hdutil copies in the dmg
# the content of the folder specified in the -srcfolder folder parameter, and if we
# specify as input the app bundle itself, its content will be copied and not the bundle
if os.spawnvp(os.P_WAIT, 'cp', ['cp', '-R', self.bundleDir, tmpDir]):
raise OSError('could not move app bundle in staging directory')
createargs = [
'hdiutil', 'create', '-fs', 'HFSX', '-format', 'UDZO',
self.dmgName, '-imagekey', 'zlib-level=9', '-srcfolder',
tmpDir, '-volname', self.volume_label
]
if self.applications_shortcut:
scriptargs = [
'osascript', '-e', 'tell application "Finder" to make alias \
file to POSIX file "/Applications" at POSIX file "%s"' %
os.path.realpath(self.buildDir)
]
if os.spawnvp(os.P_WAIT, 'osascript', scriptargs) != 0:
raise OSError('creation of Applications shortcut failed')
createargs.append('-srcfolder')
createargs.append(self.buildDir + '/Applications')
# create the dmg
if os.spawnvp(os.P_WAIT, 'hdiutil', createargs) != 0:
raise OSError('creation of the dmg failed')
# remove the temporary folder
dir_util.remove_tree(tmpDir, verbose=1)
评论列表
文章目录