GTG

Merge lp:~bryce/gtg/anon-noargs into lp:~gtg/gtg/old-trunk

Proposed by Bryce Harrington
Status: Merged
Merged at revision: 857
Proposed branch: lp:~bryce/gtg/anon-noargs
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: 70 lines (+38/-8)
1 file modified
scripts/anonymize_task_file.py (+38/-8)
To merge this branch: bzr merge lp:~bryce/gtg/anon-noargs
Reviewer Review Type Date Requested Status
Marko Kevac Pending
Gtg developers Pending
Review via email: mp+29696@code.launchpad.net

Description of the change

This makes the anon tasks script use reasonable defaults when run with no args.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/anonymize_task_file.py'
2--- scripts/anonymize_task_file.py 2010-06-11 14:50:21 +0000
3+++ scripts/anonymize_task_file.py 2010-07-12 13:12:39 +0000
4@@ -1,5 +1,5 @@
5 #!/usr/bin/env python
6-# -*- coding: UTF-8 -*-
7+### -*- coding: utf-8 -*-
8 # Copyright © 2010 Marko Kevac <marko@kevac.org>
9 #
10 # This program is free software: you can redistribute it and/or modify
11@@ -15,8 +15,10 @@
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15+import os
16 import sys
17 from xml.dom.minidom import parse
18+from xdg.BaseDirectory import xdg_data_home
19
20 def anonymize(filename, outputfile):
21
22@@ -64,14 +66,42 @@
23 except Exception, err:
24 print "error while saving output file: %s" % err
25
26+def usage():
27+ print "Usage: %s [taskfile] [outputfile]" % sys.argv[0]
28+ print
29+ print "Removes private data from specified taskfile, or your"
30+ print "default gtg tasks file if unspecified. Writes output"
31+ print "to /tmp/gtg-tasks.xml by default, or to specified"
32+ print "outputfile if provided."
33+ sys.exit(1)
34+
35 def main():
36- if len(sys.argv) != 3:
37- print "Remove private data from your tasks file."
38- print "Usage: %s <taskfile> <outputfile>" % sys.argv[0]
39- sys.exit(1)
40-
41- xmlfile = sys.argv[1]
42- outputfile = sys.argv[2]
43+ #if len(sys.argv) != 3:
44+ # usage()
45+
46+ if len(sys.argv) > 1:
47+ xmlfile = sys.argv[1]
48+ else:
49+ try:
50+ # Or use CoreConfig().get_data_dir() . CoreConfig.???
51+ # which needs 'from GTG.core import import CoreConfig'
52+ data_dir = os.path.join(xdg_data_home, "gtg")
53+ project_filepath = os.path.join(data_dir, "projects.xml")
54+ dom = parse(project_filepath)
55+ xmlproject = dom.getElementsByTagName("backend")[0]
56+ xmlfile = str(xmlproject.getAttribute("path"))
57+
58+ print "Reading tasks from %s" %(xmlfile)
59+ except:
60+ print
61+ usage()
62+
63+ if len(sys.argv) > 2:
64+ outputfile = sys.argv[2]
65+ else:
66+ # Use a reasonable default, and write out where it's sent
67+ outputfile = "/tmp/gtg-tasks.xml"
68+ print "Saving anonymized tasks to %s" %(outputfile)
69
70 anonymize(xmlfile, outputfile)
71

Subscribers

People subscribed via source and target branches

to status/vote changes: