1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 from __future__ import print_function
28 import os, sys, re, MySQLdb
29
30 dirNm, execName = os.path.split(os.path.realpath(sys.argv[0]))
31 sys.path.append(os.path.realpath(os.path.join(dirNm, "../libexec")))
32
33 from XALTdb import XALTdb
34 from xalt_util import dbConfigFn
35 import argparse
37 """ Command line Options class """
38
40 """ Empty Ctor """
41 pass
42
44 """ Specify command line arguments and parse the command line"""
45 parser = argparse.ArgumentParser()
46 parser.add_argument("--dbname", dest='dbname', action="store", default = "xalt", help="xalt")
47 args = parser.parse_args()
48 return args
49
51 """
52 This program removes the Database used by XALT.
53 """
54
55 args = CmdLineOptions().execute()
56 configFn = dbConfigFn(args.dbname)
57
58 if (not os.path.isfile(configFn)):
59 dirNm, exe = os.path.split(sys.argv[0])
60 fn = os.path.join(dirNm, configFn)
61 if (os.path.isfile(fn)):
62 configFn = fn
63 else:
64 configFn = os.path.abspath(os.path.join(dirNm, "../site", configFn))
65
66 xalt = XALTdb(configFn)
67 db = xalt.db()
68
69 try:
70 conn = xalt.connect()
71 cursor = conn.cursor()
72
73
74 cursor.execute("SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"")
75
76 cursor.execute("DROP DATABASE IF EXISTS %s " % xalt.db())
77
78 cursor.close()
79 except MySQLdb.Error, e:
80 print ("Error %d: %s" % (e.args[0], e.args[1]))
81 sys.exit (1)
82
83 if ( __name__ == '__main__'): main()
84