munkicommon: pylint cleanup, better handling of items in the pkgutil database that don't have a version number (I didn't know this was possible!).

appleupdates: pylint cleanup; provide installed_size data for Managed Software Update display

managedsoftwareupdate: move "Checking for available Apple Software Updates..." message to appleupdates.checkForSoftwareUpdates()

makepkginfo: fix installer_item_size determination when we add up the contents of a directory (was bytes, now Kbytes like everything else)

git-svn-id: http://munki.googlecode.com/svn/trunk@725 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
Greg Neagle
2010-09-07 18:04:40 +00:00
parent a82374aaf3
commit 121ecb0484
4 changed files with 70 additions and 59 deletions
+3 -3
View File
@@ -435,12 +435,12 @@ def main():
filename = os.path.join(path, name)
# use os.lstat so we don't follow symlinks
itemsize += int(os.lstat(filename).st_size)
# convert to kbytes
itemsize = int(itemsize/1024)
else:
print >> sys.stderr, "%s is not an installer package!" % item
exit(-1)
catinfo['installer_item_size'] = int(itemsize/1024)
catinfo['installer_item_hash'] = itemhash
-8
View File
@@ -516,14 +516,6 @@ def main():
# if there are no munki updates,
# are we supposed to check for and install Apple Software Updates?
if munkicommon.pref('InstallAppleSoftwareUpdates'):
if options.munkistatusoutput:
munkistatus.message("Checking for available "
"Apple Software Updates...")
munkistatus.detail("")
munkistatus.percent(-1)
else:
munkicommon.display_status("Checking for available "
"Apple Software Updates...")
try:
if appleupdates.appleSoftwareUpdatesAvailable(
forcecheck=(options.manualcheck or
+50 -15
View File
@@ -42,7 +42,7 @@ def getCurrentSoftwareUpdateServer():
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if proc.returncode == 0:
return str(out).rstrip('\n')
else:
@@ -55,7 +55,7 @@ def selectSoftwareUpdateServer():
cmd = ['/usr/bin/defaults', 'write',
'/Library/Preferences/com.apple.SoftwareUpdate',
'CatalogURL', munkicommon.pref('SoftwareUpdateServerURL')]
retcode = subprocess.call(cmd)
unused_retcode = subprocess.call(cmd)
def restoreSoftwareUpdateServer(theurl):
@@ -69,7 +69,7 @@ def restoreSoftwareUpdateServer(theurl):
cmd = ['/usr/bin/defaults', 'delete',
'/Library/Preferences/com.apple.SoftwareUpdate',
'CatalogURL']
retcode = subprocess.call(cmd)
unused_retcode = subprocess.call(cmd)
def setupSoftwareUpdateCheck():
@@ -78,19 +78,27 @@ def setupSoftwareUpdateCheck():
cmd = ['/usr/bin/defaults', '-currentHost', 'write',
'com.apple.SoftwareUpdate', 'AgreedToLicenseAgreement',
'-bool', 'YES']
retcode = subprocess.call(cmd)
unused_retcode = subprocess.call(cmd)
cmd = ['/usr/bin/defaults', '-currentHost', 'write',
'com.apple.SoftwareUpdate', 'AutomaticDownload',
'-bool', 'YES']
retcode = subprocess.call(cmd)
unused_retcode = subprocess.call(cmd)
cmd = ['/usr/bin/defaults', '-currentHost', 'write',
'com.apple.SoftwareUpdate', 'LaunchAppInBackground',
'-bool', 'YES']
retcode = subprocess.call(cmd)
unused_retcode = subprocess.call(cmd)
def checkForSoftwareUpdates():
'''Does our Apple Software Update check'''
if munkicommon.munkistatusoutput:
munkistatus.message("Checking for available "
"Apple Software Updates...")
munkistatus.detail("")
munkistatus.percent(-1)
else:
munkicommon.display_status("Checking for available "
"Apple Software Updates...")
# save the current SUS URL
original_url = getCurrentSoftwareUpdateServer()
# switch to a different SUS server if specified
@@ -135,7 +143,9 @@ def checkForSoftwareUpdates():
if not output and (proc.poll() != None):
break
# send the output to STDOUT or MunkiStatus as applicable
munkicommon.display_status(output.rstrip('\n'))
# But first, filter out some noise...
if not output.contains("Missing bundle identifier"):
munkicommon.display_status(output.rstrip('\n'))
retcode = proc.poll()
if retcode:
@@ -154,7 +164,7 @@ def checkForSoftwareUpdates():
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if proc.returncode == 0:
try:
LastResultCode = int(str(out).rstrip('\n'))
@@ -215,7 +225,7 @@ def parseDist(filename):
line = line[16:]
# lop off everything up through '
line = line[line.find("'")+1:]
if keep:
# replace escaped single quotes
line = line.replace("\\'","'")
@@ -229,8 +239,30 @@ def parseDist(filename):
else:
# append the line to the description
description += line + "\n"
# now try to extract the size
itemsize = 0
if gui_scripts:
pkgrefs = gui_scripts[0].getElementsByTagName("pkg-ref")
if pkgrefs:
for ref in pkgrefs:
keys = ref.attributes.keys()
if 'installKBytes' in keys:
itemsize = int(
ref.attributes[
'installKBytes'].value.encode('UTF-8'))
break
if itemsize == 0:
for (path, dirs, files) in os.walk(os.path.dirname(filename)):
for name in files:
pathname = os.path.join(path, name)
# use os.lstat so we don't follow symlinks
itemsize += int(os.lstat(pathname).st_size)
# convert to kbytes
itemsize = int(itemsize/1024)
return title, vers, description
return title, vers, description, itemsize
def getRestartInfo(installitemdir):
@@ -261,7 +293,7 @@ def getRestartInfo(installitemdir):
bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if out:
thisAction = str(out).rstrip('\n')
if thisAction in weight.keys():
@@ -289,7 +321,9 @@ def getSoftwareUpdateInfo():
for subitem in os.listdir(installitem):
if subitem.endswith('.dist'):
distfile = os.path.join(installitem, subitem)
(title, vers, description) = parseDist(distfile)
(title, vers,
description,
installedsize) = parseDist(distfile)
iteminfo = {}
iteminfo["installer_item"] = updatename
iteminfo["name"] = title
@@ -299,6 +333,7 @@ def getSoftwareUpdateInfo():
"Updated Apple software."
iteminfo["version_to_install"] = vers
iteminfo['display_name'] = title
iteminfo['installed_size'] = installedsize
restartAction = getRestartInfo(installitem)
if restartAction != "None":
iteminfo['RestartAction'] = restartAction
@@ -373,7 +408,7 @@ def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
if forcecheck:
# typically because user initiated the check from
# Managed Software Update.app
retcode = checkForSoftwareUpdates()
unused_retcode = checkForSoftwareUpdates()
elif suppresscheck:
# typically because we're doing a logout install; if
# there are no waiting Apple Updates we shouldn't
@@ -390,7 +425,7 @@ def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
proc = subprocess.Popen(cmd, bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
lastSUcheckString = str(out).rstrip('\n')
if lastSUcheckString:
@@ -401,7 +436,7 @@ def appleSoftwareUpdatesAvailable(forcecheck=False, suppresscheck=False):
except (ValueError, TypeError):
pass
if now.timeIntervalSinceDate_(nextSUcheck) >= 0:
retcode = checkForSoftwareUpdates()
unused_retcode = checkForSoftwareUpdates()
if writeAppleUpdatesFile():
displayAppleUpdateInfo()
+17 -33
View File
@@ -305,7 +305,7 @@ def archive_report():
proc = subprocess.Popen(['/bin/ls', '-t1', archivepath],
bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(output, err) = proc.communicate()
(output, unused_err) = proc.communicate()
if output:
archiveitems = [item
for item in str(output).splitlines()
@@ -357,7 +357,7 @@ def currentGUIusers():
proc = subprocess.Popen("/usr/bin/who", shell=False,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(output, err) = proc.communicate()
(output, unused_err) = proc.communicate()
lines = str(output).splitlines()
for line in lines:
if "console" in line:
@@ -373,7 +373,7 @@ def pythonScriptRunning(scriptname):
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
mypid = os.getpid()
lines = str(out).splitlines()
for line in lines:
@@ -419,8 +419,8 @@ def mountdmg(dmgpath, use_shadow=False):
bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(pliststr, err) = proc.communicate()
if err:
display_error("Error %s mounting %s." % (err, dmgname))
if proc.returncode:
display_error("Error: '%s' while mounting %s." % (err, dmgname))
if pliststr:
plist = FoundationPlist.readPlistFromString(pliststr)
for entity in plist['system-entities']:
@@ -434,12 +434,10 @@ def unmountdmg(mountpoint):
"""
Unmounts the dmg at mountpoint
"""
proc = subprocess.Popen(['/usr/bin/hdiutil', 'detach', mountpoint],
bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(ouptut, err) = proc.communicate()
if proc.returncode:
display_warning("Attempting to force unmount %s" % mountpoint)
retcode = subprocess.call(['/usr/bin/hdiutil', 'detach', mountpoint])
if retcode:
display_warning("Polite unmount failed. "
"Attempting to force unmount %s" % mountpoint)
# try forcing the unmount
retcode = subprocess.call(['/usr/bin/hdiutil', 'detach', mountpoint,
'-force'])
@@ -594,7 +592,7 @@ def getInstallerPkgInfo(filename):
"-plist", "-pkg", filename],
bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if out:
# discard any lines at the beginning that aren't part of the plist
@@ -722,11 +720,6 @@ def parsePkgRefs(filename):
for ref in pkgrefs:
keys = ref.attributes.keys()
if 'id' in keys and 'version' in keys:
#if debug:
# for key in keys:
# print key, "=>", \
# ref.attributes[key].value.encode('UTF-8')
pkginfo = {}
pkginfo['packageid'] = \
ref.attributes['id'].value.encode('UTF-8')
@@ -744,11 +737,6 @@ def parsePkgRefs(filename):
for ref in pkgrefs:
keys = ref.attributes.keys()
if 'identifier' in keys and 'version' in keys:
#if debug:
# for key in keys:
# print key, "=>", \
# ref.attributes[key].value.encode('UTF-8')
pkginfo = {}
pkginfo['packageid'] = \
ref.attributes['identifier'].value.encode('UTF-8')
@@ -976,24 +964,20 @@ def getInstalledPackageVersion(pkgid):
bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if out:
try:
plist = FoundationPlist.readPlistFromString(out)
if "pkgid" in plist:
foundbundleid = plist["pkgid"]
if "pkg-version" in plist:
foundvers = plist["pkg-version"]
except FoundationPlist.NSPropertyListSerializationException:
pass
else:
foundbundleid = plist.get("pkgid")
foundvers = plist.get("pkg-version","0.0.0.0.0")
if pkgid == foundbundleid:
display_debug2("\tThis machine has %s, version %s" %
(pkgid, foundvers))
return padVersionString(foundvers, 5)
except (AttributeError,
FoundationPlist.NSPropertyListSerializationException):
pass
# If we got to this point, we haven't found the pkgid yet.
# Check /Library/Receipts
@@ -1148,7 +1132,7 @@ def getAvailableDiskSpace(volumepath="/"):
bufsize=1,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = proc.communicate()
(out, unused_err) = proc.communicate()
if out:
try:
plist = FoundationPlist.readPlistFromString(out)