Fabric & Django
Or how automate the creation of new projects with simple script
Preface: Do you remember all this tiny little steps that you have to perform every time when you start new project – create virtual environment, install packages, start and setup Django project? Kind of annoying repetition, isn’t it? How about to automate it a bit.
Solution: Recently I started learning Fabric and thought “What better way to test it in practice than automating a simple, repetitive task?”. So, lets mark the tasks that I want the script to perform:
- Create virtual environment with the project name
- Activate the virtual environment
- Download list of packages and install them
- Make ‘src’ directory where the project source will reside
- Create new Django project in source directory
- Update the settings
Thanks to the local command the first one was easy. The problem was with the second one. Obviously each local command is run autonomously so I had to find some way have activated virtual environment for each task after this. Fortunately the prefix context manager works like a charm. I had some issues making it read and write in the paths I wants and voilà it was working exactly as I want.
The script is too long to place it here but is publicly available at https://gist.github.com/2818562
It is quite simple to use, you only need python, fabric and virtual environment. Then just use the following code.
To Do: Here are few things that can be improved:
- Read the packages from a file
- Update urls.py to enable admin
- Generate Nginx server block file
So this is my first try with Fabric, I hope that you will like it and find it useful. As always any comments, questions and/or improvement ideas are welcome.
- Django for Web Prototyping
- Functions in Python presentation
- Simple Site Checker and the User-Agent header
- Automation, Fabric and Django – presentation
- Django project file structure
- Automated deployment with Ubuntu, Fabric and Django
- The road to hell is paved with regular expressions …
- Django compressor and image preloading
- Python is not a Panacea …
- Simple Site Checker