-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartproject
executable file
·122 lines (95 loc) · 3.23 KB
/
startproject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
# NOTE: THIS SCRIPT WAS DEVELOPED AND TESTED ON LINUX.
#
# See the README for some details.
#
set -e # Stop script on first error.
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
TEMPLATE_DIR="$SCRIPT_PATH/src/myproject"
if [ ! -d "$TEMPLATE_DIR" ]; then
echo "$0: Cannot find template in $TEMPLATE_DIR"
exit 1
fi
PROJECT_IDENT="$1"
if [ ! "$PROJECT_IDENT" ]; then
echo "$0: Please supply the Python identifier of the new project."
exit 2
fi
if [ -e "$PROJECT_IDENT" ]; then
echo "$0: '$PROJECT_IDENT' already exists in current directory."
exit 3
fi
mkdir -v -p "$PROJECT_IDENT"/src
# For cd to stop echoing.
unset CDPATH
cd "$PROJECT_IDENT"/src
echo "cp: Recursive copy."
cp -r "$TEMPLATE_DIR" .
find -type f \( -name '*.pyc' -o -name '*~' \) -delete
cp -v myproject/myproject/conf/local_settings_example.py \
myproject/myproject/conf/local_settings.py
SECRET_KEY="`python -c "import random; print ''.join(random.choice('abcdefghijklmnopqrstuvwxyz0123456789') for i in xrange(60)),"`"
echo "Setting SECRET_KEY"
sed -i -e"s#installation secret key#$SECRET_KEY#" myproject/myproject/conf/local_settings.py
DB_PASSWORD="`python -c "import random; print ''.join(random.choice('abcdefghijklmnopqrstuvwxyz0123456789') for i in xrange(10)),"`"
echo "Setting db password"
sed -i -e"s#installation database password#$DB_PASSWORD#" myproject/myproject/conf/local_settings.py
echo
echo "Run this as the PostgreSQL DBA:"
echo "CREATE ROLE $PROJECT_IDENT LOGIN ENCRYPTED PASSWORD '$DB_PASSWORD';"
echo "CREATE DATABASE $PROJECT_IDENT WITH ENCODING='UTF8' LC_COLLATE='en_US.UTF-8' LC_CTYPE='en_US.UTF-8' OWNER=$PROJECT_IDENT TEMPLATE template0;"
echo
read -p"Can we continue? [Enter] "
echo
if [ "$PROJECT_IDENT" != myproject ]; then
echo "Renaming:"
mv -v myproject/myproject myproject/"$PROJECT_IDENT"
mv -v myproject "$PROJECT_IDENT"
find -type f | xargs grep -l -F myproject | xargs sed -i -e "s#myproject#$PROJECT_IDENT#g"
fi
cd ..
echo
read -p"Do you want to run git init? [y] " ANS
if [ "$ANS" != "n" ]; then
cd src/"$PROJECT_IDENT"
git init
echo
read -p"Do you want the initial commit? [y] " ANS
if [ "$ANS" != "n" ]; then
git add .
git commit -m "Initial commit based on django-new-project-template."
fi
cd ../..
fi
echo
read -p"Do you want to setup the virtualenv? Answering 's' will be like 'y', but adds --system-site-packages option. [s] " ANS
if [ "$ANS" != "n" ]; then
if [ "$ANS" != "y" ]; then
virtualenv --system-site-packages .
else
virtualenv .
fi
cd src/"$PROJECT_IDENT"
echo
../../bin/python setup.py develop
cd ../..
echo
PACKAGES="`grep -E -v '^(\s*$|#|django[^\w-])' src/$PROJECT_IDENT/requirements.pip | tr '\n' ' '`"
read -p "Do you want to install packages $PACKAGES ? [y] " ANS
if [ "$ANS" != "n" ]; then
./bin/pip install $PACKAGES
echo
echo "Django itself was not installed because you may want to develop on your"
echo "central Django installation (e.g. based on a ramdisk)."
echo "So install Django the way you like. The easiest is now to run:"
echo
echo "./$PROJECT_IDENT/bin/pip install django"
echo
fi
fi
echo "Now create a role and database as instructed above, then run"
echo
echo "./$PROJECT_IDENT/bin/manage.py syncdb"
echo
echo "and you can start to develop right away."
echo