source: TI12-security/trunk/python/bin/initCredReposDb.py @ 1116

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/bin/initCredReposDb.py@1116
Revision 1116, 1.9 KB checked in by pjkersha, 13 years ago (diff)

Script to initial Credential Repository database - got left out of check in from April!

Line 
1#!/usr/bin/env python
2
3"""NDG Security - initialisation script for MySQL Credential Repository
4database
5
6Use with care!  It initialise all the tables in the database.
7
8NERC Data Grid Project
9
10P J Kershaw 25/04/06
11
12Copyright (C) 2006 CCLRC & NERC
13
14This software may be distributed under the terms of the Q Public License,
15version 1.0 or later.
16"""
17# Command line processing
18import sys
19import os
20import optparse
21import getpass
22
23from NDG.Session import *
24
25
26if __name__ == "__main__":
27    parser = optparse.OptionParser()
28    parser.add_option("-u",
29                      "--username",
30                      dest="username",
31                      help="Database username")
32
33    parser.add_option("-n",
34                      "--hostname",
35                      dest="hostname",
36                      help="database hostname - default is \"localhost\"")
37
38    parser.add_option("-D",
39                      "--database-name",
40                      dest="dbName",
41                      help="database name - default is \"ndgCredRepos\"")
42
43    (opt, args) = parser.parse_args()
44
45    if not opt.username:
46        sys.stderr.write("Error, No username set.\n\n")
47        parser.print_help()
48        sys.exit(1)
49
50    if not opt.hostname:
51        opt.hostname = "localhost"
52
53    if not opt.dbName:
54        opt.dbName = "ndgCredRepos"
55
56
57    # Obtain from prompt
58    try:
59        password = getpass.getpass(prompt="Database password: ")
60    except KeyboardInterrupt:
61        sys.exit(1)
62
63
64    try:
65        dbURI = "mysql://%s:%s@%s/%s" % \
66                            (opt.username, password, opt.hostname, opt.dbName)
67        credRepos = SessionMgrCredRepos(dbURI=dbURI)
68    except Exception, e:
69        sys.stderr.write("%s\n" % str(e))
70        sys.exit(1)
71
72    # This method prompts the user for confirmation of table initialisation
73    try:
74        credRepos._initTables()
75    except Exception, e:
76        sys.stderr.write("Error creating tables: %s\n" % str(e))
Note: See TracBrowser for help on using the repository browser.