From 1093f6a55fe16eeb0bbe24d0d3c27f6109e8f0c2 Mon Sep 17 00:00:00 2001 From: Hannes Juutilainen Date: Thu, 14 Mar 2013 15:15:24 +0200 Subject: [PATCH] Minor refactoring and documentation --- code/client/makepkginfo | 8 +++---- code/client/munkilib/munkicommon.py | 33 +++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/code/client/makepkginfo b/code/client/makepkginfo index ef586010..2027ab0b 100755 --- a/code/client/makepkginfo +++ b/code/client/makepkginfo @@ -55,8 +55,8 @@ def getCatalogInfoFromDmg(dmgpath, options): To-do: handle multiple installer items on a disk image(?) """ cataloginfo = None - dmgWasAlreadyMounted = munkicommon.dmgIsMounted(dmgpath) - mountpoints = munkicommon.mountdmg(dmgpath) + dmgWasAlreadyMounted = munkicommon.diskImageIsMounted(dmgpath) + mountpoints = munkicommon.mountdmg(dmgpath, use_existing_mounts=True) if not mountpoints: print >> sys.stderr, "Could not mount %s!" % dmgpath exit(-1) @@ -701,10 +701,10 @@ def main(): if item and os.path.exists(item): # Check if the item is a mount point for a disk image - if munkicommon.dmgForMountPoint(item): + if munkicommon.pathIsVolumeMountPoint(item): # Get the disk image path for the mount point # and use that instead of the original item - item = munkicommon.dmgForMountPoint(item) + item = munkicommon.diskImageForMountPoint(item) # get size of installer item itemsize = 0 diff --git a/code/client/munkilib/munkicommon.py b/code/client/munkilib/munkicommon.py index 6cc56f7d..0bccc282 100755 --- a/code/client/munkilib/munkicommon.py +++ b/code/client/munkilib/munkicommon.py @@ -820,6 +820,7 @@ def DMGhasSLA(dmgpath): def hdiutilInfo(): """ Convenience method for running 'hdiutil info -plist' + Returns the root object parsed with readPlistFromString() """ proc = subprocess.Popen( @@ -839,7 +840,7 @@ def hdiutilInfo(): return None -def dmgIsMounted(dmgpath): +def diskImageIsMounted(dmgpath): """ Returns true if the given disk image is currently mounted """ @@ -854,12 +855,32 @@ def dmgIsMounted(dmgpath): return isMounted -def dmgForMountPoint(path): +def pathIsVolumeMountPoint(path): """ - Checks if the given file system path - is a mount point for a disk image + Checks if the given path is a volume for an attached disk image - Returns the dmg path or None + Returns true if the given path is a mount point or false if it isn't + """ + isMountPoint = False + infoplist = hdiutilInfo() + for imageProperties in infoplist.get('images'): + if 'image-path' in imageProperties: + imagepath = imageProperties['image-path'] + for entity in imageProperties.get('system-entities', []): + if 'mount-point' in entity: + mountpoint = entity['mount-point'] + if path == mountpoint: + isMountPoint = True + break + return isMountPoint + + +def diskImageForMountPoint(path): + """ + Resolves the given mount point path to an attached disk image path + + Returns a path to a disk image file or None if the path is not + a valid mount point """ dmgpath = None infoplist = hdiutilInfo() @@ -873,7 +894,7 @@ def dmgForMountPoint(path): dmgpath = imagepath return dmgpath -def mountPointsForDmg(dmgpath): +def mountPointsForDiskImage(dmgpath): """ Returns a list of mountpoints for the given disk image """