From 232aed6a4c276172d5253273d66264333cc79cec Mon Sep 17 00:00:00 2001 From: Kamil Kisiel Date: Tue, 3 Nov 2009 17:31:32 +0000 Subject: Moved launchd plist cache to __init__ function. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5524 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Tools/launchd.py | 45 ++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/lib/Client/Tools/launchd.py b/src/lib/Client/Tools/launchd.py index bcdb50df8..cd786a7e8 100644 --- a/src/lib/Client/Tools/launchd.py +++ b/src/lib/Client/Tools/launchd.py @@ -5,26 +5,6 @@ import os import Bcfg2.Client.Tools import popen2 -'''Locate plist file that provides given reverse-fqdn name -/Library/LaunchAgents Per-user agents provided by the administrator. -/Library/LaunchDaemons System wide daemons provided by the administrator. -/System/Library/LaunchAgents Mac OS X Per-user agents. -/System/Library/LaunchDaemons Mac OS X System wide daemons.''' -plistLocations = ["/Library/LaunchDaemons", "/System/Library/LaunchDaemons"] -plistMapping = {} -for directory in plistLocations: - for daemon in os.listdir(directory): - try: - if daemon.endswith(".plist"): - d = daemon[:-6] - else: - d = daemon - (stdout, _) = popen2.popen2('defaults read %s/%s Label' % (directory, d)) - label = stdout.read().strip() - plistMapping[label] = "%s/%s" % (directory, daemon) - except KeyError: #perhaps this could be more robust - pass - class launchd(Bcfg2.Client.Tools.Tool): '''Support for Mac OS X Launchd Services''' __handles__ = [('Service', 'launchd')] @@ -36,8 +16,31 @@ class launchd(Bcfg2.Client.Tools.Tool): currently requires the path to the plist to load/unload, and Name is acually a reverse-fqdn (or the label) ''' + def __init__(self, logger, setup, config): + Bcfg2.Client.Tools.Tool.__init__(self, logger, setup, config) + + '''Locate plist file that provides given reverse-fqdn name + /Library/LaunchAgents Per-user agents provided by the administrator. + /Library/LaunchDaemons System wide daemons provided by the administrator. + /System/Library/LaunchAgents Mac OS X Per-user agents. + /System/Library/LaunchDaemons Mac OS X System wide daemons.''' + plistLocations = ["/Library/LaunchDaemons", "/System/Library/LaunchDaemons"] + self.plistMapping = {} + for directory in plistLocations: + for daemon in os.listdir(directory): + try: + if daemon.endswith(".plist"): + d = daemon[:-6] + else: + d = daemon + (stdout, _) = popen2.popen2('defaults read %s/%s Label' % (directory, d)) + label = stdout.read().strip() + self.plistMapping[label] = "%s/%s" % (directory, daemon) + except KeyError: #perhaps this could be more robust + pass + def FindPlist(self, entry): - return plistMapping.get(entry.get('name'), None) + return self.plistMapping.get(entry.get('name'), None) def os_version(self): version = "" -- cgit v1.2.3-1-g7c22