2018-01-09 13:13:10 +01:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
#=============================================================================================
|
|
|
|
|
# File: "macbuild/makeDMG4mac.py"
|
|
|
|
|
#
|
|
|
|
|
# Python script for making a DMG file of KLayout (http://www.klayout.de/index.php) bundles.
|
|
|
|
|
#
|
2018-01-14 09:17:53 +01:00
|
|
|
# This is a derivative work of Ref. 2) below. Refer to "macbuild/LICENSE" file.
|
2018-01-09 13:13:10 +01:00
|
|
|
# Ref.
|
|
|
|
|
# 1) https://el-tramo.be/guides/fancy-dmg/
|
2018-01-14 09:17:53 +01:00
|
|
|
# 2) https://github.com/andreyvit/create-dmg.git
|
2018-01-09 13:13:10 +01:00
|
|
|
#=============================================================================================
|
|
|
|
|
from __future__ import print_function # to use print() of Python 3 in Python >= 2.7
|
2018-01-15 06:55:24 +01:00
|
|
|
from time import sleep
|
2018-01-09 13:13:10 +01:00
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import glob
|
|
|
|
|
import platform
|
|
|
|
|
import optparse
|
|
|
|
|
import subprocess
|
2018-01-14 09:17:53 +01:00
|
|
|
import hashlib
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
## To import global dictionaries of different modules and utility functions
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
mydir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
sys.path.append( mydir + "/macbuild" )
|
|
|
|
|
from build4mac_util import *
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
## To set global variables including present directory and platform info.
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
def SetGlobals():
|
|
|
|
|
global ProjectDir # project directory where "build.sh" exists
|
|
|
|
|
global Usage # string on usage
|
2018-01-13 09:18:14 +01:00
|
|
|
global GenOSName # generic OS name
|
2018-01-09 13:13:10 +01:00
|
|
|
global Platform # platform
|
|
|
|
|
global PkgDir # the package directory where "klayout.app" and "klayout.scripts" exist
|
|
|
|
|
global OpClean # 'clean' operation
|
|
|
|
|
global OpMake # 'make' operation
|
|
|
|
|
global DMGSerialNum # the DMG serial number
|
2018-01-15 07:12:06 +01:00
|
|
|
global QtIdentification # Qt identification
|
2018-01-09 13:13:10 +01:00
|
|
|
global Version # KLayout's version
|
2018-01-16 06:08:25 +01:00
|
|
|
global OccupiedDS # approx. occupied disc space
|
2018-01-15 06:55:24 +01:00
|
|
|
global BackgroundPNG # the background PNG image file
|
|
|
|
|
global VolumeIcons # the volume icon file
|
2018-01-14 09:17:53 +01:00
|
|
|
global AppleScriptDMG # the AppleScript for KLayout DMG
|
2018-01-16 06:08:25 +01:00
|
|
|
global WorkDMG # work DMG file created under ProjectDir/
|
2018-01-14 03:12:45 +01:00
|
|
|
global VolumeDMG # the volume name of DMG
|
2018-01-16 06:08:25 +01:00
|
|
|
global TargetDMG # the name of target DMG file
|
2018-01-11 13:46:56 +01:00
|
|
|
global RootApplications # reserved directory name for applications
|
2018-01-09 13:13:10 +01:00
|
|
|
# auxiliary variables on platform
|
|
|
|
|
global System # 6-tuple from platform.uname()
|
|
|
|
|
global Node # - do -
|
|
|
|
|
global Release # - do -
|
|
|
|
|
global Version # - do -
|
|
|
|
|
global Machine # - do -
|
|
|
|
|
global Processor # - do -
|
|
|
|
|
global Bit # machine bit-size
|
|
|
|
|
|
|
|
|
|
Usage = "\n"
|
|
|
|
|
Usage += "--------------------------------------------------------------------------------------------------------\n"
|
|
|
|
|
Usage += "<< Usage of 'makeDMG4mac.py' >>\n"
|
|
|
|
|
Usage += " for making a DMG file of KLayout 0.25 or later on different Apple Mac OSX platforms.\n"
|
|
|
|
|
Usage += "\n"
|
|
|
|
|
Usage += "$ [python] ./makeDMG4mac.py \n"
|
|
|
|
|
Usage += " option & argument : descriptions | default value\n"
|
|
|
|
|
Usage += " ----------------------------------------------------------------------------------+---------------\n"
|
|
|
|
|
Usage += " <-p|--pkg <dir>> : package directory created by `build4mac.py` with [-y|-Y] | `` \n"
|
|
|
|
|
Usage += " : like 'qt5.pkg.macos-HighSierra-release' | \n"
|
|
|
|
|
Usage += " <-c|--clean> : clean the work directory | disabled \n"
|
2018-01-15 06:55:24 +01:00
|
|
|
Usage += " <-m|--make> : make a compressed DMG file | disabled \n"
|
2018-01-09 13:13:10 +01:00
|
|
|
Usage += " : <-c|--clean> and <-m|--make> are mutually exclusive | \n"
|
2018-03-19 02:06:38 +01:00
|
|
|
Usage += " [-q|--qt <ID>] : ID name of deployed Qt | Qt510Xmp \n"
|
2018-01-09 13:13:10 +01:00
|
|
|
Usage += " [-s|--serial <num>] : DMG serial number | 1 \n"
|
|
|
|
|
Usage += " [-?|--?] : print this usage and exit | disabled \n"
|
|
|
|
|
Usage += "--------------------------------------------------------------------------------------------------------\n"
|
|
|
|
|
|
|
|
|
|
ProjectDir = os.getcwd()
|
|
|
|
|
(System, Node, Release, Version, Machine, Processor) = platform.uname()
|
|
|
|
|
|
|
|
|
|
if not System == "Darwin":
|
|
|
|
|
print("")
|
|
|
|
|
print( "!!! Sorry. Your system <%s> looks like non-Mac" % System, file=sys.stderr )
|
|
|
|
|
print(Usage)
|
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
release = int( Release.split(".")[0] ) # take the first of ['14', '5', '0']
|
|
|
|
|
if release == 14:
|
2018-01-13 09:18:14 +01:00
|
|
|
GenOSName = "MacOSX"
|
|
|
|
|
Platform = "Yosemite"
|
2018-01-09 13:13:10 +01:00
|
|
|
elif release == 15:
|
2018-01-13 09:18:14 +01:00
|
|
|
GenOSName = "MacOSX"
|
|
|
|
|
Platform = "ElCapitan"
|
2018-01-09 13:13:10 +01:00
|
|
|
elif release == 16:
|
2018-01-13 09:18:14 +01:00
|
|
|
GenOSName = "macOS"
|
|
|
|
|
Platform = "Sierra"
|
2018-01-09 13:13:10 +01:00
|
|
|
elif release == 17:
|
2018-01-13 09:18:14 +01:00
|
|
|
GenOSName = "macOS"
|
|
|
|
|
Platform = "HighSierra"
|
2018-01-09 13:13:10 +01:00
|
|
|
else:
|
|
|
|
|
Platform = ""
|
|
|
|
|
print("")
|
|
|
|
|
print( "!!! Sorry. Unsupported major OS release <%d>" % release, file=sys.stderr )
|
|
|
|
|
print(Usage)
|
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
if not Machine == "x86_64":
|
|
|
|
|
print("")
|
|
|
|
|
print( "!!! Sorry. Only x86_64 architecture machine is supported but found <%s>" % Machine, file=sys.stderr )
|
|
|
|
|
print(Usage)
|
|
|
|
|
quit()
|
|
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
PkgDir = ""
|
|
|
|
|
OpClean = False
|
|
|
|
|
OpMake = False
|
|
|
|
|
DMGSerialNum = 1
|
2018-03-19 02:06:38 +01:00
|
|
|
QtIdentification = "Qt510Xmp"
|
2018-01-14 09:17:53 +01:00
|
|
|
Version = GetKLayoutVersionFrom( "./version.sh" )
|
2018-01-13 09:18:14 +01:00
|
|
|
OccupiedDS = -1
|
2018-01-15 06:55:24 +01:00
|
|
|
BackgroundPNG = "KLayoutDMG-Back.png"
|
|
|
|
|
VolumeIcons = "KLayoutHDD.icns"
|
2018-01-14 09:17:53 +01:00
|
|
|
AppleScriptDMG = "macbuild/Resources/KLayoutDMG.applescript"
|
|
|
|
|
WorkDMG = "work-KLayout.dmg"
|
|
|
|
|
VolumeDMG = "KLayout"
|
|
|
|
|
TargetDMG = ""
|
2018-01-16 06:08:25 +01:00
|
|
|
RootApplications = "/Applications"
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
## To check the contents of the package directory
|
|
|
|
|
#
|
2018-01-14 09:17:53 +01:00
|
|
|
# @return on success, positive integer in [MB] that tells approx. occupied disc space;
|
2018-01-13 09:18:14 +01:00
|
|
|
# on failure, -1
|
2018-01-09 13:13:10 +01:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
def CheckPkgDirectory():
|
|
|
|
|
|
|
|
|
|
if PkgDir == "":
|
|
|
|
|
print( "! Package directory is not specified", file=sys.stderr )
|
|
|
|
|
print(Usage)
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
if not os.path.isdir(PkgDir):
|
|
|
|
|
print( "! Specified package directory <%s> does not exist" % PkgDir, file=sys.stderr )
|
|
|
|
|
print( "" )
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
os.chdir(PkgDir)
|
2018-01-14 09:17:53 +01:00
|
|
|
items = glob.glob( "*" ) # must be ['klayout.app', 'klayout.scripts']
|
|
|
|
|
if not len(items) == 2:
|
|
|
|
|
print( "! The package directory <%s> must have just <2> directories ['klayout.app', 'klayout.scripts']" % PkgDir, file=sys.stderr )
|
|
|
|
|
print( "" )
|
|
|
|
|
os.chdir(ProjectDir)
|
|
|
|
|
return -1
|
|
|
|
|
|
2018-01-09 13:13:10 +01:00
|
|
|
if not os.path.isdir( "klayout.app" ):
|
|
|
|
|
print( "! The package directory <%s> does not hold <klayout.app> bundle" % PkgDir, file=sys.stderr )
|
|
|
|
|
print( "" )
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
if not os.path.isdir( "klayout.scripts" ):
|
|
|
|
|
print( "! The package directory <%s> does not hold <klayout.scripts> subdirectory" % PkgDir, file=sys.stderr )
|
|
|
|
|
print( "" )
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
os.chdir( "klayout.scripts" )
|
|
|
|
|
if not os.path.isdir( "KLayoutEditor.app" ):
|
2018-01-15 06:55:24 +01:00
|
|
|
print( "! The package directory <%s> does not hold <KLayoutEditor.app> bundle under 'klayout.scripts/'" % PkgDir, file=sys.stderr )
|
2018-01-09 13:13:10 +01:00
|
|
|
print( "" )
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
if not os.path.isdir( "KLayoutViewer.app" ):
|
2018-01-15 06:55:24 +01:00
|
|
|
print( "! The package directory <%s> does not hold <KLayoutViewer.app> bundle under 'klayout.scripts/'" % PkgDir, file=sys.stderr )
|
2018-01-09 13:13:10 +01:00
|
|
|
print( "" )
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-13 09:18:14 +01:00
|
|
|
return -1
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-13 09:18:14 +01:00
|
|
|
os.chdir(PkgDir)
|
2018-01-16 06:08:25 +01:00
|
|
|
size1 = int( os.popen( "\du -sm klayout.app" ) .read().strip("\n").split("\t")[0] )
|
|
|
|
|
size2 = int( os.popen( "\du -sm klayout.scripts" ).read().strip("\n").split("\t")[0] )
|
2018-01-13 09:18:14 +01:00
|
|
|
os.chdir(ProjectDir)
|
|
|
|
|
return size1+size2
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
## To get command line parameters
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
def ParseCommandLineArguments():
|
|
|
|
|
global ProjectDir
|
|
|
|
|
global Usage
|
2018-01-13 09:18:14 +01:00
|
|
|
global GenOSName
|
2018-01-09 13:13:10 +01:00
|
|
|
global Platform
|
|
|
|
|
global PkgDir
|
|
|
|
|
global OpClean
|
|
|
|
|
global OpMake
|
|
|
|
|
global DMGSerialNum
|
2018-01-15 07:12:06 +01:00
|
|
|
global QtIdentification
|
2018-01-09 13:13:10 +01:00
|
|
|
global Version
|
2018-01-13 09:18:14 +01:00
|
|
|
global OccupiedDS
|
2018-01-11 13:46:56 +01:00
|
|
|
global TargetDMG
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
p = optparse.OptionParser( usage=Usage )
|
|
|
|
|
p.add_option( '-p', '--pkg',
|
|
|
|
|
dest='pkg_dir',
|
|
|
|
|
help="the pkg directory" )
|
|
|
|
|
|
|
|
|
|
p.add_option( '-c', '--clean',
|
|
|
|
|
action='store_true',
|
|
|
|
|
dest='operation_clean',
|
|
|
|
|
default=False,
|
|
|
|
|
help="clean operation" )
|
|
|
|
|
|
|
|
|
|
p.add_option( '-m', '--make',
|
|
|
|
|
action='store_true',
|
|
|
|
|
dest='operation_make',
|
|
|
|
|
default=False,
|
|
|
|
|
help="make operation" )
|
|
|
|
|
|
2018-01-11 13:46:56 +01:00
|
|
|
p.add_option( '-q', '--qt',
|
|
|
|
|
dest='qt_identification',
|
|
|
|
|
help="Qt's ID" )
|
|
|
|
|
|
2018-01-09 13:13:10 +01:00
|
|
|
p.add_option( '-s', '--serial',
|
|
|
|
|
dest='dmg_serial',
|
|
|
|
|
help="DMG serial number" )
|
|
|
|
|
|
|
|
|
|
p.add_option( '-?', '--??',
|
|
|
|
|
action='store_true',
|
|
|
|
|
dest='checkusage',
|
|
|
|
|
default=False,
|
|
|
|
|
help='check usage' )
|
|
|
|
|
|
2018-01-11 13:46:56 +01:00
|
|
|
p.set_defaults( pkg_dir = "",
|
|
|
|
|
operation_clean = False,
|
|
|
|
|
operation_make = False,
|
2018-03-19 02:06:38 +01:00
|
|
|
qt_identification = "Qt510Xmp",
|
2018-01-11 13:46:56 +01:00
|
|
|
dmg_serial = "1",
|
|
|
|
|
checkusage = False )
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
opt, args = p.parse_args()
|
|
|
|
|
if (opt.checkusage):
|
|
|
|
|
print(Usage)
|
|
|
|
|
quit()
|
|
|
|
|
|
2018-01-15 07:12:06 +01:00
|
|
|
PkgDir = opt.pkg_dir
|
|
|
|
|
OpClean = opt.operation_clean
|
|
|
|
|
OpMake = opt.operation_make
|
|
|
|
|
QtIdentification = opt.qt_identification
|
|
|
|
|
DMGSerialNum = int(opt.dmg_serial)
|
|
|
|
|
TargetDMG = "klayout-%s-%s-%s-%d-%s.dmg" % (Version, GenOSName, Platform, DMGSerialNum, QtIdentification)
|
2018-01-09 13:13:10 +01:00
|
|
|
|
2018-01-13 09:18:14 +01:00
|
|
|
OccupiedDS = CheckPkgDirectory()
|
|
|
|
|
if not OccupiedDS > 0:
|
2018-01-09 13:13:10 +01:00
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
if (OpClean and OpMake) or (not OpClean and not OpMake):
|
|
|
|
|
print( "! Specify <-c|--clean> OR <-m|--make>", file=sys.stderr )
|
|
|
|
|
print(Usage)
|
|
|
|
|
quit()
|
|
|
|
|
|
2018-01-11 13:46:56 +01:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
## Make the target DMG file
|
|
|
|
|
#
|
|
|
|
|
# @param[in] msg message to print
|
|
|
|
|
#
|
|
|
|
|
# @return True on success; False on failure
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
def MakeTargetDMGFile(msg=""):
|
2018-01-14 09:17:53 +01:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
# The work DMG is mounted like:
|
|
|
|
|
# /dev/disk6s1 248Mi 228Mi 20Mi 93% 58449 5027 92% /Volumes/KLayout
|
|
|
|
|
#-----------------------------------------------------------------------
|
2018-01-15 06:55:24 +01:00
|
|
|
global MountDir # the mount directory: eg. /Volumes/KLayout
|
2018-01-16 06:08:25 +01:00
|
|
|
global FileSys # the file system : eg. /dev/disk6s1
|
2018-01-11 13:46:56 +01:00
|
|
|
|
2018-01-16 06:08:25 +01:00
|
|
|
#-------------------------------------------------------------
|
2018-01-11 13:46:56 +01:00
|
|
|
# [1] Print message
|
2018-01-16 06:08:25 +01:00
|
|
|
#-------------------------------------------------------------
|
2018-01-11 13:46:56 +01:00
|
|
|
if not msg == "":
|
|
|
|
|
print(msg)
|
|
|
|
|
|
2018-01-16 06:08:25 +01:00
|
|
|
#-------------------------------------------------------------
|
|
|
|
|
# [2] Do the following jobs (0) through (14) sequentially
|
|
|
|
|
#-------------------------------------------------------------
|
|
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (0) Cleanup ProjectDir/
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-14 09:17:53 +01:00
|
|
|
CleanUp()
|
|
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (1) Read the AppleScript template file and generate
|
2018-01-16 06:08:25 +01:00
|
|
|
# the actual one to execute later
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-14 09:17:53 +01:00
|
|
|
print( ">>> (1) Preparing AppleScript to execute later..." )
|
2018-01-16 06:08:25 +01:00
|
|
|
tempScr = "macbuild/Resources/template-KLayoutDMG.applescript"
|
2018-01-14 03:12:45 +01:00
|
|
|
try:
|
2018-01-16 06:08:25 +01:00
|
|
|
fd = open( tempScr, "r" )
|
2018-01-14 03:12:45 +01:00
|
|
|
tmpl = fd.read()
|
|
|
|
|
fd.close()
|
|
|
|
|
except Exception as e:
|
2018-01-16 10:47:30 +01:00
|
|
|
print( " ! Failed to read <%s>" % tempScr, file=sys.stderr )
|
2018-01-14 03:12:45 +01:00
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
t = string.Template(tmpl)
|
2018-01-16 06:08:25 +01:00
|
|
|
# Figures below were determined by experiments for best fit
|
2018-01-15 10:22:14 +01:00
|
|
|
applescript = t.safe_substitute(
|
|
|
|
|
ORGX='50', ORGY='100',
|
|
|
|
|
WIN_WIDTH='1000', WIN_HEIGHT='700',
|
|
|
|
|
FULL_PATH_DS_STORE='/Volumes/%s/.DS_Store' % VolumeDMG,
|
|
|
|
|
BACKGROUND_PNG_FILE=BackgroundPNG,
|
|
|
|
|
ITEM_1='klayout.app', X1='960', Y1='140',
|
|
|
|
|
ITEM_2='klayout.scripts', X2='610', Y2='140',
|
|
|
|
|
ITEM_3='Applications', X3='790', Y3='140',
|
|
|
|
|
CHECK_BASH='[ -f " & dotDSStore & " ]; echo $?'
|
|
|
|
|
)
|
2018-01-14 09:17:53 +01:00
|
|
|
try:
|
2018-01-14 03:12:45 +01:00
|
|
|
# print(applescript)
|
2018-01-14 09:17:53 +01:00
|
|
|
fd = open( AppleScriptDMG, "w" )
|
|
|
|
|
fd.write(applescript)
|
|
|
|
|
fd.close()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print( "! Failed to write <%s>" % AppleScriptDMG, file=sys.stderr )
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
print( " saved <%s>" % AppleScriptDMG )
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
2018-01-14 09:17:53 +01:00
|
|
|
# (2) Create a work disk image under ProjectDir/
|
2018-01-11 13:46:56 +01:00
|
|
|
#----------------------------------------------------
|
2018-01-14 03:12:45 +01:00
|
|
|
if os.path.exists(WorkDMG):
|
|
|
|
|
os.remove(WorkDMG)
|
2018-01-14 09:17:53 +01:00
|
|
|
dmgsize = OccupiedDS + 20 # approx. occupied size plus 20[MB]
|
2018-01-14 03:12:45 +01:00
|
|
|
cmdline = 'hdiutil create -srcfolder %s -volname %s -fs HFS+ -fsargs "-c c=64,a=16,e=16" '
|
2018-01-16 06:08:25 +01:00
|
|
|
cmdline += '-format UDRW -size %dm %s'
|
2018-01-14 09:17:53 +01:00
|
|
|
command = cmdline % (PkgDir, VolumeDMG, dmgsize, WorkDMG)
|
|
|
|
|
print( ">>> (2) Creating a work DMG file <%s> of <%d> [MB] with the volume name of <%s>..." % (WorkDMG, dmgsize, VolumeDMG) )
|
2018-01-14 03:12:45 +01:00
|
|
|
os.system(command)
|
2018-01-14 09:17:53 +01:00
|
|
|
MountDir = "/Volumes/%s" % VolumeDMG
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-15 06:55:24 +01:00
|
|
|
# (3) Check if the mount point 'MountDir' already exists.
|
2018-01-16 06:08:25 +01:00
|
|
|
# If so, unmount it first.
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-14 09:17:53 +01:00
|
|
|
command1 = "hdiutil info | grep %s | grep \"/dev/\" | awk '{print $1}'" % VolumeDMG
|
|
|
|
|
print ( ">>> (3) Checking if the mount point <%s> already exists..." % MountDir)
|
2018-01-16 06:08:25 +01:00
|
|
|
FileSys = os.popen(command1).read().strip('\n')
|
|
|
|
|
if os.path.isdir(MountDir) and not FileSys == "":
|
|
|
|
|
command2 = "hdiutil detach %s" % FileSys
|
2018-01-14 09:17:53 +01:00
|
|
|
os.system(command2)
|
|
|
|
|
print( " Mount directory <%s> was detached" % MountDir )
|
|
|
|
|
else:
|
|
|
|
|
print( " Mount directory <%s> does not exist; nothing to do" % MountDir )
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (4) Mount the DMG
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
print( ">>> (4) Mounting <%s> to <%s>" % (WorkDMG, MountDir ) )
|
2018-09-18 03:38:34 +02:00
|
|
|
command1 = "hdiutil attach %s -readwrite -noverify -quiet -noautoopen" % WorkDMG
|
2018-01-14 09:17:53 +01:00
|
|
|
os.system(command1)
|
|
|
|
|
|
|
|
|
|
command2 = "hdiutil info | grep %s | grep \"/dev/\" | awk '{print $1}'" % VolumeDMG
|
2018-01-16 06:08:25 +01:00
|
|
|
FileSys = os.popen(command2).read().strip('\n')
|
|
|
|
|
if FileSys == "":
|
2018-01-14 09:17:53 +01:00
|
|
|
print( "! Failed to identify the file system on which <%s> is mounted" % VolumeDMG )
|
2018-01-14 03:12:45 +01:00
|
|
|
return False
|
|
|
|
|
else:
|
2018-01-16 06:08:25 +01:00
|
|
|
print( " File System = %s" % FileSys )
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-15 13:16:16 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (5) Copy the background image
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-16 06:08:25 +01:00
|
|
|
print( ">>> (5) Copying the background image..." )
|
2018-01-15 06:55:24 +01:00
|
|
|
imageSrc = "macbuild/Resources/%s" % BackgroundPNG
|
|
|
|
|
imageDest = "%s/.background" % MountDir
|
2018-01-14 09:17:53 +01:00
|
|
|
if not os.path.isdir(imageDest):
|
|
|
|
|
os.mkdir(imageDest)
|
2018-01-16 06:08:25 +01:00
|
|
|
command = "\cp -p %s %s/%s" % (imageSrc, imageDest, BackgroundPNG)
|
2018-01-15 13:16:16 +01:00
|
|
|
os.system(command)
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (6) Create a symbolic link to /Applications
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
print( ">>> (6) Creating a symbolic link to /Applications..." )
|
2018-01-16 06:08:25 +01:00
|
|
|
command = "\ln -s %s %s/%s" % (RootApplications, MountDir, RootApplications)
|
2018-01-14 09:17:53 +01:00
|
|
|
os.system(command)
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (7) Run the AppleScript
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
print( ">>> (7) Running the AppleScript..." )
|
|
|
|
|
command = "/usr/bin/osascript %s %s" % (AppleScriptDMG, VolumeDMG)
|
|
|
|
|
process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True )
|
|
|
|
|
output, error = process.communicate()
|
|
|
|
|
if not output == "":
|
|
|
|
|
print( " STDOUT: %s" % output )
|
|
|
|
|
if not error == "":
|
|
|
|
|
print( " STDERR: %s" % error )
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
# (8) Copy the custom volume icon
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-16 06:08:25 +01:00
|
|
|
sleep(4)
|
2018-01-15 13:16:16 +01:00
|
|
|
print( ">>> (8) Copying the volume icon..." )
|
|
|
|
|
iconsSrc = "macbuild/Resources/%s" % VolumeIcons
|
|
|
|
|
iconsDest = "%s/.VolumeIcon.icns" % MountDir
|
2018-01-16 06:08:25 +01:00
|
|
|
command1 = "\cp -p %s %s" % (iconsSrc, iconsDest)
|
2018-01-15 13:16:16 +01:00
|
|
|
command2 = "SetFile -c icnC %s" % iconsDest
|
|
|
|
|
os.system(command1)
|
2018-01-16 06:08:25 +01:00
|
|
|
sleep(2)
|
2018-01-15 13:16:16 +01:00
|
|
|
os.system(command2)
|
2018-01-16 06:08:25 +01:00
|
|
|
sleep(2)
|
2018-01-15 13:16:16 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
# (9) Change the permission
|
|
|
|
|
#--------------------------------------------------------
|
|
|
|
|
print( ">>> (9) Changing permission to 755..." )
|
2018-01-16 06:08:25 +01:00
|
|
|
command = "\chmod -Rf 755 %s &> /dev/null" % MountDir
|
2018-01-15 13:16:16 +01:00
|
|
|
os.system(command)
|
2018-01-14 03:12:45 +01:00
|
|
|
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-16 06:08:25 +01:00
|
|
|
# (10) Set volume bootability and startup disk options.
|
|
|
|
|
# The folder will open on mount.
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
print( ">>> (10) Setting volume bootability and startup disk options..." )
|
2018-01-14 09:17:53 +01:00
|
|
|
command = "bless --folder %s --openfolder %s" % (MountDir, MountDir)
|
|
|
|
|
os.system(command)
|
2018-01-16 06:08:25 +01:00
|
|
|
sleep(2)
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
# (11) Set attributes of files and directories
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
print( ">>> (11) Setting attributes of files and directories..." )
|
2018-01-14 09:17:53 +01:00
|
|
|
command = "SetFile -a C %s" % MountDir # Custom icon (allowed on folders)
|
|
|
|
|
os.system(command)
|
2018-01-16 06:08:25 +01:00
|
|
|
sleep(2)
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
# (12) Unmount the disk image
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
print( ">>> (12) Unmounting the disk image..." )
|
2018-01-16 06:08:25 +01:00
|
|
|
command = "hdiutil detach %s" % FileSys
|
2018-01-14 09:17:53 +01:00
|
|
|
os.system(command)
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
# (13) Compress the disk image
|
2018-01-11 13:46:56 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-14 09:17:53 +01:00
|
|
|
print( "" )
|
2018-01-15 13:16:16 +01:00
|
|
|
print( ">>> (13) Compressing the disk image..." )
|
2018-01-14 09:17:53 +01:00
|
|
|
command = "hdiutil convert %s -format UDZO -imagekey zlib-level=9 -o %s" % (WorkDMG, TargetDMG)
|
|
|
|
|
os.system(command)
|
|
|
|
|
os.remove(WorkDMG)
|
|
|
|
|
print( "" )
|
2018-01-16 06:08:25 +01:00
|
|
|
print( " generated compressed target DMG <%s>" % TargetDMG )
|
2018-01-14 09:17:53 +01:00
|
|
|
|
|
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
# (14) Compute MD5 checksum
|
2018-01-14 09:17:53 +01:00
|
|
|
#--------------------------------------------------------
|
2018-01-15 13:16:16 +01:00
|
|
|
print( "" )
|
|
|
|
|
print( ">>> (14) Computing MD5 checksum..." )
|
|
|
|
|
with open( TargetDMG, "rb" ) as f:
|
|
|
|
|
data = f.read()
|
|
|
|
|
md5 = hashlib.md5(data).hexdigest()
|
|
|
|
|
md5 += " *%s\n" % TargetDMG
|
|
|
|
|
f.close()
|
|
|
|
|
path, ext = os.path.splitext( os.path.basename(TargetDMG) )
|
|
|
|
|
md5TargetDMG = path + ".dmg.md5"
|
|
|
|
|
with open( md5TargetDMG, "w" ) as f:
|
|
|
|
|
f.write(md5)
|
|
|
|
|
f.close()
|
|
|
|
|
print( " generated MD5 checksum file <%s>" % md5TargetDMG )
|
|
|
|
|
print( "" )
|
2018-01-11 13:46:56 +01:00
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
## Clean up
|
|
|
|
|
#
|
|
|
|
|
# @param[in] msg message to print
|
|
|
|
|
#
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
def CleanUp(msg=""):
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
# [1] Print message
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
if not msg == "":
|
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
2018-01-14 09:17:53 +01:00
|
|
|
# [2] Clean up *.dmg*
|
2018-01-11 13:46:56 +01:00
|
|
|
#----------------------------------------------------
|
|
|
|
|
os.chdir(ProjectDir)
|
2018-01-14 09:17:53 +01:00
|
|
|
dmgs = glob.glob( "*.dmg*" )
|
2018-01-11 13:46:56 +01:00
|
|
|
for item in dmgs:
|
|
|
|
|
os.system( "rm -Rf %s" % item )
|
2018-01-14 09:17:53 +01:00
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
# [3] Clean up AppleScript if any
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
if os.path.exists(AppleScriptDMG) and os.path.isfile(AppleScriptDMG):
|
|
|
|
|
os.remove(AppleScriptDMG)
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
## The main function
|
|
|
|
|
#------------------------------------------------------------------------------
|
2018-01-11 13:46:56 +01:00
|
|
|
def Main():
|
2018-01-09 13:13:10 +01:00
|
|
|
SetGlobals()
|
|
|
|
|
ParseCommandLineArguments()
|
2018-01-11 13:46:56 +01:00
|
|
|
if OpMake:
|
|
|
|
|
print( "" )
|
|
|
|
|
print( " ### You are going to make <%s> from <%s>" % (TargetDMG, PkgDir) )
|
2018-01-13 09:18:14 +01:00
|
|
|
print( " KLayout bundles occupy about <%d> [MB] of disc space." % OccupiedDS )
|
2018-01-16 06:08:25 +01:00
|
|
|
print( "" )
|
2018-01-11 13:46:56 +01:00
|
|
|
ok = MakeTargetDMGFile()
|
|
|
|
|
if not ok:
|
|
|
|
|
print( " !!! Failed to make the target DMG <%s> ..." % TargetDMG, file=sys.stderr )
|
|
|
|
|
print( "", file=sys.stderr )
|
|
|
|
|
else:
|
2018-01-15 06:55:24 +01:00
|
|
|
print( " ### Done making the target DMG" )
|
2018-01-11 13:46:56 +01:00
|
|
|
print( "" )
|
|
|
|
|
else:
|
|
|
|
|
print( "" )
|
2018-01-14 09:17:53 +01:00
|
|
|
print( " ### You are going to clean up <%s> directory" % ProjectDir )
|
2018-01-11 13:46:56 +01:00
|
|
|
CleanUp()
|
2018-01-15 06:55:24 +01:00
|
|
|
print( " ### Done cleaning up" )
|
2018-01-11 13:46:56 +01:00
|
|
|
print( "" )
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#===================================================================================
|
|
|
|
|
if __name__ == "__main__":
|
2018-01-11 13:46:56 +01:00
|
|
|
Main()
|
2018-01-09 13:13:10 +01:00
|
|
|
|
|
|
|
|
#---------------
|
|
|
|
|
# End of file
|
|
|
|
|
#---------------
|