Created
October 11, 2011 21:04
-
-
Save alexmacedo/1279438 to your computer and use it in GitHub Desktop.
Virtualenv bootstrap script to create a Django environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
#! /usr/bin/env python | |
import os | |
import subprocess | |
def extend_parser(optparse_parser): | |
optparse_parser.add_option("--nose", action="store_true", | |
dest="nose", default=False, | |
help="add django-nose package to environment") | |
optparse_parser.add_option("--south", action="store_true", | |
dest="south", default=False, | |
help="add South package to environment") | |
optparse_parser.add_option("--fabric", action="store_true", | |
dest="fabric", default=False, | |
help="add Fabric to environment") | |
optparse_parser.add_option("--mock", action="store_true", | |
dest="mock", default=False, | |
help="add Mock package to environment") | |
optparse_parser.add_option("--project", action="store", type="string", | |
dest="project_name", default=None, | |
help="Create a django project with name PROJECT", | |
metavar="PROJECT") | |
optparse_parser.add_option("--mysql", action="store_true", | |
dest="mysql", default=False, | |
help="add MySQL-python to environment") | |
optparse_parser.add_option("--git", action="store_true", | |
dest="git", default=False, | |
help="add git versioning to project") | |
optparse_parser.add_option("--hg", action="store_true", | |
dest="hg", default=False, | |
help="add mercurial versioning to project") | |
def adjust_options(options, args): | |
options.no_site_packages = True | |
def after_install(options, home_dir): | |
pip = os.path.join(home_dir, 'bin', 'pip') | |
django = os.path.join('bin', 'django-admin.py') | |
subprocess.call([pip, 'install', 'Django']) | |
if options.south: | |
subprocess.call([pip, 'install', 'South']) | |
if options.nose: | |
subprocess.call([pip, 'install', 'django-nose']) | |
if options.mock: | |
subprocess.call([pip, 'install', 'mock']) | |
if options.fabric: | |
subprocess.call([pip, 'install', 'Fabric']) | |
if options.mysql: | |
subprocess.call([pip, 'install', 'MySQL-python']) | |
if options.project_name is not None: | |
project_name = os.path.join(home_dir, options.project_name) | |
subprocess.call([django, "startproject", options.project_name], cwd=home_dir) | |
with open(os.path.join(project_name, "requirements.txt"), "w") as f: | |
subprocess.call([pip, "freeze"], stdout=f) | |
with open(os.path.join(project_name, "README"), "w") as f: | |
f.write("Put a description here...\n") | |
os.mkdir(os.path.join(project_name, "static")) | |
os.mkdir(os.path.join(project_name, "templates")) | |
if options.fabric: | |
with open(os.path.join(project_name, 'fabfile.py'), "w") as f: | |
f.write("some useful template...\n") | |
if options.git: | |
subprocess.call(['git', 'init', project_name]) | |
with open(os.path.join(project_name, '.gitignore'), "w") as f: | |
f.write("*.pyc\n") | |
elif options.hg: | |
subprocess.call(['hg', 'init', project_name]) | |
with open(os.path.join(project_name, '.hgignore'), "w") as f: | |
f.write("syntax: glob\n\n*.pyc\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
#! /usr/bin/env python | |
import virtualenv | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) == 2: | |
filename = sys.argv[1] | |
try: | |
content = open(filename, 'r').read() | |
except IOError: | |
sys.stdout.write("File %s not found.\n" % filename) | |
output = virtualenv.create_bootstrap_script(content) | |
sys.stdout.write(output) | |
else: | |
sys.stdout.write("Usage: %s <bootstrap_file>\n" % sys.argv[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python generate_bootstrap.py bootstrap_base.py > django-bootstrap.py | |
$ python django-bootstrap.py ENV --project=NAME [ --hg --git --mysql --south --fabric --nose ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment