Changeset 5524

Show
Ignore:
Timestamp:
11/03/09 11:31:32 (3 weeks ago)
Author:
kisielk
Message:

Moved launchd plist cache to init function.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/bcfg2/src/lib/Client/Tools/launchd.py

    r5523 r5524  
    55import Bcfg2.Client.Tools 
    66import popen2 
    7  
    8 '''Locate plist file that provides given reverse-fqdn name 
    9 /Library/LaunchAgents          Per-user agents provided by the administrator. 
    10 /Library/LaunchDaemons         System wide daemons provided by the administrator. 
    11 /System/Library/LaunchAgents   Mac OS X Per-user agents. 
    12 /System/Library/LaunchDaemons  Mac OS X System wide daemons.''' 
    13 plistLocations = ["/Library/LaunchDaemons", "/System/Library/LaunchDaemons"] 
    14 plistMapping = {} 
    15 for directory in plistLocations: 
    16     for daemon in os.listdir(directory): 
    17         try: 
    18             if daemon.endswith(".plist"): 
    19                 d = daemon[:-6] 
    20             else: 
    21                 d = daemon 
    22             (stdout, _) = popen2.popen2('defaults read %s/%s Label' % (directory, d)) 
    23             label = stdout.read().strip() 
    24             plistMapping[label] = "%s/%s" % (directory, daemon) 
    25         except KeyError: #perhaps this could be more robust 
    26             pass 
    277 
    288class launchd(Bcfg2.Client.Tools.Tool): 
     
    3717    and Name is acually a reverse-fqdn (or the label) 
    3818    ''' 
     19    def __init__(self, logger, setup, config): 
     20        Bcfg2.Client.Tools.Tool.__init__(self, logger, setup, config) 
     21 
     22        '''Locate plist file that provides given reverse-fqdn name 
     23        /Library/LaunchAgents          Per-user agents provided by the administrator. 
     24        /Library/LaunchDaemons         System wide daemons provided by the administrator. 
     25        /System/Library/LaunchAgents   Mac OS X Per-user agents. 
     26        /System/Library/LaunchDaemons  Mac OS X System wide daemons.''' 
     27        plistLocations = ["/Library/LaunchDaemons", "/System/Library/LaunchDaemons"] 
     28        self.plistMapping = {} 
     29        for directory in plistLocations: 
     30            for daemon in os.listdir(directory): 
     31                try: 
     32                    if daemon.endswith(".plist"): 
     33                        d = daemon[:-6] 
     34                    else: 
     35                        d = daemon 
     36                    (stdout, _) = popen2.popen2('defaults read %s/%s Label' % (directory, d)) 
     37                    label = stdout.read().strip() 
     38                    self.plistMapping[label] = "%s/%s" % (directory, daemon) 
     39                except KeyError: #perhaps this could be more robust 
     40                    pass 
     41 
    3942    def FindPlist(self, entry): 
    40         return plistMapping.get(entry.get('name'), None) 
     43        return self.plistMapping.get(entry.get('name'), None) 
    4144 
    4245    def os_version(self):