This is a snapshot of Indico's old Trac site. Any information contained herein is most probably outdated. Access our new GitHub site here.

Ticket #984: setShortURL.py

File setShortURL.py, 1.1 KB (added by ricceri, 4 years ago)

Script for manually set the ShortUrlTag?

Line 
1import getopt, sys
2from MaKaC.common import DBMgr
3from MaKaC.conference import ConferenceHolder
4from MaKaC.common.url import ShortURLMapper
5 
6def usage():
7    print "Usage: %s -i 44 -t tag" % sys.argv[0]
8
9def main():
10    try:
11        opts, args = getopt.getopt(sys.argv[1:], "i:t:", ["id=","tag="])
12    except getopt.GetoptError, err:
13        # print help information and exit:
14        print str(err) # will print something like "option -a not recognized"
15        usage()
16        sys.exit(0)
17    id = None
18    tag = None 
19    for o, a in opts:
20        if o == "-i":
21            id = str(a)
22        elif o == "-t":
23            tag = str(a)
24        else:
25            assert False, "unhandled option"
26 
27    dbi = DBMgr.getInstance()
28    dbi.startRequest()
29
30    if id and tag:
31        ch = ConferenceHolder()
32        conf = ch.getById(id)
33        print "Setting ShortURLTag of %s to %s" % (conf.getTitle(), tag)
34        sum = ShortURLMapper()
35        sum.add(tag,conf)
36    else:
37        usage()
38        sys.exit(0)
39    dbi.endRequest()
40    dbi.commit()
41if __name__ == "__main__":
42    main()