├── LICENSE ├── MANIFEST.in ├── README.md ├── django_env ├── __init__.py ├── bin │ ├── __init__.py │ ├── install.py │ ├── postactivate │ ├── postdeactivate │ ├── postmkvirtualenv │ ├── runserver │ └── uninstall.py ├── config │ ├── django_env_settings_template.txt │ └── empty_fabfile.txt └── utils │ ├── get_django_env_settings.py │ └── vcs.py └── setup.py /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Brent O'Connor 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following 12 | disclaimer in the documentation and/or other materials provided 13 | with the distribution. 14 | * Neither the name of the author nor the names of other 15 | contributors may be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include LICENSE 3 | include MANIFEST.in 4 | recursive-include django_env * -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django-environment 2 | 3 | A plugin for virtualenvwrapper that makes setting up and creating new Django environments easier. 4 | 5 | ## Quick Install Instructions 6 | 7 | Pip install django-environment 8 | 9 | $ pip install django-environment 10 | $ python -c "from django_env.bin import install; install.main();" 11 | 12 | Optionally you can make the `--no-site-packages` argument the default argument when making a new virtual environment. Edit your `~/.profile` or `~/.bashrc` to add the following alias. 13 | 14 | alias mkvirtualenv="mkvirtualenv --no-site-packages" 15 | 16 | ## Optional Config Settings 17 | 18 | You can add optional settings that can change the default install behavior. One of the best settings is `DJANGO_BASE_SITE_URL`, if you have a Django base site on your local file system, Github, Bitbucket or any GIT, HG or SVN repository, you can have Django-environment setup a new environment using your own custom base site! 19 | 20 | To setup and use the optional config settings, all you need to do is add the file `~/.django_env_config` with any of the following settings. Alternatively, if you would prefer to put your config file somewhere else, then all you need to do is something like, `export DJANGO_ENV_CONFIG_PATH=/Users/username/.dotfiles/django_env_config` in your `~/.profile` or `~/.bashrc` (depending on your OS). 21 | 22 | # Controls whether or not to prompt the user during the setup of a new environment. Use N for No or Y for Yes. 23 | USE_DEFAULTS="N" 24 | 25 | # Controls whether or not to create a basic default fabfile template. 26 | CREATE_FABFILE="Y" 27 | 28 | # Sets the URL to use when pip installs Django. If blank Django will be 29 | # installed using, "pip install django". If you want to save download time 30 | # you could use something like, "/usr/local/src/django/Django-1.3.tar.gz" 31 | # to use a local tar gzipped version. 32 | DJANGO_SRC_URL="" 33 | 34 | # Use this setting to set the url of a Django base site. Currently Django- 35 | # environment has been tested with Github, Bitbucket and a privately hosted 36 | # SVN repository. 37 | # 38 | # Example URLs: 39 | # git+git://github.com/epicserve/django-base-site.git 40 | # hg+https://epicserve@bitbucket.org/epicserve/django-base-site 41 | # svn+ssh://user@ssh.yourdomain.com/path/to/django-base-site/trunk 42 | # file:///Users/username/code/django/django-base-site 43 | DJANGO_BASE_SITE_URL="" 44 | 45 | # Use this setting to change the default Django CONFIG_PATH. 46 | CONFIG_PATH="config" 47 | 48 | # Change the default Django development server address. 49 | SERVER_ADDR="127.0.0.1" 50 | 51 | # Change the default Django development server port. 52 | SERVER_PORT="8000" 53 | 54 | # If you Django base site has requirement files you can have 55 | # Django-environment install your pip requirements after your new 56 | # environment is installed. 57 | # Example: POST_PIP_CMD="install -r config/requirements.txt -r config/dev-requirements.txt" 58 | POST_PIP_CMD="" 59 | 60 | 61 | ## Create a new Django Environment for a Project 62 | 63 | 1. Create your container directory for your project. For example if you're working on the website example.com you might want to create a container directory called "example.com" in your home `~/Sites` directory. 64 | 65 | $ cd ~/Sites 66 | $ mkdir example.com 67 | $ cd example.com 68 | 69 | 2. Next you create your virtual environment and add your initial Django configuration files inside your Django project container directory or inside the Django project root directory. 70 | 71 | Run the `mkvirtualenv` command followed by the name you want to give your virtual environment. This is usually just an abbreviation of your website or your website domain name without the [TLD](http://en.wikipedia.org/wiki/Top-level_domain) extension. 72 | 73 | $ mkvirtualenv --no-site-packages example 74 | 75 | The previous command should give you an output like the following. Just answer all the prompts and when it finishes you should have a newly setup Django environment. Pay close attention to the question about the path to your config directory. The default setting should work well for most people. 76 | 77 | New python executable in example/bin/python 78 | Installing setuptools............done. 79 | virtualenvwrapper.user_scripts Creating /Users/username/.virtualenvs/example/bin/predeactivate 80 | virtualenvwrapper.user_scripts Creating /Users/username/.virtualenvs/example/bin/postdeactivate 81 | virtualenvwrapper.user_scripts Creating /Users/username/.virtualenvs/example/bin/preactivate 82 | virtualenvwrapper.user_scripts Creating /Users/username/.virtualenvs/example/bin/postactivate 83 | Is this a Django-enviroment your creating (y/n)? [Default: y] 84 | Enter the python path to the config directory (i.e. Where your settings.py, manage.py and urls will go). Use just . if you want the config files in your current project root. [Default: example.config] 85 | Development server address? [Default: 127.0.0.1] 86 | Development server address? [Default: 8000] 87 | Create a blank Fabric fabfile in your project (y/n)? [Default: y] 88 | Unpacking /Users/username/Downloads/Django-1.2.3.tar.gz 89 | Running setup.py egg_info for package from file:///Users/username/Downloads/Django-1.2.3.tar.gz 90 | warning: no files found matching 'django/dispatch/LICENSE.txt' 91 | warning: no files found matching '*' under directory 'examples' 92 | Installing collected packages: Django 93 | Running setup.py install for Django 94 | changing mode of build/scripts-2.6/django-admin.py from 644 to 755 95 | warning: no files found matching 'django/dispatch/LICENSE.txt' 96 | warning: no files found matching '*' under directory 'examples' 97 | changing mode of /Users/username/.virtualenvs/example/bin/django-admin.py to 755 98 | Successfully installed Django 99 | Cleaning up... 100 | 101 | Your Django-environment "example" has been activated. 102 | 103 | Django-environment Commands: 104 | runserver Starts the Django development server 105 | deactivate Deactivates the current Django-environment 106 | workon Work on a different Django-environment 107 | 108 | (example)oconnor@shiny:~/Sites/django_env_test/example.com$ 109 | 110 | Start the development server for your new project. 111 | 112 | $ runserver 113 | 114 | The previous command should give you an output like the following. Now if you go to the URL it gives you in your browser you should get the Django "It worked!" page. Now you're readying to start working on your new Django website. 115 | 116 | 0 errors found 117 | 118 | Django version 1.2.3, using settings 'example.config.settings' 119 | Development server is running at http://127.0.0.1:8000/ 120 | Quit the server with CONTROL-C. 121 | -------------------------------------------------------------------------------- /django_env/__init__.py: -------------------------------------------------------------------------------- 1 | VERSION = (0, 3, 8) 2 | __version__ = '.'.join(map(str, VERSION)) 3 | -------------------------------------------------------------------------------- /django_env/bin/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epicserve/django-environment/07a4f45f39551fc81fee3ac6796a79eb03544d43/django_env/bin/__init__.py -------------------------------------------------------------------------------- /django_env/bin/install.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import sys 5 | import os 6 | 7 | 8 | def main(): 9 | django_env_dir = os.path.abspath('%s/../' % os.path.dirname(__file__)) 10 | workon_home = os.environ.get('WORKON_HOME') 11 | if not workon_home: 12 | print "ERROR: The $WORKON_HOME environment variable is not set. Please check to make sure you've installed and setup virtualenvwrapper correctly." 13 | sys.exit() 14 | 15 | # symlink the django_env directory inside the $WORKON_HOME 16 | command = 'ln -sf %s "$WORKON_HOME/django_env"' % django_env_dir 17 | os.system(command) 18 | 19 | # add the ejango_env postmkvirtualenv hook to the virtualenvwrapper postmkvirtualenv hook 20 | postmkvirtualenv_cmd = 'source $WORKON_HOME/django_env/bin/postmkvirtualenv' 21 | workon_home = os.getenv('WORKON_HOME') 22 | postmkvirtualenv_path = os.path.join(workon_home, 'postmkvirtualenv') 23 | fh = open(postmkvirtualenv_path, "r") 24 | contents = fh.read() 25 | fh.close() 26 | if contents.find(postmkvirtualenv_cmd) == -1: 27 | fh = open(postmkvirtualenv_path, "a") 28 | fh.write("\n\n%s\n\n" % postmkvirtualenv_cmd) 29 | fh.close() 30 | 31 | print """ 32 | 33 | Django-environment is now installed. To create a django-environment run 34 | the following. 35 | 36 | mkvirtualenv [project_name] 37 | 38 | Example: 39 | mkvirtualenv example 40 | 41 | """ 42 | 43 | 44 | if __name__ == '__main__': 45 | main() 46 | -------------------------------------------------------------------------------- /django_env/bin/postactivate: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # For this django postactivate script to work you must add the following configuration variables to your django settings 4 | # DJANGO_ENV_PROJECT_DIR = '/home/username/sites/example.com' # The root directory where your project is saved 5 | # DJANGO_ENV_SETTINGS_MODULE = 'example.config.settings' # The python path to your django settings 6 | # DJANGO_ENV_SERVER_ADDR = '127.0.0.1' # Django Dev Server address (Not Required) 7 | # DJANGO_ENV_SERVER_PORT = '8088' # Django Dev Server port (Not Required) 8 | # DJANGO_ENV_FABFILE = '%s/bin/DJANGO_ENV_FABFILE.py' % PROJECT_DIR # Path to your fabric DJANGO_ENV_FABFILE (Not Required) 9 | 10 | # this is needed so you can load your Django settings 11 | 12 | DJANGO_ENV_PROJECT_DIR=$(get_django_env_settings.py get_var DJANGO_ENV_PROJECT_DIR) 13 | DJANGO_SETTINGS_MODULE=$(get_django_env_settings.py get_var DJANGO_ENV_SETTINGS_MODULE) 14 | DJANGO_ENV_SERVER_ADDR=$(get_django_env_settings.py get_var DJANGO_ENV_SERVER_ADDR) 15 | DJANGO_ENV_SERVER_PORT=$(get_django_env_settings.py get_var DJANGO_ENV_SERVER_PORT) 16 | DJANGO_ENV_FABFILE=$(get_django_env_settings.py get_var DJANGO_ENV_FABFILE) 17 | DJANGO_ENV_ACTIVATED_MSG='Your Django-environment "'`basename $VIRTUAL_ENV`'" has been activated. 18 | 19 | Django-environment Commands: 20 | runserver Starts the Django development server 21 | deactivate Deactivates the current Django-environment 22 | workon Work on a different Django-environment' 23 | 24 | # set the DJANGO_ENV_PROJECT_DIR enviroment variable 25 | if [ -n "$DJANGO_ENV_PROJECT_DIR" ]; then 26 | export DJANGO_ENV_PROJECT_DIR=$DJANGO_ENV_PROJECT_DIR 27 | fi 28 | 29 | export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE 30 | 31 | # set the DJANGO_ENV_SERVER_ADDR enviroment for running the djanog dev server (Not Required) 32 | if [ -n "$DJANGO_ENV_SERVER_ADDR" ]; then 33 | export DJANGO_ENV_SERVER_ADDR=$DJANGO_ENV_SERVER_ADDR 34 | fi 35 | 36 | # set the DJANGO_ENV_SERVER_PORT enviroment for running the djanog dev server (Not Required) 37 | if [ -n "$DJANGO_ENV_SERVER_PORT" ]; then 38 | export DJANGO_ENV_SERVER_PORT=$DJANGO_ENV_SERVER_PORT 39 | fi 40 | 41 | # Setup an alias to the DJANGO_ENV_FABFILE.py so fab workds from anywhere 42 | if [ -n "$DJANGO_ENV_FABFILE" ]; then 43 | alias fab="fab -f $DJANGO_ENV_FABFILE" 44 | DJANGO_ENV_ACTIVATED_MSG="$DJANGO_ENV_ACTIVATED_MSG 45 | fab Run fabric commands in your fabfile.py for this Django project." 46 | 47 | fi 48 | 49 | # Make an alias so you can easily cd to your project directory 50 | alias cddjango_project="cd $DJANGO_ENV_PROJECT_DIR" 51 | 52 | cddjango_project 53 | 54 | echo " 55 | $DJANGO_ENV_ACTIVATED_MSG 56 | " -------------------------------------------------------------------------------- /django_env/bin/postdeactivate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # remove all enviroment variables prefixed with DJANGO 4 | if [ -n "$(env | grep DJANGO_ENV)" ]; then 5 | for i in $(env | grep DJANGO_ENV | perl -lne "s/(django_env[_a-z]+)=.+/\\1/ig; print;"); do unset $i; done 6 | fi 7 | 8 | # remove the alias to the fabfile.py for this project 9 | if [ -n "$(alias | grep 'alias fab')" ]; then 10 | unalias fab 11 | fi 12 | -------------------------------------------------------------------------------- /django_env/bin/postmkvirtualenv: -------------------------------------------------------------------------------- 1 | 2 | # DEFUALT SETTINGS 3 | PROJECT_NAME=`basename $VIRTUAL_ENV` 4 | USE_DEFAULTS="N" 5 | CREATE_FABFILE="y" 6 | DJANGO_SRC_URL="" 7 | DJANGO_BASE_SITE_URL="" 8 | CONFIG_PATH="$PROJECT_NAME.config" 9 | SERVER_ADDR="127.0.0.1" 10 | SERVER_PORT="8000" 11 | POST_PIP_CMD="" 12 | RUN_SYNCDB="N" 13 | 14 | # If the DJANGO_ENV_CONFIG_PATH environment variable is set then source it's 15 | # path, else if the defualt django_env_config file exits source the file. The 16 | # loaded settings file overrides any of the default settings. 17 | if [[ -n "$DJANGO_ENV_CONFIG_PATH" ]]; then 18 | source $DJANGO_ENV_CONFIG_PATH 19 | elif [[ -f ~/.django_env_config ]]; then 20 | source ~/.django_env_config 21 | fi 22 | 23 | # Check to see if the user wants to install a Django environment 24 | echo -n "Is this a Django-enviroment your creating (y/n)? [Default: y] " 25 | read -e IS_DJANGO_ENV 26 | 27 | if [ -z "$IS_DJANGO_ENV" ]; then 28 | IS_DJANGO_ENV="y" 29 | fi 30 | if [ $IS_DJANGO_ENV == "n" ]; then 31 | exit 0 32 | fi 33 | 34 | if [ "$USE_DEFAULTS" != "Y" ]; then 35 | echo -n "Enter the python path to the config directory (i.e. Where your settings.py, manage.py and urls.py will go). Use a period (.) if you want the config files in your current project root. [Default: $CONFIG_PATH] " 36 | read -e CONFIG_PATH_INPUT 37 | fi 38 | if [ -n "$CONFIG_PATH_INPUT" ]; then 39 | CONFIG_PATH=$CONFIG_PATH_INPUT 40 | fi 41 | 42 | if [ "$USE_DEFAULTS" != "Y" ]; then 43 | echo -n "Development server address? [Default: $SERVER_ADDR] " 44 | read -e SERVER_ADDR_INPUT 45 | fi 46 | 47 | if [ "$USE_DEFAULTS" != "Y" ]; then 48 | echo -n "Development server address? [Default: $SERVER_PORT] " 49 | read -e SERVER_PORT_INPUT 50 | fi 51 | 52 | if [ "$USE_DEFAULTS" != "Y" ]; then 53 | echo -n "Create a blank Fabric fabfile in your project (y/n)? [Default: y] " 54 | read -e CREATE_FABFILE_INPUT 55 | fi 56 | if [ -n "$CREATE_FABFILE_INPUT" ]; then 57 | CREATE_FABFILE=$CREATE_FABFILE_INPUT 58 | fi 59 | 60 | # install Django 61 | if [ -n "$DJANGO_SRC_URL" ]; then 62 | pip install $DJANGO_SRC_URL 63 | else 64 | pip install django 65 | fi 66 | 67 | # Setup the Django project 68 | DJANGO_ENV_PROJECT_DIR=`pwd` 69 | if [ -n "$DJANGO_BASE_SITE_URL" ]; then 70 | SHELLPATH=`echo $CONFIG_PATH | perl -wpe "s/\./\//g"` 71 | FABFILE_LOCATION="$SHELLPATH/fabfile.py" 72 | SETTINGS_PATH="$SHELLPATH/settings.py" 73 | ROOT_URLCONF="$CONFIG_PATH.urls" 74 | SETTINGS_MODULE="$CONFIG_PATH.settings" 75 | $WORKON_HOME/django_env/utils/vcs.py $DJANGO_BASE_SITE_URL `pwd`/temp 76 | mv $DJANGO_ENV_PROJECT_DIR/temp/* $DJANGO_ENV_PROJECT_DIR 77 | rm -rf "$DJANGO_ENV_PROJECT_DIR/temp/" 78 | SETTINGS_MODULE="$CONFIG_PATH.settings" 79 | ROOT_URLCONF="$CONFIG_PATH.urls" 80 | else 81 | django-admin.py startproject temp 82 | if [ "$CONFIG_PATH" == "." ]; then 83 | FABFILE_LOCATION="$DJANGO_ENV_PROJECT_DIR/fabfile.py" 84 | SETTINGS_PATH="$DJANGO_ENV_PROJECT_DIR/settings.py" 85 | ROOT_URLCONF="urls" 86 | SETTINGS_MODULE="settings" 87 | mv $DJANGO_ENV_PROJECT_DIR/temp/* $DJANGO_ENV_PROJECT_DIR 88 | rm -rf "$DJANGO_ENV_PROJECT_DIR/temp/" 89 | else 90 | SHELLPATH=`echo $CONFIG_PATH | perl -wpe "s/\./\//g"` 91 | FABFILE_LOCATION="$SHELLPATH/fabfile.py" 92 | SETTINGS_PATH="$SHELLPATH/settings.py" 93 | ROOT_URLCONF="$CONFIG_PATH.urls" 94 | SETTINGS_MODULE="$CONFIG_PATH.settings" 95 | mkdir -p $SHELLPATH 96 | cp $DJANGO_ENV_PROJECT_DIR/temp/* $SHELLPATH/ 97 | find . -type d -exec touch {}/__init__.py \; 98 | rm $DJANGO_ENV_PROJECT_DIR/__init__.py 99 | rm -rf $DJANGO_ENV_PROJECT_DIR/temp 100 | fi 101 | fi 102 | 103 | 104 | 105 | 106 | # Setup the django_env_settings.py 107 | LOCAL_SETTINGS=`cat $WORKON_HOME/django_env/config/django_env_settings_template.txt` 108 | LOCAL_SETTINGS_TARGET=$VIRTUAL_ENV/bin/django_env_settings.py 109 | echo "$LOCAL_SETTINGS" > $LOCAL_SETTINGS_TARGET 110 | 111 | perl -i -wpe "s|{{ PROJECT_DIR }}|$DJANGO_ENV_PROJECT_DIR|g" $LOCAL_SETTINGS_TARGET 112 | perl -i -wpe "s/{{ SETTINGS_MODULE }}/$SETTINGS_MODULE/g" $LOCAL_SETTINGS_TARGET 113 | if [ -n "$SERVER_ADDR_INPUT" ]; then 114 | perl -i -wpe "s/127\.0\.0\.1/$SERVER_ADDR_INPUT/g" $LOCAL_SETTINGS_TARGET 115 | perl -i -wpe "s/# DJANGO_ENV_SERVER_ADDR/DJANGO_ENV_SERVER_ADDR /g" $LOCAL_SETTINGS_TARGET 116 | fi 117 | if [ -n "$SERVER_PORT_INPUT" ]; then 118 | perl -i -wpe "s/8000/$SERVER_PORT_INPUT/g" $LOCAL_SETTINGS_TARGET 119 | perl -i -wpe "s/# DJANGO_ENV_SERVER_PORT/DJANGO_ENV_SERVER_PORT /g" $LOCAL_SETTINGS_TARGET 120 | fi 121 | perl -i -wpe "s|{{ FABFILE }}|$FABFILE_LOCATION|g" $LOCAL_SETTINGS_TARGET 122 | if [ "$CREATE_FABFILE" == "Y" ]; then 123 | FABFILE=`cat $WORKON_HOME/django_env/config/empty_fabfile.txt` 124 | echo "$FABFILE" > $FABFILE_LOCATION 125 | fi 126 | 127 | 128 | # symlink all bin files 129 | ln -s $WORKON_HOME/django_env/bin/runserver $VIRTUAL_ENV/bin/runserver 130 | ln -s $WORKON_HOME/django_env/utils/get_django_env_settings.py $VIRTUAL_ENV/bin/get_django_env_settings.py 131 | 132 | 133 | # add the postactivate and postdeactivate hooks 134 | echo ' 135 | 136 | source $WORKON_HOME/django_env/bin/postactivate 137 | 138 | ' >> "$VIRTUAL_ENV/bin/postactivate" 139 | echo ' 140 | 141 | source $WORKON_HOME/django_env/bin/postdeactivate 142 | 143 | ' >> "$VIRTUAL_ENV/bin/postdeactivate" 144 | 145 | # fix the ROOT_URLCONF setting 146 | perl -i -wpe "s/temp\.urls/$ROOT_URLCONF/g" $SETTINGS_PATH 147 | 148 | # add all paths to the PYTHONPATH 149 | add2virtualenv $DJANGO_ENV_PROJECT_DIR 150 | 151 | # Install any requirements using PIP 152 | if [ -n "$POST_PIP_CMD" ]; then 153 | pip $POST_PIP_CMD 154 | fi 155 | 156 | # Run SYNCDB 157 | if [ "$RUN_SYNCDB" == "Y" ]; then 158 | export DJANGO_SETTINGS_MODULE="$CONFIG_PATH.settings" 159 | django-admin.py syncdb 160 | fi 161 | 162 | # source the Django-environment postactivate script 163 | source "$WORKON_HOME/django_env/bin/postactivate" 164 | 165 | -------------------------------------------------------------------------------- /django_env/bin/runserver: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ -n "$DJANGO_ENV_SERVER_ADDR" -a -n "$DJANGO_ENV_SERVER_PORT" ]; then 4 | django-admin.py runserver $DJANGO_ENV_SERVER_ADDR:$DJANGO_ENV_SERVER_PORT 5 | elif [ -n "$DJANGO_SERVER_PORT" ]; then 6 | django-admin.py runserver $DJANGO_ENV_SERVER_PORT 7 | else 8 | django-admin.py runserver 9 | fi -------------------------------------------------------------------------------- /django_env/bin/uninstall.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | import sys, os, re 5 | 6 | 7 | def main(): 8 | os.system('rm "$WORKON_HOME/django_env"') 9 | f = open('%s/postmkvirtualenv' % os.environ.get('WORKON_HOME'), 'r') 10 | fcontents = f.read() 11 | f.close() 12 | f = open('%s/postmkvirtualenv' % os.environ.get('WORKON_HOME'), 'w') 13 | replacement_text = re.sub(r'\s+source \$WORKON_HOME/django_env/bin/postmkvirtualenv\s+', '', fcontents) 14 | f.write(replacement_text) 15 | f.close() 16 | print "Django-environment uninstalled." 17 | 18 | 19 | if __name__ == '__main__': 20 | main() -------------------------------------------------------------------------------- /django_env/config/django_env_settings_template.txt: -------------------------------------------------------------------------------- 1 | # Django-enviroment settings 2 | DJANGO_ENV_PROJECT_DIR = '{{ PROJECT_DIR }}' 3 | DJANGO_ENV_SETTINGS_MODULE = '{{ SETTINGS_MODULE }}' 4 | # DJANGO_ENV_SERVER_ADDR = '127.0.0.1' 5 | # DJANGO_ENV_SERVER_PORT = '8000' 6 | # DJANGO_ENV_FABFILE = '{{ FABFILE }}' -------------------------------------------------------------------------------- /django_env/config/empty_fabfile.txt: -------------------------------------------------------------------------------- 1 | from fabric.api import * 2 | 3 | """ 4 | This is file where you add your fabric commands, see http://docs.fabfile.org 5 | for more information. 6 | 7 | # Example method 8 | def ls(): 9 | local('ls -la') 10 | """ -------------------------------------------------------------------------------- /django_env/utils/get_django_env_settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, os 4 | 5 | project_name = os.path.basename(os.getenv("VIRTUAL_ENV")) 6 | 7 | # try: 8 | # exec "from %s.config import settings" % project_name 9 | # except ImportError: 10 | # from django.conf import settings 11 | 12 | def get_var(var_name, default=''): 13 | val = getattr(settings, var_name, default) 14 | print val 15 | 16 | def get_path(var_name): 17 | val = get_var(var_name, []) 18 | val = ":".join(val) 19 | print val 20 | 21 | if __name__ == '__main__': 22 | 23 | setting_missing = True 24 | 25 | try: 26 | sys.path.insert(0, os.path.dirname(__file__)) 27 | settings = __import__('django_env_settings', globals(), locals(), []) 28 | del sys.path[0] 29 | except ImportError: 30 | raise Exception("\n\n\ 31 | Error: The django_env_settings.py file is missing.\n\n\ 32 | You need to add the file %s/django_env_settings.py and include the following django-environment settings.\n\n\ 33 | DJANGO_ENV_PROJECT_DIR = '/path/to/your/django/project/root'\n\ 34 | DJANGO_ENV_SETTINGS_MODULE = 'config.settings'\n\ 35 | DJANGO_ENV_SERVER_ADDR = '127.0.0.1'\n\ 36 | DJANGO_ENV_SERVER_PORT = '8000'\n" % os.path.dirname(__file__)) 37 | 38 | else: 39 | locals()[sys.argv[1]](sys.argv[2]) -------------------------------------------------------------------------------- /django_env/utils/vcs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from subprocess import call 4 | 5 | import os 6 | import sys 7 | import re 8 | import shutil 9 | 10 | 11 | def main(): 12 | vcs_schemes = ['git', 'hg', 'svn', 'file'] 13 | vcs_scheme_url = sys.argv[1] 14 | target_dir = sys.argv[2] 15 | url_match = re.search(r'^(?P[a-z]{2,3})\+(?P.+)', vcs_scheme_url) 16 | 17 | if not url_match and not vcs_scheme_url.startswith('file://'): 18 | print """Error: VCS URL wasn't in the correct format 19 | 20 | Examples: 21 | git+git://github.com/epicserve/django-base-site.git. 22 | hg+https://epicserve@bitbucket.org/epicserve/django-base-site 23 | svn+ssh://user@ssh.yourdomain.com/path/to/django-base-site/trunk 24 | file:///Users/username/code/django/django-base-site""" 25 | 26 | if vcs_scheme_url.startswith('file://'): 27 | scheme = 'file' 28 | path = vcs_scheme_url.replace('file://', '') 29 | if not path.endswith('/'): 30 | path = path + '/' 31 | else: 32 | scheme = url_match.group('scheme') 33 | url = url_match.group('url') 34 | 35 | if not scheme in vcs_schemes: 36 | print "Error: Unsupported VCS. Supported VCS (%S)" % ", ".join(vcs_schemes) 37 | 38 | if scheme == "git": 39 | call(["git", "clone", url, target_dir]) 40 | git_dir = os.path.join(target_dir, '.git') 41 | if os.path.isdir(git_dir): 42 | shutil.rmtree(git_dir) 43 | 44 | if scheme == "hg": 45 | call(["hg", "clone", url, target_dir]) 46 | hg_dir = os.path.join(target_dir, '.hg') 47 | if os.path.isdir(hg_dir): 48 | shutil.rmtree(hg_dir) 49 | 50 | if scheme == "svn": 51 | if vcs_scheme_url.startswith('svn+ssh'): 52 | url = vcs_scheme_url 53 | call(["svn", "export", url, target_dir]) 54 | 55 | if scheme == "file": 56 | if not path.endswith('/'): 57 | target_dir = target_dir + '/' 58 | os.mkdir(target_dir) 59 | cmd = "cp -r %s* %s" % (path, target_dir) 60 | print cmd 61 | os.system(cmd) 62 | 63 | 64 | if __name__ == '__main__': 65 | main() 66 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | import os 3 | 4 | # OS X: prevent 'tar' from including resource forks ("._*" files) 5 | os.environ['COPYFILE_DISABLE'] = 'true' 6 | 7 | # Compile the list of packages available, because distutils doesn't have 8 | # an easy way to do this. 9 | packages, data_files = [], [] 10 | for dirpath, dirnames, filenames in os.walk('django_env'): 11 | # Ignore dirnames that start with '.' 12 | for i, dirname in enumerate(dirnames): 13 | if dirname.startswith('.'): 14 | del dirnames[i] 15 | if '__init__.py' in filenames and dirpath != os.path.join('django_env', 'bin'): 16 | pkg = dirpath.replace(os.path.sep, '.') 17 | if os.path.altsep: 18 | pkg = pkg.replace(os.path.altsep, '.') 19 | packages.append(pkg) 20 | elif filenames: 21 | prefix = dirpath[11:] # Strip "django_env/" or "django_env\" 22 | for f in filenames: 23 | if not f.endswith('.pyc'): # ignore pyc files 24 | data_files.append(os.path.join(prefix, f)) 25 | 26 | setup( 27 | name='django-environment', 28 | version=__import__('django_env').__version__, 29 | description='A plugin for virtualenvwrapper that makes setting up and creating new Django environments easier.', 30 | long_description=open('README.md').read(), 31 | author="Brent O'Connor", 32 | author_email='epicserve@gmail.com', 33 | url='http://github.com/epicserve/django-environment', 34 | install_requires=['virtualenvwrapper'], 35 | packages=packages, 36 | package_data={'django_env': data_files}, 37 | classifiers=[ 38 | 'Development Status :: 4 - Beta', 39 | 'Environment :: Web Environment', 40 | 'Framework :: Django', 41 | 'Intended Audience :: Developers', 42 | 'Operating System :: OS Independent', 43 | 'Programming Language :: Python', 44 | 'Topic :: Software Development :: Libraries :: Python Modules', 45 | ], 46 | ) 47 | --------------------------------------------------------------------------------