83
by Martin Pitt
add json-report |
1 |
#!/usr/bin/python
|
2 |
#
|
|
3 |
# Create a JSON report from a work item database. The structure is the one
|
|
4 |
# returned by report_tools.assignee_completion()
|
|
5 |
||
144
by Colin Watson
fix pyflakes unhappiness (trailing whitespace, unused imports) |
6 |
import optparse, simplejson |
83
by Martin Pitt
add json-report |
7 |
|
8 |
import report_tools |
|
9 |
||
10 |
#
|
|
11 |
# main
|
|
12 |
#
|
|
13 |
||
14 |
if __name__ == '__main__': |
|
15 |
report_tools.fix_stdouterr() |
|
16 |
||
17 |
# argv parsing
|
|
18 |
optparser = optparse.OptionParser() |
|
19 |
optparser.add_option('-d', '--database', |
|
20 |
help='Path to database', dest='database', metavar='PATH') |
|
21 |
optparser.add_option('-t', '--team', |
|
22 |
help='Restrict report to a particular team', dest='team') |
|
23 |
optparser.add_option('-m', '--milestone', |
|
24 |
help='Restrict report to a particular milestone', dest='milestone') |
|
121
by Jos Boumans
* XXX incompatible change! |
25 |
optparser.add_option('-c', '--config', |
26 |
help='Path to configuration file (if given, this can read adjusted trend lines start values)', |
|
27 |
dest='config', metavar='PATH') |
|
205.1.8
by Clint Byrum
only show user direct assigned items on personal page |
28 |
optparser.add_option('-u', '--user', |
29 |
help='Run for this user', dest='user') |
|
83
by Martin Pitt
add json-report |
30 |
|
31 |
(opts, args) = optparser.parse_args() |
|
32 |
if not opts.database: |
|
33 |
optparser.error('No database given') |
|
292
by Mattias Backman
Re-apply the Storm changes. |
34 |
store = report_tools.get_store(opts.database) |
83
by Martin Pitt
add json-report |
35 |
|
205.1.8
by Clint Byrum
only show user direct assigned items on personal page |
36 |
if opts.user and opts.team: |
37 |
optparser.error('team and user options are mutually exclusive') |
|
38 |
||
39 |
# The typing allows polymorphic behavior
|
|
40 |
if opts.user: |
|
41 |
opts.team = report_tools.user_string(opts.user) |
|
42 |
elif opts.team: |
|
43 |
opts.team = report_tools.team_string(opts.team) |
|
44 |
||
121
by Jos Boumans
* XXX incompatible change! |
45 |
if opts.config: |
46 |
config = report_tools.load_config(opts.config) |
|
144
by Colin Watson
fix pyflakes unhappiness (trailing whitespace, unused imports) |
47 |
else: |
121
by Jos Boumans
* XXX incompatible change! |
48 |
config = {} |
49 |
||
50 |
json = {} |
|
144
by Colin Watson
fix pyflakes unhappiness (trailing whitespace, unused imports) |
51 |
|
121
by Jos Boumans
* XXX incompatible change! |
52 |
# original WI dump
|
53 |
json["workitems_by_assignee"] = report_tools.assignee_completion( |
|
292
by Mattias Backman
Re-apply the Storm changes. |
54 |
store, opts.team, opts.milestone) |
121
by Jos Boumans
* XXX incompatible change! |
55 |
|
56 |
# blueprint data
|
|
57 |
json["specs"] = report_tools.spec_information( |
|
292
by Mattias Backman
Re-apply the Storm changes. |
58 |
store, config, opts.team, opts.milestone) |
144
by Colin Watson
fix pyflakes unhappiness (trailing whitespace, unused imports) |
59 |
|
121
by Jos Boumans
* XXX incompatible change! |
60 |
# team data
|
292
by Mattias Backman
Re-apply the Storm changes. |
61 |
json["teams"] = report_tools.team_information(store, opts.team ) |
121
by Jos Boumans
* XXX incompatible change! |
62 |
|
63 |
print simplejson.dumps(json, indent=2, sort_keys=True) |