dotfiles/zsh/func/makers/mkdjango
2013-08-09 10:13:34 -07:00

77 lines
2.1 KiB
Bash

#!/bin/zsh
# Create a Django project using a template in .dotfiles/codetemplates/django
# Eryn Wells <eryn@erynwells.me>
local funcname=$0
_usage_mkdjango() {
print_info "Usage: $funcname template_name project_name [optional destination directory]"
}
function mkdjango
{
if [[ ${#@} -lt 2 ]]; then
print_error "Need moar arguments" 1>&2
_usage_mkdjango
return -1
fi
local template_name=$1
local template_dir="$HOME/.codetemplates/django/$template_name"
local project_name=$2
local project_dst=$3
if [[ ! -d "$template_dir" ]]; then
print_error "Invalid template name: $template_name" 1>&2
return -2
fi
if [[ -n "$project_dst" ]]; then
if [[ ! -d "$project_dst" ]]; then
print_info_sub "Destination directory given but does not exist; " \
"will create $project_dst"
fi
else
project_dst="`pwd`/$project_name"
fi
print_info "Making Django project '$project_name'"
print_info_sub "Template name: $template_name"
print_info_sub "Template directory: $template_dir"
print_info_sub "Project directory: $project_dst"
# Determine what files might not be rendered by django-admin.py
local missing_files=()
for f in `ls -A1 "$template_dir"`; do
# Pick up all dotfiles
if [[ -e "$f" && "$f" =~ "^\." ]]; then
missing_files+=("$f")
fi
done
print_info_sub "Missing files: ${(j., .)missing_files}"
mkdir -p "$project_dst"
print_info "Calling django-admin.py"
django-admin.py startproject --template="$template_dir" \
--name=${(j.,.)missing_files} \
"$project_name" \
"$project_dst"
exitcode=$?
if [[ $exitcode -ne 0 ]]; then
print_error "django-admin.py failed"
return $exitcode
fi
# print_info "Setting up Git repo"
# cd "$project_dir"
# git init
# git add * .*
# git commit -m 'Initial commit'
return $exitcode
}
mkdjango $@