Code

Sending of PGP-Encrypted mail to all users or selected users (via roles)
[roundup.git] / tools / migrate-queries.py
1 #! /usr/bin/env python
2 '''
3 migrate-queries <instance-home> [<instance-home> *]
5 Migrate old queries in the specified instances to Roundup 0.6.0+ by
6 removing the leading ? from their URLs. 0.6.0+ queries do not carry a
7 leading ?; it is added by the 0.6.0 templating, so old queries lead
8 to query URLs with a double leading ?? and a consequent 404 Not Found.
9 '''
10 __author__ = 'James Kew <jkew@mediabright.co.uk>'
12 import sys
13 import roundup.instance
15 if len(sys.argv) == 1:
16     print __doc__
17     sys.exit(1)
19 # Iterate over all instance homes specified in argv.
20 for home in sys.argv[1:]:
21     # Do some basic exception handling to catch bad arguments.
22     try:
23         instance = roundup.instance.open(home)
24     except:
25         print 'Cannot open instance home directory %s!' % home
26         continue
28     db = instance.open('admin')
30     print 'Migrating active queries in %s (%s):'%(
31         instance.config.TRACKER_NAME, home)
32     for query in db.query.list():
33         url = db.query.get(query, 'url')
34         if url[0] == '?':
35             url = url[1:]
36             print '  Migrating query%s (%s)'%(query,
37                 db.query.get(query, 'name'))
38             db.query.set(query, url=url)
40     db.commit()
41     db.close()