Module removeDataBase
[hide private]
[frames] | no frames]

Source Code for Module removeDataBase

 1  #!/usr/bin/env python 
 2  # -*- python -*- 
 3  # 
 4  # Git Version: @git@ 
 5   
 6  #----------------------------------------------------------------------- 
 7  # XALT: A tool that tracks users jobs and environments on a cluster. 
 8  # Copyright (C) 2013-2014 University of Texas at Austin 
 9  # Copyright (C) 2013-2014 University of Tennessee 
10  #  
11  # This library is free software; you can redistribute it and/or modify 
12  # it under the terms of the GNU Lesser General Public License as 
13  # published by the Free Software Foundation; either version 2.1 of  
14  # the License, or (at your option) any later version.  
15  # 
16  # This library is distributed in the hope that it will be useful, 
17  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
18  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
19  # Lesser  General Public License for more details.  
20  # 
21  # You should have received a copy of the GNU Lesser General Public 
22  # License along with this library; if not, write to the Free 
23  # Software Foundation, Inc., 59 Temple Place, Suite 330, 
24  # Boston, MA 02111-1307 USA 
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 
36 -class CmdLineOptions(object):
37 """ Command line Options class """ 38
39 - def __init__(self):
40 """ Empty Ctor """ 41 pass
42
43 - def execute(self):
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
50 -def main():
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 # If MySQL version < 4.1, comment out the line below 74 cursor.execute("SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\"") 75 # If the database does not exist, create it, otherwise, switch to the database. 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