Updated munkicommon.py, removepackages.py, installer.py, and updatecheck.py to use munkilib/FoundationPlist.py instead of plistlib.

git-svn-id: http://munki.googlecode.com/svn/trunk@173 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
Greg Neagle
2009-08-20 17:55:42 +00:00
parent a11b85e970
commit a049d87846
4 changed files with 38 additions and 60 deletions
+4 -3
View File
@@ -23,10 +23,11 @@ import os
import subprocess
import sys
import time
import plistlib
#import plistlib
import tempfile
import munkicommon
import munkistatus
import FoundationPlist
from removepackages import removepackages
@@ -201,7 +202,7 @@ def installWithInfo(dirpath, installlist):
return restartflag
if 'installer_choices_xml' in item:
choicesXMLfile = os.path.join(munkicommon.tmpdir, "choices.xml")
plistlib.writePlist(item['installer_choices_xml'], choicesXMLfile)
FoundationPlist.writePlist(item['installer_choices_xml'], choicesXMLfile)
else:
choicesXMLfile = ''
if itempath.endswith(".dmg"):
@@ -355,7 +356,7 @@ def run():
installinfo = os.path.join(managedinstallbase, 'InstallInfo.plist')
if os.path.exists(installinfo):
try:
pl = plistlib.readPlist(installinfo)
pl = FoundationPlist.readPlist(installinfo)
except:
print >>sys.stderr, "Invalid %s" % installinfo
return -1
+14 -37
View File
@@ -25,7 +25,7 @@ Common functions used by the munki tools.
import sys
import os
import re
import plistlib
#import plistlib
import time
import subprocess
import tempfile
@@ -35,11 +35,9 @@ from xml.dom import minidom
#from SystemConfiguration import SCDynamicStoreCopyConsoleUser
from Foundation import NSDictionary, NSDate
from Foundation import NSData, NSPropertyListSerialization, NSPropertyListMutableContainers, NSPropertyListXMLFormat_v1_0
from PyObjCTools import Conversion
import munkistatus
import FoundationPlist
# output and logging functions
@@ -186,26 +184,6 @@ def stopRequested():
return False
def readPlist(plistfile):
"""Read a plist, return a dict.
This method can deal with binary plists,
whereas plistlib cannot.
Args:
plistfile: Path to plist file to read
Returns:
dict of plist contents.
"""
plistData = NSData.dataWithContentsOfFile_(plistfile)
dataObject, plistFormat, error = NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription_(plistData, NSPropertyListMutableContainers, None, None)
if not error:
# convert from Obj-C collection to Python collection
return Conversion.pythonCollectionFromPropertyList(dataObject)
else:
raise Exception(error)
def getconsoleuser():
# workaround no longer needed, but leaving this here for now...
#osvers = int(os.uname()[2].split('.')[0])
@@ -224,8 +202,7 @@ def getconsoleuser():
cfuser = SCDynamicStoreCopyConsoleUser( None, None, None )
return cfuser[0]
def pythonScriptRunning(scriptname):
cmd = ['/bin/ps', '-eo', 'pid=,command=']
p = subprocess.Popen(cmd, shell=False, bufsize=1, stdin=subprocess.PIPE,
@@ -259,7 +236,7 @@ def mountdmg(dmgpath):
if err:
print >>sys.stderr, "Error %s mounting %s." % (err, dmgpath)
if plist:
pl = plistlib.readPlistFromString(plist)
pl = FoundationPlist.readPlistFromString(plist)
for entity in pl['system-entities']:
if 'mount-point' in entity:
mountpoints.append(entity['mount-point'])
@@ -368,7 +345,7 @@ def getInstallerPkgInfo(filename):
(out, err) = p.communicate()
if out:
pl = plistlib.readPlistFromString(out)
pl = FoundationPlist.readPlistFromString(out)
if 'Size' in pl:
installerinfo['installed_size'] = int(pl['Size'])
if 'Description' in pl:
@@ -410,7 +387,7 @@ def getExtendedVersion(bundlepath):
infoPlist = os.path.join(bundlepath,"Contents","Info.plist")
pl = {}
if os.path.exists(versionPlist):
pl = readPlist(versionPlist)
pl = FoundationPlist.readPlist(versionPlist)
if pl:
shortVers = "0.0.0"
sourceVers = "0"
@@ -422,13 +399,13 @@ def getExtendedVersion(bundlepath):
if "BuildVersion" in pl:
buildVers = padVersionString(pl["BuildVersion"],1)
if os.path.exists(infoPlist):
pl = readPlist(infoPlist)
pl = FoundationPlist.readPlist(infoPlist)
if 'IFMinorVersion' in pl:
buildVers = padVersionString(pl['IFMinorVersion'],1)
return shortVers + "." + sourceVers + "." + buildVers
if os.path.exists(infoPlist):
pl = readPlist(infoPlist)
pl = FoundationPlist.readPlist(infoPlist)
if "CFBundleShortVersionString" in pl:
return padVersionString(pl["CFBundleShortVersionString"],5)
elif "Bundle versions string, short" in pl:
@@ -511,7 +488,7 @@ def getOnePackageInfo(pkgpath):
plistpath = os.path.join(pkgpath, "Contents", "Info.plist")
if os.path.exists(plistpath):
pkginfo['filename'] = os.path.basename(pkgpath)
pl = readPlist(plistpath)
pl = FoundationPlist.readPlist(plistpath)
if "CFBundleIdentifier" in pl:
pkginfo['packageid'] = pl["CFBundleIdentifier"]
elif "Bundle identifier" in pl:
@@ -525,8 +502,8 @@ def getOnePackageInfo(pkgpath):
if "IFPkgFlagInstalledSize" in pl:
# converting to int because plistlib barfs on longs. This might be a problem...
pkginfo['installed_size'] = int(pl["IFPkgFlagInstalledSize"])
#pkginfo['installed_size'] = pl["IFPkgFlagInstalledSize"]
#pkginfo['installed_size'] = int(pl["IFPkgFlagInstalledSize"])
pkginfo['installed_size'] = pl["IFPkgFlagInstalledSize"]
pkginfo['version'] = getExtendedVersion(pkgpath)
return pkginfo
@@ -553,7 +530,7 @@ def getBundlePackageInfo(pkgpath):
dirsToSearch = []
plistpath = os.path.join(pkgpath, "Contents", "Info.plist")
if os.path.exists(plistpath):
pl = readPlist(plistpath)
pl = FoundationPlist.readPlist(plistpath)
if 'IFPkgFlagComponentDirectory' in pl:
dirsToSearch.append(pl['IFPkgFlagComponentDirectory'])
@@ -624,7 +601,7 @@ def getInstalledPackageVersion(pkgid):
(out, err) = p.communicate()
if out:
pl = plistlib.readPlistFromString(out)
pl = FoundationPlist.readPlistFromString(out)
if "pkgid" in pl:
foundbundleid = pl["pkgid"]
@@ -751,7 +728,7 @@ def getAvailableDiskSpace(volumepath="/"):
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
if out:
pl = plistlib.readPlistFromString(out)
pl = FoundationPlist.readPlistFromString(out)
if "FreeSpace" in pl:
freespace = pl["FreeSpace"]
+5 -4
View File
@@ -30,11 +30,12 @@ import optparse
import os
import subprocess
import sys
import plistlib
#import plistlib
import sqlite3
import time
import munkistatus
import munkicommon
import FoundationPlist
##################################################################
@@ -218,7 +219,7 @@ def ImportPackage(packagepath, c):
timestamp = os.stat(packagepath).st_mtime
owner = 0
pl = munkicommon.readPlist(infopath)
pl = FoundationPlist.readPlist(infopath)
if "CFBundleIdentifier" in pl:
pkgid = pl["CFBundleIdentifier"]
elif "Bundle identifier" in pl:
@@ -308,7 +309,7 @@ def ImportBom(bompath, c):
bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(plist, err) = p.communicate()
if plist:
pl = plistlib.readPlistFromString(plist)
pl = FoundationPlist.readPlistFromString(plist)
if "install-location" in pl:
ppath = pl["install-location"]
if "pkg-version" in pl:
@@ -369,7 +370,7 @@ def ImportFromPkgutil(pkgname, c):
bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(plist, err) = p.communicate()
if plist:
pl = plistlib.readPlistFromString(plist)
pl = FoundationPlist.readPlistFromString(plist)
if "install-location" in pl:
ppath = pl["install-location"]
if "pkg-version" in pl:
+15 -16
View File
@@ -24,7 +24,7 @@ Created by Greg Neagle on 2008-11-13.
#standard libs
import sys
import os
import plistlib
#import plistlib
import tempfile
import subprocess
from distutils import version
@@ -40,6 +40,7 @@ import socket
#our lib
import munkicommon
import munkistatus
import FoundationPlist
def reporterrors():
# just a placeholder right now;
@@ -138,7 +139,7 @@ def getInstalledPackages():
if item.endswith(".pkg"):
infoplist = os.path.join(receiptsdir, item, "Contents/Info.plist")
if os.path.exists(infoplist):
pl = munkicommon.readPlist(infoplist)
pl = FoundationPlist.readPlist(infoplist)
if pl:
pkgid = pl.get('CFBundleIdentifier')
if not pkgid:
@@ -169,7 +170,7 @@ def getInstalledPackages():
(out, err) = p.communicate()
if out:
pl = plistlib.readPlistFromString(out)
pl = FoundationPlist.readPlistFromString(out)
if "pkg-version" in pl:
installedpkgs[pkg] = pl["pkg-version"]
@@ -255,7 +256,7 @@ def getAppData():
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(plist, err) = p.communicate()
if p.returncode == 0:
pl = plistlib.readPlistFromString(plist)
pl = FoundationPlist.readPlistFromString(plist)
# top level is an array instead of a dict, so get dict
spdict = pl[0]
if '_items' in spdict:
@@ -272,7 +273,7 @@ def getAppBundleID(path):
infopath = os.path.join(path, "Contents", "Info.plist")
if os.path.exists(infopath):
try:
pl = munkicommon.readPlist(infopath)
pl = FoundationPlist.readPlist(infopath)
if 'CFBundleIdentifier' in pl:
return pl['CFBundleIdentifier']
except:
@@ -395,7 +396,7 @@ def compareBundleVersion(item):
return 0
try:
pl = munkicommon.readPlist(filepath)
pl = FoundationPlist.readPlist(filepath)
except:
munkicommon.display_debug1("\t%s may not be a plist!" % filepath)
return 0
@@ -431,7 +432,7 @@ def comparePlistVersion(item):
return 0
try:
pl = munkicommon.readPlist(filepath)
pl = FoundationPlist.readPlist(filepath)
except:
munkicommon.display_debug1("\t%s may not be a plist!" % filepath)
return 0
@@ -543,7 +544,7 @@ def getInstalledVersion(pl):
try:
# check default location for app
filepath = os.path.join(install_item['path'], 'Contents', 'Info.plist')
pl = munkicommon.readPlist(filepath)
pl = FoundationPlist.readPlist(filepath)
installedappvers = pl.get('CFBundleShortVersionString')
except:
# that didn't work, fall through to the slow way
@@ -1162,7 +1163,7 @@ def processRemoval(manifestitem, cataloglist, installinfo):
processednamesandaliases = []
for catalogname in cataloglist:
localcatalog = os.path.join(catalogsdir,catalogname)
catalog = plistlib.readPlist(localcatalog)
catalog = FoundationPlist.readPlist(localcatalog)
for item_pl in catalog:
namesandaliases = []
namesandaliases.append(item_pl.get('name'))
@@ -1266,7 +1267,7 @@ def processManifestForRemovals(manifestpath, installinfo):
def getManifestValueForKey(manifestpath, keyname):
try:
pl = munkicommon.readPlist(manifestpath)
pl = FoundationPlist.readPlist(manifestpath)
except:
munkicommon.display_error("Could not read plist %s" % manifestpath)
return None
@@ -1294,9 +1295,7 @@ def getCatalogs(cataloglist):
message = "Retreiving catalog '%s'..." % catalogname
(newcatalog, err) = getHTTPfileIfNewerAtomically(catalogurl, catalogpath, message=message)
if newcatalog:
# can't use munkicommon.readPlist here because it doesn't deal with plists
# that aren't dictionaries. Our catalog plists are arrays.
catalog[catalogname] = makeCatalogDB(plistlib.readPlist(newcatalog))
catalog[catalogname] = makeCatalogDB(FoundationPlist.readPlist(newcatalog))
else:
munkicommon.display_error("Could not retreive catalog %s from server." % catalog)
munkicommon.display_error(err)
@@ -1691,12 +1690,12 @@ def check(id=''):
installinfochanged = True
installinfopath = os.path.join(ManagedInstallDir, "InstallInfo.plist")
if os.path.exists(installinfopath):
oldinstallinfo = munkicommon.readPlist(installinfopath)
oldinstallinfo = FoundationPlist.readPlist(installinfopath)
if oldinstallinfo == installinfo:
installinfochanged = False
munkicommon.display_detail("No change in InstallInfo.")
if installinfochanged:
plistlib.writePlist(installinfo, os.path.join(ManagedInstallDir, "InstallInfo.plist"))
FoundationPlist.writePlist(installinfo, os.path.join(ManagedInstallDir, "InstallInfo.plist"))
else:
# couldn't get a primary manifest. Check to see if we have a valid InstallList from
@@ -1705,7 +1704,7 @@ def check(id=''):
installinfopath = os.path.join(ManagedInstallDir, "InstallInfo.plist")
if os.path.exists(installinfopath):
try:
installinfo = munkicommon.readPlist(installinfopath)
installinfo = FoundationPlist.readPlist(installinfopath)
except:
installinfo = {}