| 1 | import getopt, sys |
|---|
| 2 | from MaKaC.common import DBMgr |
|---|
| 3 | from MaKaC.conference import ConferenceHolder |
|---|
| 4 | from MaKaC.common.url import ShortURLMapper |
|---|
| 5 | |
|---|
| 6 | def usage(): |
|---|
| 7 | print "Usage: %s -i 44 -t tag" % sys.argv[0] |
|---|
| 8 | |
|---|
| 9 | def 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() |
|---|
| 41 | if __name__ == "__main__": |
|---|
| 42 | main() |
|---|