#NEWLINE# def setupdatabase( self , data ) : #NEWLINE# #INDENT# ee_domain_name = data [ 'site_name' ] #NEWLINE# ee_random = '' . join ( random . sample ( ( ( string . ascii_uppercase + string . ascii_lowercase ) + string . digits ) , 15 ) ) #NEWLINE# ee_replace_dot = ee_domain_name . replace ( '.' , '_' ) #NEWLINE# prompt_dbname = self . app . config . get ( 'mysql' , 'db-name' ) #NEWLINE# prompt_dbuser = self . app . config . get ( 'mysql' , 'db-user' ) #NEWLINE# ee_mysql_grant_host = self . app . config . get ( 'mysql' , 'grant-host' ) #NEWLINE# ee_db_name = '' #NEWLINE# ee_db_username = '' #NEWLINE# ee_db_password = '' #NEWLINE# if ( ( prompt_dbname == 'True' ) or ( prompt_dbname == 'true' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ee_db_name = input ( 'Enter the MySQL database name [{0}]: ' . format ( ee_replace_dot ) ) #NEWLINE# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'Unable to input database name' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not ee_db_name ) : #NEWLINE# #INDENT# ee_db_name = ee_replace_dot #NEWLINE# #UNINDENT# if ( ( prompt_dbuser == 'True' ) or ( prompt_dbuser == 'true' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ee_db_username = input ( 'Enter the MySQL database user name [{0}]: ' . format ( ee_replace_dot ) ) #NEWLINE# ee_db_password = getpass . getpass ( prompt = 'Enter the MySQL database password [{0}]: ' . format ( ee_random ) ) #NEWLINE# #UNINDENT# except EOFError as e : #NEWLINE# #INDENT# Log . debug ( self , '{0}' . format ( e ) ) #NEWLINE# raise SiteError ( 'Unable to input database credentials' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not ee_db_username ) : #NEWLINE# #INDENT# ee_db_username = ee_replace_dot #NEWLINE# #UNINDENT# if ( not ee_db_password ) : #NEWLINE# #INDENT# ee_db_password = ee_random #NEWLINE# #UNINDENT# if ( len ( ee_db_username ) > 16 ) : #NEWLINE# #INDENT# Log . debug ( self , 'Autofix MySQL username (ERROR 1470 (HY000)), please wait' ) #NEWLINE# ee_db_username = ( ee_db_name [ 0 : 6 ] + generate_random ( ) ) #NEWLINE# #UNINDENT# Log . info ( self , 'Setting up database\t\t' , end = '' ) #NEWLINE# Log . debug ( self , 'Creating database {0}' . format ( ee_db_name ) ) #NEWLINE# try : #NEWLINE# #INDENT# if EEMysql . check_db_exists ( self , ee_db_name ) : #NEWLINE# #INDENT# Log . debug ( self , 'Database already exists, Updating DB_NAME .. ' ) #NEWLINE# ee_db_name = ( ee_db_name [ 0 : 6 ] + generate_random ( ) ) #NEWLINE# ee_db_username = ( ee_db_name [ 0 : 6 ] + generate_random ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# except MySQLConnectionError as e : #NEWLINE# #INDENT# raise SiteError ( 'MySQL Connectivity problem occured' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# EEMysql . execute ( self , 'create database `{0}`' . format ( ee_db_name ) ) #NEWLINE# #UNINDENT# except StatementExcecutionError as e : #NEWLINE# #INDENT# Log . info ( self , ( ( ( ( ( '[' + Log . ENDC ) + Log . FAIL ) + 'Failed' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# raise SiteError ( 'create database execution failed' ) #NEWLINE# #UNINDENT# Log . debug ( self , 'Creating user {0}' . format ( ee_db_username ) ) #NEWLINE# Log . debug ( self , "create user `{0}`@`{1}` identified by ''" . format ( ee_db_username , ee_mysql_grant_host ) ) #NEWLINE# try : #NEWLINE# #INDENT# EEMysql . execute ( self , "create user `{0}`@`{1}` identified by '{2}'" . format ( ee_db_username , ee_mysql_grant_host , ee_db_password ) , log = False ) #NEWLINE# #UNINDENT# except StatementExcecutionError as e : #NEWLINE# #INDENT# Log . info ( self , ( ( ( ( ( '[' + Log . ENDC ) + Log . FAIL ) + 'Failed' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# raise SiteError ( 'creating user failed for database' ) #NEWLINE# #UNINDENT# Log . debug ( self , 'Setting up user privileges' ) #NEWLINE# try : #NEWLINE# #INDENT# EEMysql . execute ( self , 'grant all privileges on `{0}`.* to `{1}`@`{2}`' . format ( ee_db_name , ee_db_username , ee_mysql_grant_host ) ) #NEWLINE# #UNINDENT# except StatementExcecutionError as e : #NEWLINE# #INDENT# Log . info ( self , ( ( ( ( ( '[' + Log . ENDC ) + Log . FAIL ) + 'Failed' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# SiteError ( 'grant privileges to user failed for database ' ) #NEWLINE# #UNINDENT# Log . info ( self , ( ( ( ( '[' + Log . ENDC ) + 'Done' ) + Log . OKBLUE ) + ']' ) ) #NEWLINE# data [ 'ee_db_name' ] = ee_db_name #NEWLINE# data [ 'ee_db_user' ] = ee_db_username #NEWLINE# data [ 'ee_db_pass' ] = ee_db_password #NEWLINE# data [ 'ee_db_host' ] = EEVariables . ee_mysql_host #NEWLINE# data [ 'ee_mysql_grant_host' ] = ee_mysql_grant_host #NEWLINE# return data