Skip to content

Commit

Permalink
added source_root as an option, to be able to have the project files …
Browse files Browse the repository at this point in the history
…in sub directory, for example in src/
  • Loading branch information
peterlauri committed Jan 11, 2016
1 parent 793d632 commit 93bf4aa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ Take a look at the generated README.md for information how to deploy up your dja

## Template variables

* **aws_eb_type**: if you want EB python or docker setup
* **aws_eb_type**: if you want EB python or docker setup
* **project_name**: django project name, just like in startproject
* **django_version**: what django version to install
* **setup_local_env**: if we should keep the virtualenvironment with requirements/local.txt installed and
create postgres database
* **virtualenv_bin**: location to virtualbin binary, in case it is not in your path, or if you wanna use some other
virtualenv binary
* **source_root**: relative location where the source code should end up, default is ".". Example use src to get all
the django code to reside in src/ directory.


## Prerequisites
Expand Down
3 changes: 2 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"project_name": "myproject",
"django_version": "1.9.1",
"setup_local_env": "yes",
"virtualenv_bin": "virtualenv"
"virtualenv_bin": "virtualenv",
"source_root": "."
}
15 changes: 9 additions & 6 deletions hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source_root="{{ cookiecutter.source_root }}"

# functions
do_createdb() {
# attempt to create the postgres database
Expand All @@ -14,19 +16,20 @@ do_install_local_requirements() {
}

do_patch_settings_and_manage_py() {
mv "settings" "{{ cookiecutter.project_name }}/"
mv "settings" "$source_root/{{ cookiecutter.project_name }}/"

WSGI_PATH="{{ cookiecutter.project_name }}/wsgi.py"
COMMON_SETTINGS="{{ cookiecutter.project_name }}/settings/common.py"
WSGI_PATH="$source_root/{{ cookiecutter.project_name }}/wsgi.py"
MANAGE_PATH="$source_root/manage.py"
COMMON_SETTINGS="$source_root/{{ cookiecutter.project_name }}/settings/common.py"

mv "{{ cookiecutter.project_name }}/settings.py" "$COMMON_SETTINGS"
mv "$source_root/{{ cookiecutter.project_name }}/settings.py" "$COMMON_SETTINGS"
cat "settings_extra.py" >> "$COMMON_SETTINGS" && rm "settings_extra.py"

sed -i "" -e "s/{{ cookiecutter.project_name }}.settings/{{ cookiecutter.project_name }}.settings.local/g" "manage.py" "$WSGI_PATH"
sed -i "" -e "s/{{ cookiecutter.project_name }}.settings/{{ cookiecutter.project_name }}.settings.local/g" "$MANAGE_PATH" "$WSGI_PATH"
}

do_patch_wsgi_py_whitenoise() {
WSGI_PATH="{{ cookiecutter.project_name }}/wsgi.py"
WSGI_PATH="$source_root/{{ cookiecutter.project_name }}/wsgi.py"
cat "wsgi_extra.py" >> "$WSGI_PATH" && rm "wsgi_extra.py"
}

Expand Down
5 changes: 3 additions & 2 deletions hooks/pre_gen_project.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

source_root="{{ cookiecutter.source_root }}"

require_program() {
theprogram="$1"
Expand All @@ -19,7 +20,7 @@ if [ "{{ cookiecutter.setup_local_env }}" == "yes" ]; then
fi

{{ cookiecutter.virtualenv_bin }} .ve
.ve/bin/pip install -q django=={{ cookiecutter.django_version }}
.ve/bin/django-admin.py startproject -v 0 "{{ cookiecutter.project_name }}" .
.ve/bin/pip install -q "django=={{ cookiecutter.django_version }}"
mkdir "$source_root" && .ve/bin/django-admin.py startproject -v 0 "{{ cookiecutter.project_name }}" "{{ cookiecutter.source_root }}"

echo "---> DONE Running pre-hook script..."
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN /app/.vedocker/bin/pip install -r /requirements/production.txt
# Adding application code
#######################################################

ADD . /app/
ADD {{ cookiecutter.source_root }} /app/
RUN /app/.vedocker/bin/python /app/manage.py collectstatic --noinput

#######################################################
Expand Down

0 comments on commit 93bf4aa

Please sign in to comment.