Skip to content
This repository
Newer
Older
100644 384 lines (235 sloc) 11.09 kb
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
1 Setting up Your Class2Go Dev Environment
2 ========================================
3
4 These instructions should help you get started setting up a dev
5 environment. You should be able to do most of your developmnet on
6 your laptop by running a local database (mysqld) and storing files
7 locally instead of in S3.
8
9 The majority of our dev team uses Macs, so the Mac instructions are
10 genereally the most up to date. But we do have some developers who
11 have had windows or Ubuntu Linux as their day-to-day dev machines, so
12 we know it works.
13
14 If you have suggestions how to improve these notes, please improve
15 them and send us a pull request!
16
17 * [Mac OS X](#mac)
18 * [Windows](#windows)
19 * [Linux](#linux)
0f2730e1 » sefk
2012-10-02 add configuring Django section (for database.py)
20 * [Configuring Django](#config)
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
21 * [Generating Test Data](#testdata)
22
23 It is a big step to go from a dev instance to a full-on deployed
24 cloud instance. Instructions for that are forthcoming.
25
26 <a id="mac"></a>
27 For Mac
28 -------------
29
30 General Instructions:
31
0f2730e1 » sefk
2012-10-02 add configuring Django section (for database.py)
32 * Set-up Python
33 * Set-up Python's virtual env
34 * Set-up Django
35 * Set-up Mysql
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
36
37 For MAC OS-X Lion: Instructions mainly taken from
38 http://www.tlswebsolutions.com/mac-os-x-lion-setting-up-django-pip-virtualenv-and-homebrew/
39
40 Some people don't have their normal user set up with write permissions
41 for all these commands that modify the environment (brew, easy_install,
42 pip). For all of those you should plan on running your own sudo
43 prefix for these.
44
45 1. Install XCode from the Apple App Store
46
47 2. Within XCode, add the command line tools: Preferences -> Download Item -> "Command Line Tools" Install button
48
49 3. Install Homebrew:
50
51 /usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
52
53 4. Install Python (we are expecting 2.7.x):
54
55 brew install readline sqlite gdbm
56 brew install python --universal --framework
57
58 5. Install mysql
59
60 brew install mysql
61 (Optional but useful for looking at the database)
62 Install phpmyadmin (?!) following the directions here:
63 http://www.djangoapp.com/blog/2011/07/24/installing-phpmyadmin-on-mac-os-x-lion/
64
65 6. Install pip, a python package manager
66
67 easy_install pip
68
69 7. Install python's virtual env
70
71 pip install virtualenv
72
73 8. Create the sophi virtual env (if you want)
74
75 virtualenv sophi-venv --no-site-packages
76
77 This should create the sophi-venv directory under the
78 directory where this README is found. All our django stuff
79 will happen in there now.
80
81 9. Start using the virtual environment that we just created.
82
83 . ./sophi-venv/bin/activate
84
85 WARNING: you need to do this from whatever shell you're using.
86 You can tell this because is puts an environment indicator at
87 the beginning of your prompt
88
89 10. Install django itself (this will be inside the virtualenv)
90
91 pip install django
92
93 11. Install MySQL-python (this will be inside the virtualenv)
94
95 pip install MySQL-python
96 (8/31 note - needed apt-get install python-mysqldb on ubuntu)
97
98 12. Install python image library (this will be inside the virtualenv)
99
100 pip install PIL
101
102 13. Install South, the database schema migration tool: (this will be inside the virtualenv)
103
104 pip install South
105
106 14. Install modules for Amazon S3
107
108 pip install django_storages
109 pip install boto
110
111 15. Install GData (2.0.17)
112
113 pip install gdata
114
115 16. Patch GData and storages
116
117 (instructions coming)
118
119 17. Install Celery ecosystem
120
121 pip install django-celery django-celery-email pytz
122
123 18. Setup initial db.
124
125 ./manage.py syncdb
126 ./manage.py migrate
127 ./manage.py syncdb --database=celery
128 ./manage.py migrate --database=celery
129
130 At this point you should be able to look at the django database in
131 your local mysql and see a bunch of c2g_* tables. Yay.
132
133
134
135 <a id="windows"></a>
136 For Windows
137 ----------------
138
139
140 Eclipse Users and/or WAMP users:
141
142 The following versions seem to be compatible:
143
144 - Python: 2.7.3
145 - Eclipse for PHP: Helios (http://download.eclipse.org/releases/helios)
146 - PyDev plugin for Eclipse: 2.5.0 (http://pydev.org/updates)
147 - Egit plugin for Eclipse: (http://download.eclipse.org/egit/updates)
148 - WAMPServer: 2.1
149
150
151 Steps:
152
153 1. Install Eclipse
154
155 2. Install Egit and configure it to the github repos (https://github.com/Stanford-Online/class2go)
156 For this you would need Jason to set you up with access to this repos.
157 Note, when configuring the Remote Push Url you'll need to add ".git" on the end:
46a2268b » jinpa
2012-10-04 fix address of repo
158 (git clone https://github.com/Stanford-Online/class2go.git)
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
159
160
161 **Requirements**
162
163 1. Prereqs:
164 If you do not have the following, install them:
165 python 2.7
166 django
167 easy_install
168 pip
169 python image library (pip install PIL)
170 django_storages
171 boto
172
173 2. Install South, the database schema migration tool: (this will be inside the virtualenv)
174 easy_install South
175
176 3. Create a database called c2g (for example).
177
178 4. Copy database.example.py to database.py.
179
180 5. In database.py, append ‘mysql’ to ENGINE, and enter the name of the database you created in step 1, and the credentials of an authorized user of the database (user ‘root’ and empty password may work on MySQL unless you specified otherwise during the MySQL setup)
181
182 6. Make sure you’re in the src/class2go/django-project directory (wherever that is for you)
183
184 7. ‘python manage.py syncdb’ followed by ‘python manage.py migrate’ to create the required database tables and make sure the schema is up to date.
185 You will be asked to create your admin account on the way. Skip it. You will later be able to create a user and promote it to admin manually using your DBMS client.
186
187 8. XX -- ‘python manage.py collectstatic ’ to copy all static files to the directory specified in settings.py.
188
189 9. ‘python manage.py runserver xxxx’ to run a dev server on port number xxxx. Example: xxxx = 8000
190
191 10. Visit localhost:xxxx in your web browser and confirm that you get a C2G page.
192
193
194
195
196 <a id="linux"></a>
197 For Linux
198 -----------------
199
200 This assumes you have mysql and python installed, and you've logged
201 into mysql and created the c2g database ('create database c2g;').
202 These instructions also include info for virtualenvwrapper, which
203 contains useful tools for virtualenv. virtualenvwrapper can also
204 be installed for Mac (and probably Windows too)
205
206 1. Install pip:
207
208 sudo apt-get install python-pip
209
210 2. Install virtualenv:
211
212 sudo pip install virtualenv
213
214 3. Install virtualenvwrapper:
215
216 sudo pip install virtualenvwrapper
217
218 4. Verify installation location of virtualenv and virtualenvwrapper:
219
220 ls /usr/local/bin/
221
222 5. Edit login script:
223
224 vim .bashrc
225
226 6. ...and add the following (without the backslashes at the start):
227
228 \# virtualenv setup -- use Distribute by default
229 export VIRTUALENV_DISTRIBUTE=true
230
231 \# virtualenvwrapper setup
232 export WORKON_HOME=~/DevEnvs
233 export PROJECT_HOME=~/DevProjects
234 export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
235 export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
236 source /usr/local/bin/virtualenvwrapper.sh
237
238 7. Source login script so env vars take effect:
239
240 source ~/.bashrc
241 (Sourcing should auto-create your virtual environment base dir)
242
243 8. Check out new virtual base directory:
244
245 ls -l DevEnvs/
246
247 9. Check out your PATH to see if /usr/local/bin comes before /usr/bin:
248
249 echo $PATH
250 (If not, add "export PATH=/usr/local/bin:$PATH" to your .bashrc)
251
252 10. Make sure PROJECT_HOME is defined
253
254 echo $PROJECT_HOME
255
256 11. Make new project directory:
257
258 mkdir -p $PROJECT_HOME
259
260 12. Issue command to set up new project subdirectory and link it to virtual env:
261
262 mkproject class2go
263
264 13. Once inside virtual env/project directory, install django:
265
266 pip install django
267
268 14. Clone class2go repo from github:
269
46a2268b » jinpa
2012-10-04 fix address of repo
270 git clone https://github.com/Stanford-Online/class2go.git .
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
271
272 15. Check out where your mysql is installed, make sure mysql_config exists in the dir:
273
274 which mysql
275 ls /usr/local/mysql (or whichever directory "which mysql" gives you)
276
277 16. Need to install mysql_config if it's not there:
278
279 sudo apt-get install libmysqlclient-dev
280 (For Macs, brew install mysql should give you the equivalent of this)
281
282 17. Might need some extra python developer stuff:
283
284 sudo apt-get install python-dev
285
286 18. Install python hooks for MySQL:
287
288 pip install MySQL-python
289
290 19. Install Python Imaging Lib:
291
292 pip install PIL
293
294 20. Install South db stuff:
295
296 pip install South
297
298 21. Install modules for Amazon S3
299
300 pip install django_storages
301 pip install boto
302
303 22. Go to django-project dir and copy over database settings file:
304
305 cd django-project/
306 cp database_example.py database.py
307
308 23. Edit file and add db name, username and password:
309
310 vim database.py
311
312 24. Run syncdb to create database tables
313
314 ./manage.py syncdb
315 Might need to issue "syncdb" command a couple times if there are errors. The
316 first time, it will ask you for username and password for the database
317
318 25. Migrate user stuff over:
319
320 ./manage.py migrate
321
322 26. Update settings file and add "static/" for STATIC_ROOT_DIR:
323
324 vim settings.py
325
326 27. Make sure directory exists, or create it:
327
328 mkdir static
329
330 28. Run collectstatic to copy stuff into your dir:
331
332 ./manage.py collectstatic
333
334 29. Run server on whatever port you want:
335
336 python manage.py runserver 8100
337
338
339 When you want to start working on your project, just do the following:
340 workon class2go
341 cd project (shouldn't be necessary, as workon command will automatically cd to project dir, but use it if you need to)
342 python manage.py runserver 8100
343
344
0f2730e1 » sefk
2012-10-02 add configuring Django section (for database.py)
345 <a id="config"></a>
346 Configuring Django
347 ------------------
348
349 The "main" dir is where the django project lives. You will spend
350 most of your time in there. All the runtime application source is
351 under main, and the manage.py script is the interface to runtime
352 command line tools.
353
354 We partition our django project settings into two settings files:
355
356 * **settings.py** - Most of the project settings are in here. This
357 shoudl be familiar to any django dev.
358
359 * **database.py** - Anything that should *not* be checked in, i.e.
360 secret keys or local configuration, should be in the database.py
361 file. Upon setting up your project one of the first things you
362 have to do is create your own database.py. There is an example
363 file to get you started, database_example.py.
364
365
366
c7e91c74 » sefk
2012-10-02 move dev setup doc to top level, convert to md, cleanup
367 <a id="testdata"></a>
368 Generating Test Data
369 -----------------------
370
371 1. Some schema mods were made so run: manage.py migrate
372
373 2. Take a look in c2g/views.py as there are some parameters that
374 affect which data gets created. Note, if you choose the delete_current_data
375 option it will delete your current django users so you'll have to
376 recreate those users if you want.
377
378 3. To run the script that populates the data do "manage.py help db_populate" first.
379 This will tell you where to setup the params for the test data.
380
381 A helper script for this exists at main/repave_dev_database.sh. It
382 drops/recreates your dev database and then does the syncdb / migrate
383 / db_populate steps so you end up with a clean database. It requires
384 a ~/.my.cnf file to know what database to talk to.
Something went wrong with that request. Please try again.