import repository from arizona
[raven.git] / apps / gacks / gacksadmin.py
1 from gackscalendar_mysql import *
2
3 def init_database():
4    global db
5    db = GacksMySQLCalendar();
6
7 def create_parser():
8    # Generate command line parser
9    parser = OptionParser(usage="gacksadmin [options] command [command_options] [command_args]",
10         description="Commands: reset purgeold",
11         version="gackscli ??")
12
13    parser.disable_interspersed_args()
14
15    return parser
16
17 def create_cmd_parser(command):
18    cmdargs = {"reset": "",
19               "purgeold": ""}
20
21    if command not in cmdargs:
22       print "Invalid command\n"
23       print "Commands: ",
24       for key in cmdargs.keys():
25           print key+",",
26       print ""
27       sys.exit(2)
28
29    parser = OptionParser(usage="gackscli [raven_options] %s [options] %s" \
30       % (command, cmdargs[command]))
31
32    return parser
33
34 def main():
35    global db
36
37    parser = create_parser()
38    (options, args) = parser.parse_args()
39
40    if len(args) <= 0:
41        print "No command given. Use -h for help."
42        return -1
43
44    command = args[0]
45    (cmd_opts, cmd_args) = create_cmd_parser(command).parse_args(args[1:])
46
47    init_database();
48
49    if command == "reset":
50        db.reset()
51    elif command == "purge":
52        db.purge_old()
53
54 if __name__=="__main__":
55    main()