本文整理汇总了Python中munkilib.FoundationPlist类的典型用法代码示例。如果您正苦于以下问题:Python FoundationPlist类的具体用法?Python FoundationPlist怎么用?Python FoundationPlist使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FoundationPlist类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
filevault = fv_status()
mac_ver = mac_version()
if LooseVersion("10.11") <= LooseVersion(mac_ver):
sip = sip_status()
else:
sip = 'Not Supported'
# Yes, I know it came in 10.7.5, but eh. I don't care, I'm lazy
if LooseVersion("10.8") <= LooseVersion(mac_ver):
gatekeeper = gatekeeper_status()
else:
gatekeeper = 'Not Supported'
plist_path = '/usr/local/sal/plugin_results.plist'
if os.path.exists(plist_path):
plist = FoundationPlist.readPlist(plist_path)
else:
plist = []
result = {}
result['plugin'] = 'MachineDetailSecurity'
result['historical'] = True
data = {}
data['Filevault'] = filevault
data['SIP'] = sip
data['Gatekeeper'] = gatekeeper
result['data'] = data
plist.append(result)
FoundationPlist.writePlist(plist, plist_path)
示例2: checkForOSXFlashbackk
def checkForOSXFlashbackk():
# Checks Various browsers for the malware
browsersToCheck = ["Firefox.app", "Safari.app", "Opera.app", "Google Chrome.app" "Camino.app", "Stainless.app", "OmniWebb.app", "Fluid.app"]
userFilestoCheck = ["Library/LaunchAgents/com.sun.jsched.plist", ".jsched"]
applicationsDirectory = "/Applications"
plistLocation = "Contents/Info.plist"
for browser in browsersToCheck:
fullPathToPlist = (os.path.join(applicationsDirectory, browser, plistLocation))
if os.path.exists(fullPathToPlist):
loadedPlist = FoundationPlist.readPlist(fullPathToPlist)
malwareKey = loadedPlist.get("LSEnvironment", "")
if malwareKey:
return True
# Check for malware in shared folder
if os.path.exists("/Users/Shared/.libgmalloc.dylib"):
return True
# Check for malware in each user's folder
for user in os.listdir("/Users/"):
if not user.startswith('.'):
fullPathToEnvPlist = (os.path.join("/Users", user, ".MacOSX", "environment.plist"))
if os.path.exists(fullPathToEnvPlist):
loadedPlist = FoundationPlist.readPlist(fullPathToEnvPlist)
DYLDkey = loadedPlist.get("DYLD_INSERT_LIBRARIES", "")
if DYLDkey:
return True
for fileToCheck in userFilestoCheck:
if os.path.exists((os.path.join("/Users", user, fileToCheck))):
print os.path.join("/Users", user, fileToCheck)
return True
return False
示例3: get_munkiimport_prefs
def get_munkiimport_prefs():
"""Get the current user's munkiimport preferences as plist dict."""
try:
prefs = FoundationPlist.readPlist(MUNKIIMPORT_PREFS)
except NSPropertyListSerializationException:
prefs = {}
return prefs
示例4: build_pkginfo_cache_with_errors
def build_pkginfo_cache_with_errors(repo):
"""Build a dictionary of pkgsinfo.
Args:
repo: String path to the base of a Munki repo.
Returns:
Tuple of:
Dictionary of pkgsinfo with:
key: path to pkginfo.
val: pkginfo dictionary.
Dictionary of errors with:
key: path to pkginfo.
val: Exception message.
"""
pkginfos = {}
errors = {}
pkginfo_dir = os.path.join(repo, "pkgsinfo")
for dirpath, _, filenames in os.walk(pkginfo_dir):
for ifile in filter(is_pkginfo, filenames):
path = os.path.join(dirpath, ifile)
try:
pkginfo_file = FoundationPlist.readPlist(path)
except FoundationPlist.FoundationPlistException as error:
errors[path] = error.message
continue
pkginfos[path] = pkginfo_file
return (pkginfos, errors)
示例5: main
def main():
uptime_seconds = get_uptime()
plist_path = '/usr/local/sal/plugin_results.plist'
if os.path.exists(plist_path):
plist = FoundationPlist.readPlist(plist_path)
else:
plist = []
result = {}
result['plugin'] = 'Uptime'
result['historical'] = False
data = {}
data['UptimeDays'] = uptime_seconds / 60 / 60 / 24
data['UptimeSeconds'] = uptime_seconds
result['data'] = data
plist.append(result)
FoundationPlist.writePlist(plist, plist_path)
示例6: pref
def pref(prefname):
"""Returns a preference for prefname"""
try:
_prefs = FoundationPlist.readPlist(PREFSPATH)
except Exception:
return None
if prefname in _prefs:
return _prefs[prefname]
else:
return None
示例7: main
def main():
plist_path = (
'/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist')
if os.path.exists(plist_path):
plist = FoundationPlist.readPlist(plist_path)
version = str(plist['Version'])
else:
version = 'Not supported'
add_plugin_results('XprotectVersion', {'Version': version})
示例8: build_prefs
def build_prefs():
# If munkiimport prefs exist, offer them as defaults.
munkiimport_prefs = get_munkiimport_prefs()
keys = ("repo_path", "repo_url")
prefs = {}
print ("No preference file was found for Spruce. Please allow me to "
"break it down for you.")
for key in keys:
choice = None
while choice is None:
default = munkiimport_prefs.get(key, "")
choice = raw_input(
"Please enter a value for '{}' or hit enter to use the "
"default value '{}': ".format(key, default))
prefs[key] = choice if choice else default
FoundationPlist.writePlist(prefs, SPRUCE_PREFS)
return prefs
示例9: get_prefs
def get_prefs():
# If prefs don't exist yet, offer to help create them.
try:
prefs = FoundationPlist.readPlist(SPRUCE_PREFS)
except FoundationPlist.NSPropertyListSerializationException:
prefs = None
if not prefs or not prefs.get("repo_path"):
prefs = build_prefs()
return prefs
示例10: add_plugin_results
def add_plugin_results(plugin, data, historical=False):
"""Add data to the shared plugin results plist.
This function creates the shared results plist file if it does not
already exist; otherwise, it adds the entry by appending.
Args:
plugin (str): Name of the plugin returning data.
data (dict): Dictionary of results.
historical (bool): Whether to keep only one record (False) or
all results (True). Optional, defaults to False.
"""
plist_path = '/usr/local/sal/plugin_results.plist'
if os.path.exists(plist_path):
plugin_results = FoundationPlist.readPlist(plist_path)
else:
plugin_results = []
plugin_results.append({'plugin': plugin, 'historical': historical, 'data': data})
FoundationPlist.writePlist(plugin_results, plist_path)
示例11: getBundleInfo
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
示例12: GetAppleSUSCatalog
def GetAppleSUSCatalog():
"""Fetches an Apple Software Update Service catalog from the server."""
url = GetServerURL()
try:
new = updatecheck.getResourceIfChangedAtomically(
'%s/applesus/' % url, APPLE_SUS_CATALOG)
except fetch.MunkiDownloadError:
logging.exception('MunkiDownloadError getting Apple SUS catalog.')
return
if new:
# SUS catalog changed, clear last check date to run softwareupdate soon.
munkicommon.set_pref('LastAppleSoftwareUpdateCheck', None)
try:
sus_catalog = fpl.readPlist(APPLE_SUS_PLIST)
except fpl.NSPropertyListSerializationException:
# plist may not exist, but will be created when softwareupdate is run, then
# the next execution of of this code will set the CatalogURL.
logging.exception('Failed to read Apple SoftwareUpdate plist.')
return
# Update the CatalogURL setting in com.apple.SoftwareUpdate.plist.
sus_catalog['CatalogURL'] = urlparse.urljoin(
'file://localhost/', urllib.quote(APPLE_SUS_CATALOG))
fpl.writePlist(sus_catalog, APPLE_SUS_PLIST)
示例13: GetAppleSUSCatalog
def GetAppleSUSCatalog():
"""Fetches an Apple Software Update Service catalog from the server."""
url = GetServerURL()
try:
updatecheck.getResourceIfChangedAtomically(
'%s/applesus/' % url, APPLE_SUS_CATALOG)
# Update the CatalogURL setting in com.apple.SoftwareUpdate.plist.
sus_catalog = fpl.readPlist(APPLE_SUS_PLIST)
sus_catalog['CatalogURL'] = urlparse.urljoin(
'file://localhost/', urllib.quote(APPLE_SUS_CATALOG))
fpl.writePlist(sus_catalog, APPLE_SUS_PLIST)
except (fetch.MunkiDownloadError, fpl.NSPropertyListSerializationException):
logging.exception('MunkiDownloadError getting Apple SUS catalog.')
示例14: GetPlistValue
def GetPlistValue(key, secure=False, plist=None):
"""Returns the value of a given plist key.
Args:
key: string key to get from the plist.
secure: boolean; True = munki secure plist, False = munki regular plist.
plist: optional, str plist path to use, instead of Munki plist.
Note, if plist is supplied, secure boolean is ignored.
Returns:
string value, or empty string if the key doesn't exist.
"""
if not plist:
if secure:
plist = DEFAULT_SECURE_MANAGED_INSTALLS_PLIST_PATH
else:
plist = DEFAULT_MANAGED_INSTALLS_PLIST_PATH
if OBJC_OK:
pl = fpl.readPlist(plist)
return pl.get(key, '')
# get XML output of (potential) binary plist from plutil.
exit_code, plist_xml, unused_err = Exec(
['/usr/bin/plutil', '-convert', 'xml1', '-o', '-', plist])
if exit_code:
logging.error('Failed to convert plist to xml1: %s', plist)
return ''
plist_contents = plistlib.readPlistFromString(plist_xml)
return plist_contents.get(key, '')
示例15: get_pkgid_version
def get_pkgid_version(this_pkg_plist, this_pkg_id):
if this_pkg_id in this_pkg_plist:
cmd = [pkgutil_path, "--pkg-info-plist", this_pkg_id]
cmd_output = subprocess.check_output(cmd)
cmd_output_plist = plistlib.readPlistFromString(cmd_output)
pkg_version = cmd_output_plist['pkg-version']
return pkg_version
else:
return False