|
a/migrate-3rdparty/trac_export.py |
|
b/migrate-3rdparty/trac_export.py |
|
... |
|
... |
21 |
optparser = OptionParser(usage=''' %prog <Trac URL>
|
21 |
optparser = OptionParser(usage=''' %prog <Trac URL>
|
22 |
|
22 |
|
23 |
Export ticket data from a Trac instance''')
|
23 |
Export ticket data from a Trac instance''')
|
24 |
optparser.add_option('-o', '--out-file', dest='out_filename', help='Write to file (default stdout)')
|
24 |
optparser.add_option('-o', '--out-file', dest='out_filename', help='Write to file (default stdout)')
|
25 |
optparser.add_option('--attachments', dest='do_attachments', action='store_true', help='Export attachment info')
|
25 |
optparser.add_option('--attachments', dest='do_attachments', action='store_true', help='Export attachment info')
|
|
|
26 |
optparser.add_option('--only-tickets', dest='only_tickets', action='store_true', help='Export only ticket list')
|
26 |
optparser.add_option('--start', dest='start_id', type='int', default=1, help='Start with given ticket numer (or next accessible)')
|
27 |
optparser.add_option('--start', dest='start_id', type='int', default=1, help='Start with given ticket numer (or next accessible)')
|
27 |
optparser.add_option('--limit', dest='limit', type='int', default=None, help='Limit number of tickets')
|
28 |
optparser.add_option('--limit', dest='limit', type='int', default=None, help='Limit number of tickets')
|
28 |
optparser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose operation')
|
29 |
optparser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose operation')
|
29 |
options, args = optparser.parse_args()
|
30 |
options, args = optparser.parse_args()
|
30 |
if len(args) != 1:
|
31 |
if len(args) != 1:
|
|
... |
|
... |
223 |
return json.JSONEncoder.default(self, obj)
|
224 |
return json.JSONEncoder.default(self, obj)
|
224 |
|
225 |
|
225 |
if __name__ == '__main__':
|
226 |
if __name__ == '__main__':
|
226 |
options, args = parse_options()
|
227 |
options, args = parse_options()
|
227 |
ex = TracExport(args[0], start_id=options.start_id)
|
228 |
ex = TracExport(args[0], start_id=options.start_id)
|
|
|
229 |
# Implement iterator sequence limiting using islice()
|
228 |
doc = [t for t in islice(ex, options.limit)]
|
230 |
doc = [t for t in islice(ex, options.limit)]
|
|
|
231 |
|
|
|
232 |
if not options.only_tickets:
|
|
|
233 |
doc = {
|
|
|
234 |
'class': 'PROJECT',
|
|
|
235 |
'trackers': {'default': {'artifacts': doc}}
|
|
|
236 |
}
|
|
|
237 |
|
229 |
out_file = sys.stdout
|
238 |
out_file = sys.stdout
|
230 |
if options.out_filename:
|
239 |
if options.out_filename:
|
231 |
out_file = open(options.out_filename, 'w')
|
240 |
out_file = open(options.out_filename, 'w')
|
232 |
out_file.write(json.dumps(doc, cls=DateJSONEncoder, indent=2, sort_keys=True))
|
241 |
out_file.write(json.dumps(doc, cls=DateJSONEncoder, indent=2, sort_keys=True))
|
233 |
# It's bad habit not to terminate lines
|
242 |
# It's bad habit not to terminate lines
|