def list(self, labelmatch="*"):
'''
run "launchctl list" and return list of jobs that match the shell-
style wildcard <labelmatch>
since all jobs have our app-specific prefix, and have their
run time appended to their names, caller should terminate
<labelmatch> with ".*" unless they already have an exact name.
'''
results = []
try:
output = subprocess.check_output(["sudo", "launchctl", "list"])
for line in output.split("\n"):
if len(line) == 0:
break
fields= line.split(None,3)
if len(fields) < 3:
self.bomb("unexpected output from 'sudo launchctl list: %s'" % line)
job= fields[2]
if fnmatch(job, self.prefix + labelmatch):
results.append(job[len(self.prefix):])
except (subprocess.CalledProcessError) as error:
self.bomb("running 'sudo launchctl list'", error)
return results
评论列表
文章目录