decrease repeated defintions of the same function

This commit is contained in:
Greg Neagle
2017-01-09 10:14:16 -08:00
parent 0e56d0bae3
commit 8deb944a7c
3 changed files with 32 additions and 38 deletions

View File

@@ -263,6 +263,7 @@ def getCatalogInfoFromDmg(dmgpath, options):
return cataloginfo
# TO-DO: delete this and use pkgutils.getBundleInfo() other places here
def getBundleInfo(path):
"""
Returns Info.plist data if available
@@ -282,6 +283,7 @@ def getBundleInfo(path):
return None
# TO-DO: this (or a similar) function is defined several places. De-dupe.
def readfile(path):
'''Reads file at path. Returns a string.'''
try:

View File

@@ -31,7 +31,6 @@ from xml.dom import minidom
from .. import osutils
from .. import pkgutils
from .. import FoundationPlist
# we use lots of camelCase-style names. Deal with it.
# pylint: disable=C0103
@@ -395,25 +394,6 @@ def getHDInstallerInfo(hd_payload_root, sap_code):
return hd_app_info
def getBundleInfo(path):
"""
Returns Info.plist data if available
for bundle at path
"""
infopath = os.path.join(path, "Contents", "Info.plist")
if not os.path.exists(infopath):
infopath = os.path.join(path, "Resources", "Info.plist")
if os.path.exists(infopath):
try:
plist = FoundationPlist.readPlist(infopath)
return plist
except FoundationPlist.NSPropertyListSerializationException:
pass
return None
def getCS5mediaSignature(dirpath):
'''Returns the CS5 mediaSignature for an AAMEE CS5 install.
dirpath is typically the root of a mounted dmg'''
@@ -736,7 +716,7 @@ def getAdobeCatalogInfo(mountpoint, pkgname=""):
cataloginfo = {}
cataloginfo['installer_type'] = "AdobeAcrobatUpdater"
cataloginfo['uninstallable'] = False
plist = getBundleInfo(acrobatpatcherapp)
plist = pkgutils.getBundleInfo(acrobatpatcherapp)
cataloginfo['version'] = pkgutils.getVersionString(plist)
cataloginfo['name'] = "AcrobatPro9Update"
cataloginfo['display_name'] = "Adobe Acrobat Pro Update"

46
code/client/munkilib/pkgutils.py Normal file → Executable file
View File

@@ -173,11 +173,29 @@ def getVersionString(plist, key=None):
return ''
def getBundleInfo(path):
"""
Returns Info.plist data if available
for bundle at path
"""
infopath = os.path.join(path, "Contents", "Info.plist")
if not os.path.exists(infopath):
infopath = os.path.join(path, "Resources", "Info.plist")
if os.path.exists(infopath):
try:
plist = FoundationPlist.readPlist(infopath)
return plist
except FoundationPlist.NSPropertyListSerializationException:
pass
return None
def getAppBundleExecutable(bundlepath):
"""Returns path to the actual executable in an app bundle or None"""
infoPlist = os.path.join(bundlepath, 'Contents', 'Info.plist')
if os.path.exists(infoPlist):
plist = FoundationPlist.readPlist(infoPlist)
plist = getBundleInfo(bundlepath)
if plist:
if 'CFBundleExecutable' in plist:
executable = plist['CFBundleExecutable']
elif 'CFBundleName' in plist:
@@ -198,11 +216,8 @@ def getBundleVersion(bundlepath, key=None):
Specify key to use a specific key in the Info.plist for
the version string.
"""
infoPlist = os.path.join(bundlepath, 'Contents', 'Info.plist')
if not os.path.exists(infoPlist):
infoPlist = os.path.join(bundlepath, 'Resources', 'Info.plist')
if os.path.exists(infoPlist):
plist = FoundationPlist.readPlist(infoPlist)
plist = getBundleInfo(bundlepath)
if plist:
versionstring = getVersionString(plist, key)
if versionstring:
return versionstring
@@ -412,11 +427,10 @@ def getBomList(pkgpath):
def getOnePackageInfo(pkgpath):
"""Gets receipt info for a single bundle-style package"""
pkginfo = {}
plistpath = os.path.join(pkgpath, 'Contents', 'Info.plist')
if os.path.exists(plistpath):
plist = getBundleInfo(pkgpath)
if plist:
pkginfo['filename'] = os.path.basename(pkgpath)
try:
plist = FoundationPlist.readPlist(plistpath)
if 'CFBundleIdentifier' in plist:
pkginfo['packageid'] = plist['CFBundleIdentifier']
elif 'Bundle identifier' in plist:
@@ -491,9 +505,8 @@ def getBundlePackageInfo(pkgpath):
# no .dist file found, look for packages in subdirs
dirsToSearch = []
plistpath = os.path.join(pkgpath, 'Contents', 'Info.plist')
if os.path.exists(plistpath):
plist = FoundationPlist.readPlist(plistpath)
plist = getBundleInfo(pkgpath)
if plist:
if 'IFPkgFlagComponentDirectory' in plist:
componentdir = plist['IFPkgFlagComponentDirectory']
dirsToSearch.append(componentdir)
@@ -842,9 +855,8 @@ def isApplication(pathname):
if os.path.isdir(pathname):
# look for app bundle structure
# use Info.plist to determine the name of the executable
infoplist = os.path.join(pathname, 'Contents', 'Info.plist')
if os.path.exists(infoplist):
plist = FoundationPlist.readPlist(infoplist)
plist = getBundleInfo(pathname)
if plist:
if 'CFBundlePackageType' in plist:
if plist['CFBundlePackageType'] != 'APPL':
return False