#coding:utf-8
import os
import time
import pymysql
from kcsj.local_settings import DATABASES 

dbconf=DATABASES.get('default')
config={'host':dbconf.get('HOST'),
    'user':dbconf.get('USER'),
    'passwd':dbconf.get('PASSWORD'),
    'port':dbconf.get('PORT'),
    'charset':'utf8',
    }
database=dbconf.get('NAME')

try:
    conn=pymysql.connect(**config)
    cur=conn.cursor()
    
    cur.execute('create database if not exists {}'.format(database))
    #conn.select_db(database)
    conn.commit()    

    cur.close()
    conn.close()
except Exception,e:
     print "SQL Error: %s" % (e)

    

@@ -18,48 +18,76 @@
 ort 
-os%0Aimport time%0Aimport pymysql%0Afrom kcsj.
+pymysql%0A%0Afrom importlib import import_module%0A#search the dirname of 
 loca
@@ -96,24 +96,31 @@
 settings
+.py and
  import 
 DATABASE
@@ -115,18 +115,162 @@
 ort 
-DATABASES 
+it%0Awith open('manage.py') as f:%0A    s=f.read()%0Ad=re.search(r'DJANGO_SETTINGS_MODULE.*?,%5Cs*%22(.+?)settings',s).group(1)%0Amo=import_module(d+'local_settings')
 %0A%0Adb
@@ -274,16 +274,19 @@
 %0Adbconf=
+mo.
 DATABASE

modify createdatabase.py