Skip to content
This repository was archived by the owner on Mar 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ command script like this::

django-startproject.py --template-dir=/your/custom/template project_name

You can also clone a template directly from a repository (git, mercurial, bazaar)
using `pip-like` syntax:

django-startproject.py --template-dir=git+git://repo/template.git project_name


Specifying boilerplate variables
--------------------------------
Expand Down
22 changes: 20 additions & 2 deletions django_startproject/management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django_startproject import utils
import optparse
import os
import shutil
import subprocess
import sys


Expand All @@ -11,12 +13,11 @@
def start_project():
"""
Copy a project template, replacing boilerplate variables.

"""
usage = "usage: %prog [options] project_name [base_destination_dir]"
parser = optparse.OptionParser(usage=usage)
parser.add_option('-t', '--template-dir', dest='src_dir',
help='project template directory to use',
help='project template directory or repository to use',
default=TEMPLATE_DIR)
options, args = parser.parse_args()
if len(args) not in (1, 2):
Expand All @@ -25,12 +26,25 @@ def start_project():
project_name = args[0]

src = options.src_dir

if len(args) > 1:
base_dest_dir = args[1]
else:
base_dest_dir = ''
dest = os.path.join(base_dest_dir, project_name)

# Detect and clone repo
repo_info = src.split('+')
tmp_dest = None

if len(repo_info) > 1:
vcs, url = repo_info
tmp_dest = 'djstartproject_tmp_%s' % dest
fnull = open(os.devnull, 'w')
print "Cloning template from %s" % url
subprocess.call([vcs, 'clone', url, tmp_dest], stdout = fnull, stderr = fnull)
src = tmp_dest

# Get any boilerplate replacement variables:
replace = {}
for var, help, default in utils.get_boilerplate(src, project_name):
Expand All @@ -45,3 +59,7 @@ def start_project():
replace[var] = value

utils.copy_template(src, dest, replace)

# Cleanup repo clone
if tmp_dest != None:
shutil.rmtree(tmp_dest)