edgimar avatar edgimar committed c3553a9

- rename TaskTree.get() -> TaskTree.get_task_with_id()
- bugfix: "if not x" fails for x being a len=0 TaskTree object; replaced with
"if x is None".
- pull gtask-list -> tasktree functionality out of print_todolist() into its
own function (get_gtask_list_as_tasktree)

Comments (0)

Files changed (1)

     def __getitem__(self, key):
         return self.subtasks[key]
     def __setitem__(self, key, val):
         self.subtasks[key] = val
     def __len__(self):
         return len(self.subtasks)
-    def get(self, task_id):
+    def get_task_with_id(self, task_id):
         """Returns the task of given id"""
         if self.task_id == task_id:
             return self
+            # depth first search for id
             for subtask in self.subtasks:
-                if subtask.get(task_id) != None:
-                    return subtask.get(task_id)
+                if subtask.get_task_with_id(task_id) is not None:
+                    return subtask.get_task_with_id(task_id)
+            # if there are no subtasks to search
+            return None
     def add_subtask(self, title, task_id = None, parent_id = None,
             task_notes=None, task_status=None):
         - with the specified task_id
         - as a child of parent_id
-        if not parent_id:
-            self.subtasks.append(TasksTree(title, task_id, task_notes, task_status))
+        if parent_id is None:
+            self.subtasks.append(
+                TasksTree(title, task_id, task_notes, task_status))
-            if not self.get(parent_id):
+            if self.get_task_with_id(parent_id) is None:
                 raise ValueError, "No element with suitable parent id"
-            self.get(parent_id).add_subtask(title, task_id, None, task_notes,
-                    task_status)
+            self.get_task_with_id(parent_id).add_subtask(title, task_id, None,
+                    task_notes, task_status)
     def add_subtree(self, tree_to_add, include_root=False, root_title=None,
     return list_id
-def print_todolist(list_name=None):
-    """Prints the todo list of given id"""
+def get_gtask_list_as_tasktree(list_name=None):
+    """Get a TaskTree object representing a google tasks list.
+    The Google Tasks list named *list_name* is retrieved, and converted into a
+    TaskTree object which is returned.  If *list_name* is not specified, then
+    the default Google-Tasks list will be used.
+    """
     service = get_service()
     list_id = get_list_id(service, list_name)
     tasks = service.tasks().list(tasklist=list_id).execute()
         except ValueError:
             fail_count += 1
+    return tasks_tree
+def print_todolist(list_name=None):
+    """Print an orgmode-formatted string representing a google tasks list.
+    The Google Tasks list named *list_name* is used.  If *list_name* is not
+    specified, then the default Google-Tasks list will be used.
+    """
+    tasks_tree = get_gtask_list_as_tasktree(list_name)
 def erase_todolist(list_id):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.