Bentley4
Bentley4

Reputation: 11028

Automating customisation of Django projects after '$ django-admin.py startproject my_project' with zc.buildout

I have skimmed the official zc.buildout documentation and some tuts but I haven't found a clear answer to the following question.

Suppose I wanted to automate the following changes in every Django project(Django1.4) from now on, can all of those changes get executed by merely by a buildout.cfg file?

After doing $ django-admin.py startproject my_project, example of changes of the default startproject I would implement:

$ mkdir ~/path/to/my_project/my_project/db

settings.py:

import os
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(ROOT_PATH, 'db/my_project.db'),                      
        'USER': '',                     
        'PASSWORD': '',                  
        'HOST': '',                    
        'PORT': '', 
    }
}

I currently build and use my own customized distribution of the 1.4 branch of the Django source as a solution but it would be nice to know if I could do it using buildout as well.

Upvotes: 0

Views: 104

Answers (2)

Reinout van Rees
Reinout van Rees

Reputation: 13624

In addition to Martijn's answer: buildout can create directories just fine. Have a look at http://pypi.python.org/pypi/z3c.recipe.mkdir/

That's one of the tasks I regularly use it for (creating a var/log/ for logfiles, a var/sqlite/ dir for the sqlite file, etc.)

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1122382

What you want is not really part of the Buildout set of use-cases.

You want to customize generated code when you start a project, while buildout aims at giving you a reproducible deployment or development environment.

The former one developer would use, the latter is aimed at getting multiple developers or multiple production machines up and running with the same software stack.

That said, certainly a buildout recipe can be constructed that writes out new versions of those files when the part is run. For example, using collective.recipe.template you could specify a template file to be placed in a certain location every time buildout is run. Note that that would overwrite those files if they ever changed.

Upvotes: 1

Related Questions