it/itf/dropandcreatedb.py
2010-03-03 19:58:00 +05:30

21 lines
798 B
Python
Executable File

import sys
import os
from settings import DATABASE_NAME
try:
import settings # Assumed to be in the same directory.
except ImportError:
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
filename = "/tmp/tmp.txt"
tmpfile = open(filename, "w")
tmpfile.write("DROP DATABASE %s;\nCREATE DATABASE %s;\n" % (DATABASE_NAME, DATABASE_NAME) )
tmpfile.close()
os.system("mysql -u root < " + filename)
os.system("python manage.py syncdb --noinput")
os.system("python manage.py createsuperuser --username admin --email user@user.com")