getTasksMatching

This commit is contained in:
David Rose 2008-10-29 15:24:08 +00:00
parent 2e7751678f
commit 907c9541a9
2 changed files with 24 additions and 0 deletions

View File

@ -222,6 +222,13 @@ class TaskManager:
indicated name. """
return self.__makeTaskList(self.mgr.findTasks(taskName))
def getTasksMatching(self, taskPattern):
"""Returns a list of all tasks, active or sleeping, with a
name that matches the pattern, which can include standard
shell globbing characters like *, ?, and []. """
return self.__makeTaskList(self.mgr.findTasksMatching(GlobPattern(taskPattern)))
def getAllTasks(self):
"""Returns list of all tasks, active and sleeping, in
arbitrary order. """

View File

@ -536,6 +536,23 @@ class TaskManager:
return [task for task in self.nameDict.get(taskName, []) #grab all tasks with name
if not task._removed] #filter removed tasks
def getTasksMatching(self, taskPattern):
"""getTasksMatching(self, string taskPattern)
Returns tasks whose names match the pattern, which can include
standard shell globbing characters like *, ?, and [].
"""
keyList = filter(
lambda key: fnmatch.fnmatchcase(key, taskPattern),
self.nameDict.keys())
result = []
for key in keyList:
for task in self.nameDict.get(key, []):
if not task._removed:
result.append(task)
return result
def __doLaterFilter(self):
# Filter out all the tasks that have been removed like a mark and
# sweep garbage collector. Returns the number of tasks that have