python manage.py syncdb
Every few minutes as the database models were changing. You might consider this some kind of evil thing to do, because we should all have our database models in concrete before writing any code but I am not that organised.
One thing that was really distressing me was the fact that each time I ran a syncdb, I had to enter details for my default admin user.
- Email address
- Repeart Password
Pexpect, http://pexpect.sourceforge.net/ is a pure python module for running external commands and controlling them as if you were a user. It has good documentation, and is perfect for needs of this nature.
A quick browse through the excellent documentation, and we were away. Here is the code:
PASSWORD = '123' # replace this with something good
EMAIL = 'firstname.lastname@example.org'
# spawn the child process
child = pexpect.spawn('python manage.py syncdb')
# Wait for the application to give us this text (a regular expression)
child.expect('Would you like to create one now.*')
# Send this line in response
# Again wait for this, and send what is needed
# A blank string for the default username
# And so it goes on
# This means wait for the end of the child's output
And we are done. This runs the command, and enters the correct details without having to be interactive, and saving a load of time and typing.
I actually combined this script with an initial data-import setup script which loaded the database with the initial data, for added fruitiness.