mirror of
https://github.com/munki/munki.git
synced 2026-04-23 04:59:17 -05:00
Further refactoring for hasValid extension check functions
- hasValidPackageExt(), hasValidDiskImageExt() for the appropriate
extensions, and hasValidInstallerItemExt() to call them
- replace many checks to use the above
- munkiimport.py now uses munkicommon.isApplication() to do the
equivalent of checking endswith('.app')
- fix an errand merge ancestor from an old unrelated munkiimport
branch
This commit is contained in:
@@ -71,7 +71,7 @@ def getCatalogInfoFromDmg(dmgpath, options):
|
||||
# search for first package at root
|
||||
for fsitem in munkicommon.listdir(mountpoints[0]):
|
||||
itempath = os.path.join(mountpoints[0], fsitem)
|
||||
if itempath.endswith('.pkg') or itempath.endswith('.mpkg'):
|
||||
if munkicommon.hasValidInstallerItemExt(itempath):
|
||||
cataloginfo = munkicommon.getPackageMetaData(itempath)
|
||||
if options.installer_choices_xml:
|
||||
installer_choices_xml = munkicommon.getChoiceChangesXML(
|
||||
@@ -643,7 +643,7 @@ def main():
|
||||
itemsize = int(os.path.getsize(item))
|
||||
itemhash = munkicommon.getsha256hash(item)
|
||||
|
||||
if item.endswith('.dmg'):
|
||||
if munkicommon.hasValidDiskImageExt(item):
|
||||
if munkicommon.DMGisWritable(item):
|
||||
print >> sys.stderr, ("WARNING: %s is a writable disk "
|
||||
"image. Checksum verification is not supported."
|
||||
@@ -668,7 +668,7 @@ def main():
|
||||
item
|
||||
exit(-1)
|
||||
|
||||
elif item.endswith('.pkg') or item.endswith('.mpkg'):
|
||||
elif munkicommon.hasValidPackageExt(item):
|
||||
catinfo = munkicommon.getPackageMetaData(item)
|
||||
if options.installer_choices_xml:
|
||||
installer_choices_xml = munkicommon.getChoiceChangesXML(
|
||||
|
||||
@@ -611,8 +611,8 @@ def main():
|
||||
# Strip trailing '/' from installer_item
|
||||
installer_item = installer_item.rstrip('/')
|
||||
|
||||
item_ext = os.path.splitext(installer_item)[1]
|
||||
if item_ext not in ['.pkg', '.mpkg', '.dmg', '.app']:
|
||||
if not munkicommon.hasValidDiskImageExt(installer_item) and \
|
||||
not munkicommon.isApplication(installer_item):
|
||||
print >> sys.stderr, (
|
||||
'Unknown installer item type: "%s"' % installer_item)
|
||||
exit(-1)
|
||||
@@ -633,8 +633,8 @@ def main():
|
||||
exit(-1)
|
||||
|
||||
if os.path.isdir(installer_item):
|
||||
if item_ext == '.dmg':
|
||||
# a directory named foo.dmg!
|
||||
if munkicommon.hasValidDiskImageExt(installer_item):
|
||||
# a directory named foo.dmg or foo.iso!
|
||||
print >> sys.stderr, '%s is an unknown type.' % installer_item
|
||||
cleanupAndExit(-1)
|
||||
else:
|
||||
|
||||
@@ -260,7 +260,7 @@ def installall(dirpath, choicesXMLpath=None, suppressBundleRelocation=False,
|
||||
if munkicommon.stopRequested():
|
||||
return (retcode, restartflag)
|
||||
itempath = os.path.join(dirpath, item)
|
||||
if item.endswith(".dmg"):
|
||||
if munkicommon.hasValidDiskImageExt(item):
|
||||
munkicommon.display_info("Mounting disk image %s" % item)
|
||||
mountpoints = munkicommon.mountdmg(itempath, use_shadow=True)
|
||||
if mountpoints == []:
|
||||
@@ -286,7 +286,7 @@ def installall(dirpath, choicesXMLpath=None, suppressBundleRelocation=False,
|
||||
|
||||
munkicommon.unmountdmg(mountpoints[0])
|
||||
|
||||
if (item.endswith(".pkg") or item.endswith(".mpkg")):
|
||||
if munkicommon.hasValidInstallerItemExt(item):
|
||||
(retcode, needsrestart) = install(itempath, choicesXMLpath,
|
||||
suppressBundleRelocation,
|
||||
environment)
|
||||
@@ -659,7 +659,7 @@ def installWithInfo(
|
||||
else:
|
||||
choicesXMLfile = ''
|
||||
installer_environment = item.get('installer_environment')
|
||||
if itempath.endswith(".dmg"):
|
||||
if munkicommon.hasValidDiskImageExt(itempath):
|
||||
munkicommon.display_status_minor(
|
||||
"Mounting disk image %s" % item["installer_item"])
|
||||
mountWithShadow = suppressBundleRelocation
|
||||
@@ -679,8 +679,7 @@ def installWithInfo(
|
||||
|
||||
retcode = -99 # in case we find nothing to install
|
||||
needtorestart = False
|
||||
if item.get('package_path','').endswith('.pkg') or \
|
||||
item.get('package_path','').endswith('.mpkg'):
|
||||
if munkicommon.hasValidInstallerItemExt(item.get('package_path', '')):
|
||||
# admin has specified the relative path of the pkg
|
||||
# on the DMG
|
||||
# this is useful if there is more than one pkg on
|
||||
@@ -706,8 +705,8 @@ def installWithInfo(
|
||||
item.get("RestartAction") == "RecommendRestart"):
|
||||
restartflag = True
|
||||
munkicommon.unmountdmg(mountpoints[0])
|
||||
elif (itempath.endswith(".pkg") or itempath.endswith(".mpkg")
|
||||
or itempath.endswith(".dist")):
|
||||
elif munkicommon.hasValidPackageExt(itempath) or \
|
||||
itempath.endswith(".dist"):
|
||||
(retcode, needtorestart) = install(itempath,
|
||||
choicesXMLfile,
|
||||
suppressBundleRelocation,
|
||||
@@ -817,7 +816,7 @@ def installWithInfo(
|
||||
else:
|
||||
# flat pkg or dmg
|
||||
retcode = subprocess.call(["/bin/rm", itempath])
|
||||
if itempath.endswith('.dmg'):
|
||||
if munkicommon.hasValidDiskImageExt(itempath):
|
||||
shadowfile = os.path.join(itempath,".shadow")
|
||||
if os.path.exists(shadowfile):
|
||||
retcode = subprocess.call(
|
||||
|
||||
@@ -1473,7 +1473,7 @@ def getBundlePackageInfo(pkgpath):
|
||||
def getReceiptInfo(pkgname):
|
||||
"""Get receipt info from a package"""
|
||||
info = []
|
||||
if pkgname.endswith('.pkg') or pkgname.endswith('.mpkg'):
|
||||
if hasValidPackageExt(pkgname):
|
||||
display_debug2('Examining %s' % pkgname)
|
||||
if os.path.isfile(pkgname): # new flat package
|
||||
info = getFlatPackageInfo(pkgname)
|
||||
@@ -1592,14 +1592,21 @@ def nameAndVersion(aString):
|
||||
return (aString, '')
|
||||
|
||||
|
||||
def hasValidPackageExt(path):
|
||||
"""Verifies a path ends in '.pkg' or '.mpkg'"""
|
||||
ext = os.path.splitext(path)[1]
|
||||
return ext.lower() in ['.pkg', '.mpkg']
|
||||
|
||||
def isInstallerItem(path):
|
||||
|
||||
def hasValidDiskImageExt(path):
|
||||
"""Verifies a path ends in '.dmg' or '.iso'"""
|
||||
ext = os.path.splitext(path)[1]
|
||||
return ext.lower() in ['.dmg', '.iso']
|
||||
|
||||
|
||||
def hasValidInstallerItemExt(path):
|
||||
"""Verifies we have an installer item"""
|
||||
if (path.endswith('.pkg') or path.endswith('.mpkg') or
|
||||
path.endswith('.dmg') or path.endswith('.dist')):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return hasValidPackageExt(path) or hasValidDiskImageExt(path)
|
||||
|
||||
|
||||
def getChoiceChangesXML(pkgitem):
|
||||
@@ -1642,7 +1649,7 @@ def getPackageMetaData(pkgitem):
|
||||
(some may not be installed on some machines)
|
||||
"""
|
||||
|
||||
if not isInstallerItem(pkgitem):
|
||||
if not hasValidInstallerItemExt(pkgitem):
|
||||
return {}
|
||||
|
||||
# first get the data /usr/sbin/installer will give us
|
||||
|
||||
Reference in New Issue
Block a user