aboutsummaryrefslogtreecommitdiff
path: root/rpkid/portal-gui/scripts/rpkigui-setup-sql.py
diff options
context:
space:
mode:
authorMichael Elkins <melkins@tislabs.com>2011-12-08 00:55:20 +0000
committerMichael Elkins <melkins@tislabs.com>2011-12-08 00:55:20 +0000
commitf19ba66d8c1b98dd62550dc7eb6a98f9e6d0e226 (patch)
treeba1b3ccc810dcf6ab433fc76753a0c84ac9af73a /rpkid/portal-gui/scripts/rpkigui-setup-sql.py
parent33f8bf22f6849b90f8f53b329392f2ab69dbf1fc (diff)
Use mysql as the db backend for django.
Pull SQL authentication information from rpki.conf so the user need not edit settings.py. svn path=/branches/tk139/; revision=4106
Diffstat (limited to 'rpkid/portal-gui/scripts/rpkigui-setup-sql.py')
-rw-r--r--rpkid/portal-gui/scripts/rpkigui-setup-sql.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/rpkid/portal-gui/scripts/rpkigui-setup-sql.py b/rpkid/portal-gui/scripts/rpkigui-setup-sql.py
new file mode 100644
index 00000000..2d3c1833
--- /dev/null
+++ b/rpkid/portal-gui/scripts/rpkigui-setup-sql.py
@@ -0,0 +1,29 @@
+# $Id$
+#
+# This script is responsible for creating the database used by the
+# portal gui. Look in the settings.py file for the user and password.
+# n.b. The configure script generates a random password.
+#
+
+import getpass, MySQLdb
+from django.conf import settings
+
+dbname = settings.DATABASES['default']['NAME']
+dbuser = settings.DATABASES['default']['USER']
+dbpass = settings.DATABASES['default']['PASSWORD']
+
+print """WARNING!!!
+WARNING!!!
+WARNING!!!
+
+About to destroy and recreate the database named "%s" and give access
+to the user named "%s".
+""" % (dbname, dbuser)
+
+passwd = getpass.getpass('Please enter your MySQL root password: ')
+
+db = MySQLdb.connect(user='root', passwd=passwd)
+c = db.cursor()
+c.execute('DROP DATABASE IF EXISTS %s' % dbname)
+c.execute('CREATE DATABASE %s CHARACTER SET utf8' % dbname)
+c.execute('GRANT ALL ON %s.* TO %s@localhost identified by %%s' % (dbname, dbuser), (dbpass,))