Created
January 12, 2016 11:03
Script for packaging a pkg into a dmg.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Created on 2016-01-12 11:38 | |
Short script for packaging a pkg into a dmg. | |
@author benediceb | |
""" | |
import sys | |
import os | |
import os.path as op | |
from subprocess import check_output | |
_HDIUTIL = '/usr/bin/hdiutil' | |
_CP = '/bin/cp' | |
if __name__ == '__main__': | |
pkg = sys.argv[1] | |
basename = op.splitext(pkg)[0] | |
dmg = ''.join((basename, '.dmg')) | |
sparseimage = ''.join((dmg, '.sparseimage')) | |
mounted = op.join('/Volumes', basename) | |
command = [_HDIUTIL, 'create', '-size', '100M', '-type', 'SPARSE', '-volname', basename, | |
'-fs', 'HFS+', sparseimage] | |
print ' '.join(command) | |
check_output(command) | |
command = [_HDIUTIL, 'attach', sparseimage] | |
print ' '.join(command) | |
check_output(command) | |
command = [_CP, '-Rv', pkg, mounted] | |
print ' '.join(command) | |
check_output(command) | |
command = [_HDIUTIL, 'detach', mounted] | |
print ' '.join(command) | |
check_output(command) | |
command = [_HDIUTIL, 'convert', sparseimage, '-format', 'UDZO', '-o', dmg, | |
'-ov', '-imagekey', 'zlib-level=9'] | |
print ' '.join(command) | |
check_output(command) | |
os.remove(sparseimage) | |
print 'Output is in\n %s' % dmg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment