Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / dev / iz / ff2csv.py
blobcb37ac84e8d8a104e57fdd805b5ac277df08ddf8
1 #!/usr/bin/env python
2 # -*- Python -*-
3 """Transform find-fix.py output into Excellable csv."""
5 __date__ = "Time-stamp: <2003-10-16 13:26:27 jrepenning>"[13:30]
6 __author__ = "Jack Repenning <jrepenning@collab.net>"
8 import getopt
9 try:
10 my_getopt = getopt.gnu_getopt
11 except AttributeError:
12 my_getopt = getopt.getopt
13 import inspect
14 import os
15 import os.path
16 import pydoc
17 import re
18 import shutil
19 import string
20 import sys
21 import time
23 # Long options and their usage strings; "=" means it takes an argument.
24 # To get a list suitable for getopt, just do
26 # [x[0] for x in long_opts]
28 # Make sure to sacrifice a lamb to Guido for each element of the list.
29 long_opts = [
30 ["doc", """Optional, print pydocs."""],
31 ["help", """Optional, print usage (this text)."""],
32 ["verbose", """Optional, print more progress messages."""],
35 help = 0
36 verbose = 0
37 me = os.path.basename(sys.argv[0])
39 DATA_FILE = "http://subversion.tigris.org/iz-data/query-set-1.tsv"
41 def main():
42 """Run find-fix.py with arguments du jour for drawing pretty
43 manager-speak pictures."""
45 global verbose
47 try:
48 opts, args = my_getopt(sys.argv[1:], "", [x[0] for x in long_opts])
49 except getopt.GetoptError, e:
50 print "Error: ", e.msg
51 shortusage()
52 print me + " --help for options."
53 sys.exit(1)
55 for opt, arg in opts:
56 if opt == "--help":
57 usage()
58 sys.exit(0)
59 elif opt == "--verbose":
60 verbose = 1
61 elif opt == "--doc":
62 pydoc.doc(pydoc.importfile(sys.argv[0]))
63 sys.exit(0)
65 # do something fruitful with your life
66 if len(args) == 0:
67 args = ["query-set-1.tsv", "core-history.csv"]
68 print ("ff2csv %s %s" % args)
70 if len(args) != 2:
71 print "%s: Wrong number of args." % me
72 shortusage()
73 sys.exit(1)
75 if os.system("curl " + DATA_FILE + "> " + args[0]):
76 os.system("wget " + DATA_FILE)
78 outfile = file(args[1], "w")
79 outfile.write("Date,found,fixed,inval,dup,other,remain\n")
81 totalsre = re.compile("totals:.*found= +([0-9]+) +"
82 "fixed= +([0-9]+) +"
83 "inval= +([0-9]+) +"
84 "dup= +([0-9]+) +"
85 "other= +([0-9]+) +"
86 "remain= *([0-9]+)")
87 for year in ("2001", "2002", "2003", "2004"):
88 for month in ("01", "02", "03", "04", "05", "06", "07", "08",
89 "09", "10", "11", "12"):
90 for dayrange in (("01", "08"),
91 ("08", "15"),
92 ("15", "22"),
93 ("22", "28")):
94 if verbose:
95 print "searching %s-%s-%s to %s" % (year,
96 month,
97 dayrange[0],
98 dayrange[1])
99 ffpy = os.popen("python ./find-fix.py --m=beta "
100 "%s %s-%s-%s %s-%s-%s"
101 % (args[0],
102 year, month, dayrange[0],
103 year, month, dayrange[1]))
104 if verbose:
105 print "ffpy: ", ffpy
107 line = ffpy.readline()
108 if verbose:
109 print "initial line is: ", line
110 matches = totalsre.search(line)
111 if verbose:
112 print "initial match is: ", matches
113 while line and not matches:
114 line = ffpy.readline()
115 if verbose:
116 print "%s: read line '%s'" % (me, line)
117 matches = totalsre.search(line)
118 if verbose:
119 print "subsequent line is: ", line
121 ffpy.close()
123 if verbose:
124 print "line is ", line
126 if matches.group(1) != "0" \
127 or matches.group(2) != "0" \
128 or matches.group(3) != "0" \
129 or matches.group(4) != "0" \
130 or matches.group(5) != "0":
132 outfile.write("%s-%s-%s,%s,%s,%s,%s,%s,%s\n"
133 % (year, month, dayrange[1],
134 matches.group(1),
135 matches.group(2),
136 matches.group(3),
137 matches.group(4),
138 matches.group(5),
139 matches.group(6),
141 elif matches.group(6) != "0":
142 # quit at first nothing-done week
143 # allows slop in loop controls
144 break
145 outfile.close()
148 def shortusage():
149 "Print one-line usage summary."
150 print "%s - %s" % (me, pydoc.synopsis(sys.argv[0]))
152 def usage():
153 "Print multi-line usage tome."
154 shortusage()
155 print '''%s [opts] [queryfile [outfile]]
156 Option keywords may be abbreviated to any unique prefix.
157 Option order is not important.
158 Most options require "=xxx" arguments:''' % me
159 for x in long_opts:
160 padding_limit = 18
161 if x[0][-1:] == '=':
162 print " --" + x[0][:-1],
163 padding_limit = 19
164 else:
165 print " --" + x[0],
166 print (' ' * (padding_limit - len(x[0]))), x[1]
168 if __name__ == "__main__":
169 main()