edgimar avatar edgimar committed e2cc2d4

- allow --pull to a specified file instead of stdout.

When using the --pull flag, if --orgfile is specified, then the output is
written directly to the specified file. Otherwise, it is printed to stdout.

Comments (0)

Files changed (1)

     """
     tasks_tree = get_gtask_list_as_tasktree(list_name)
     print(tasks_tree)
+    
+def write_todolist(orgfile_path, list_name=None):
+    """Create an orgmode-formatted file 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)
+    f = open(orgfile_path, 'wb')
+    f.write(str(tasks_tree))
+    f.close()
 
 def erase_todolist(list_id):
     """Erases the todo list of given id"""
     action.add_argument("--push", action='store_true',
             help='replace *gtasks_list_name* with the contents of *org_file*.')
     action.add_argument("--pull", action='store_true',
-            help='prints the contents of *gtasks_list_name* to stdout in org-mode format.')
+            help='replace *org_file* with the contents of *gtasks_list_name*.')
     
     parser.add_argument('--orgfile',
             metavar='FILE',
         parser.error('--orgfile must be specified when using --push')
     
     if args.pull:
-        print_todolist(args.listname)
+        if args.orgfile is None:
+            print_todolist(args.listname)
+        else:
+            write_todolist(args.orgfile, args.listname)
     elif args.push:
         if not os.path.exists(args.orgfile):
             print("The org-file you want to push does not exist.")
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.