Browse Source

getTasksMatching

David Rose 17 years ago
parent
commit
907c9541a9
2 changed files with 24 additions and 0 deletions
  1. 7 0
      direct/src/task/TaskNew.py
  2. 17 0
      direct/src/task/TaskOrig.py

+ 7 - 0
direct/src/task/TaskNew.py

@@ -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. """

+ 17 - 0
direct/src/task/TaskOrig.py

@@ -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