88
99
1010class LaunchdJob (object ):
11- '''
12- Custom class that allows us to lazily query the properties
13- of the LaunchdJob when accessed.
14- '''
15- def __init__ (self , label , pid = - 1 , laststatus = '' ):
16- '''
11+ """
12+ Class to lazily query the properties of the LaunchdJob when accessed.
13+ """
14+ def __init__ (self , label , pid = - 1 , laststatus = "" ):
15+ """
1716 Instantiate a LaunchdJob instance. Only the label is required.
1817 If no pid or laststatus are specified, they will be queried when
1918 accessed.
2019
2120 :param label: required string job label
2221 :param pid: optional int, if known. Can be None.
2322 :param laststatus: optional int, if known. Can be None.
24- '''
23+ """
2524 self ._label = label
2625 if pid != - 1 : # -1 indicates no value specified
2726 self ._pid = pid
28- if laststatus != '' :
27+ if laststatus != "" :
2928 self ._laststatus = laststatus
3029 self ._properties = None
3130 self ._plist_fname = None
@@ -53,15 +52,15 @@ def laststatus(self):
5352
5453 @property
5554 def properties (self ):
56- '''
57- This is a lazily loaded dictionary containing the launchd runtime
58- information of the job in question. Internally, this is retrieved
59- using ServiceManagement.SMJobCopyDictionary(). Keep in mind that
60- some dictionary keys are not always present (for example 'PID').
55+ """
56+ Lazily load dictionary with launchd runtime information.
57+
58+ Internally, this is retrieved using ServiceManagement.SMJobCopyDictionary().
59+ Keep in mind that some dictionary keys are not always present (for example 'PID').
6160 If the job specified by the label cannot be found in launchd, then
6261 this method raises a ValueError exception.
63- '''
64- if hasattr (self , ' _nsproperties' ):
62+ """
63+ if hasattr (self , " _nsproperties" ):
6564 self ._properties = convert_NSDictionary_to_dict (self ._nsproperties )
6665 del self ._nsproperties
6766 # self._nsproperties = None
@@ -80,36 +79,37 @@ def refresh(self):
8079 self ._properties = convert_NSDictionary_to_dict (val )
8180 # update pid and laststatus attributes
8281 try :
83- self ._pid = self ._properties [' PID' ]
82+ self ._pid = self ._properties [" PID" ]
8483 except KeyError :
8584 self ._pid = None
8685 try :
87- self ._laststatus = self ._properties [' LastExitStatus' ]
86+ self ._laststatus = self ._properties [" LastExitStatus" ]
8887 except KeyError :
8988 self ._laststatus = None
9089
9190 @property
9291 def plistfilename (self ):
93- '''
94- This is a lazily detected absolute filename of the corresponding
95- property list file (*.plist). None if it doesn't exist.
96- '''
92+ """
93+ Lazily detect absolute filename of the property list file.
94+
95+ Return None if it doesn't exist.
96+ """
9797 if self ._plist_fname is None :
9898 self ._plist_fname = discover_filename (self .label )
9999 return self ._plist_fname
100100
101101
102102def jobs ():
103103 for entry in ServiceManagement .SMCopyAllJobDictionaries (None ):
104- label = entry [' Label' ]
104+ label = entry [" Label" ]
105105 if label .startswith ("0x" ):
106106 continue
107107 try :
108- pid = int (entry [' PID' ])
108+ pid = int (entry [" PID" ])
109109 except KeyError :
110110 pid = None
111111 try :
112- laststatus = int (entry [' LastExitStatus' ])
112+ laststatus = int (entry [" LastExitStatus" ])
113113 except KeyError :
114114 laststatus = None
115115 job = LaunchdJob (label , pid , laststatus )
0 commit comments