Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
433 lines (266 sloc) 12.4 KB

Setting up Your Class2Go Dev Environment

These instructions should help you get started setting up a dev environment. You should be able to do most of your developmnet on your laptop by running a local database (mysqld) and storing files locally instead of in S3.

The majority of our dev team uses Macs, so the Mac instructions are genereally the most up to date. But we do have some developers who have had windows or Ubuntu Linux as their day-to-day dev machines, so we know it works.

If you have suggestions how to improve these notes, please improve them and send us a pull request!

It is a big step to go from a dev instance to a full-on deployed cloud instance. Instructions for that are forthcoming.

For Mac

General Instructions:

  • Set-up Python
  • Set-up Python's virtual env
  • Set-up Django
  • Set-up Mysql

For MAC OS-X Lion: Instructions mainly taken from

Some people don't have their normal user set up with write permissions for all these commands that modify the environment (brew, easy_install, pip). For all of those you should plan on running your own sudo prefix for these.

  1. Install XCode from the Apple App Store Version 4.5 or later

  2. Within XCode, add the command line tools: Preferences -> Download -> "Command Line Tools" -> Install button

  3. Install Homebrew:

    /usr/bin/ruby -e "$(curl -fsSkL"
  4. Install Python (we are expecting 2.7.x):

    brew install readline sqlite gdbm  
    brew install python --universal --framework  
  5. Install mysql

    brew install mysql  

    (Optional but useful for looking at the database)
    Install phpmyadmin (?!) following the directions here:

  6. Install pip, a python package manager

    easy_install pip
  7. Install python's virtual env

    pip install virtualenv 
  8. Create the class2go virtual env (if you want)

    virtualenv class2go-venv --no-site-packages    

    This should create the class2go-venv directory under the directory where this README is found. All our django stuff will happen in there now.

  9. Start using the virtual environment that we just created.

    . ./class2go-venv/bin/activate

    WARNING: you need to do this from whatever shell you're using. You can tell this because is puts an environment indicator at the beginning of your prompt

  10. Install django itself (this will be inside the virtualenv)

    pip install django
  11. Install MySQL-python (this will be inside the virtualenv)

    pip install MySQL-python
  12. Install python image library (this will be inside the virtualenv)

    pip install PIL
  13. Install South, the database schema migration tool: (this will be inside the virtualenv)

    pip install South
  14. Install modules for Amazon S3

    pip install django-storages
    pip install boto
  15. Install GData (2.0.17)

    pip install gdata
  16. Install Celery ecosystem

    pip install django-celery django-celery-email pytz
  17. Install test environment dependencies:

    pip install mock nose django_nose
  18. Setup the account and database in MySql

    create database class2go;  
    grant all on class2go.* to class2go@'localhost' identified by 'class2gopw';  
    grant all on class2go.* to class2go@'' identified by 'class2gopw';  
  19. Set up some folders for logs and the celery database.

    Put them somewhere writable. Make sure the django entry for LOGGING_DIR and the entry for DATABASES.celery.NAME match these locations.

    mkdir /home/account/django-logs/
    mkdir /home/account/sqlite3/  
  20. In the main folder, make a copy of to and edit the DATABASES strings as follows substituting proper values for your system.

    DATABASES = {  
        'default': {  
            'ENGINE': 'django.db.backends.mysql',  
            'NAME': 'class2go',  
            'USER': 'class2go',  
            'PASSWORD': 'class2gopw',  
            'HOST': '',  
            'PORT': '',  
        'celery': {  
            'ENGINE': 'django.db.backends.sqlite3',  
            'NAME': '/Users/account/sqlite3/celerydb.sqlite',  
  21. Setup initial db from the main folder

    ./ syncdb  
    ./ migrate  
    ./ syncdb --database=celery  
    ./ migrate --database=celery  

    At this point you should be able to look at the django database in your local mysql and see a bunch of c2g_* tables. Yay.

  22. From the main folder, run server on whatever port you want:

    python runserver 8100
  23. Visit localhost:8100 in your web browser and confirm that you get a C2G page.

For Windows

Eclipse Users and/or WAMP users:

The following versions seem to be compatible:


  1. Install Eclipse

  2. Install Egit and configure it to the github repos ( For this you would need Jason to set you up with access to this repos. Note, when configuring the Remote Push Url you'll need to add ".git" on the end: (git clone


  1. Prereqs: If you do not have the following, install them: python 2.7 django easy_install pip python image library (pip install PIL) django_storages boto

  2. Install South, the database schema migration tool: (this will be inside the virtualenv) easy_install South

  3. Create a database called c2g (for example).

  4. Copy to

  5. In, 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)

  6. Make sure you’re in the src/class2go/main directory (wherever that is for you)

  7. ‘python syncdb’ followed by ‘python migrate’ to create the required database tables and make sure the schema is up to date. 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.

  8. XX -- ‘python collectstatic ’ to copy all static files to the directory specified in

  9. ‘python runserver xxxx’ to run a dev server on port number xxxx. Example: xxxx = 8000

  10. Visit localhost:xxxx in your web browser and confirm that you get a C2G page.

For Linux

This assumes you have mysql and python installed, and you've logged into mysql and created the c2g database ('create database c2g;'). These instructions also include info for virtualenvwrapper, which contains useful tools for virtualenv. virtualenvwrapper can also be installed for Mac (and probably Windows too)

  1. Install pip:

    sudo apt-get install python-pip
  2. Install virtualenv:

    sudo pip install virtualenv
  3. Install virtualenvwrapper:

    sudo pip install virtualenvwrapper
  4. Verify installation location of virtualenv and virtualenvwrapper:

    ls /usr/local/bin/
  5. Edit login script:

    vim .bashrc
  6. ...and add the following:

    # virtualenv setup -- use Distribute by default
    # virtualenvwrapper setup
    export WORKON_HOME=~/DevEnvs 
    export PROJECT_HOME=~/DevProjects
    export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
    export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
    source /usr/local/bin/
  7. Source login script so env vars take effect:

    source ~/.bashrc

    (Sourcing should auto-create your virtual environment base dir)

  8. Check out new virtual base directory:

    ls -l DevEnvs/
  9. Check out your PATH to see if /usr/local/bin comes before /usr/bin:

    echo $PATH

    (If not, add export PATH=/usr/local/bin:$PATH to your .bashrc)

  10. Make sure PROJECT_HOME is defined

    echo $PROJECT_HOME
  11. Make new project directory:

    mkdir -p $PROJECT_HOME 
  12. Issue command to set up new project subdirectory and link it to virtual env:

    mkproject class2go
  13. Once inside virtual env/project directory, install django:

    pip install django
  14. Clone class2go repo from github:

    git clone .
  15. Check out where your mysql is installed, make sure mysql_config exists in the dir:

    ls `which mysql`
  16. Need to install mysql_config if it's not there:

    sudo apt-get install libmysqlclient-dev
  17. Might need some extra python developer stuff:

    sudo apt-get install python-dev
  18. Install python hooks for MySQL:

    pip install MySQL-python
  19. Install Python Imaging Lib:

    pip install PIL
  20. Install South db stuff:

    pip install South
  21. Install modules for Amazon S3

    pip install django_storages
    pip install boto
  22. Install GData (2.0.17)

    pip install gdata
  23. Install Celery ecosystem

    pip install django-celery django-celery-email pytz
  24. Install test environment dependencies:

    pip install mock nose django_nose
  25. Go to "main" dir and copy over database settings file:

    cd main
  26. Edit file and add db name, username and password (see mac instructions)

  27. Run syncdb to create database tables

    ./ syncdb

    Might need to issue "syncdb" command a couple times if there are errors. The first time, it will ask you for username and password for the database

  28. Migrate user stuff over:

    ./ migrate
  29. Update settings file and add "static/" for STATIC_ROOT_DIR:

  30. Make sure directory exists, or create it:

    mkdir static
  31. Run collectstatic to copy stuff into your dir:

    ./ collectstatic
  32. Run server on whatever port you want:

    python runserver 8100

When you want to start working on your project, just do the following:

    # this should change to the correct virtualenv and cd you to project dir
    workon class2go
    python ./ runserver 8100

Configuring Django

The "main" dir is where the django project lives. You will spend most of your time in there. All the runtime application source is under main, and the script is the interface to runtime command line tools.

We partition our django project settings into two settings files:

  • - Most of the project settings are in here. This shoudl be familiar to any django dev.

  • - Anything that should not be checked in, i.e. secret keys or local configuration, should be in the file. Upon setting up your project one of the first things you have to do is create your own There is an example file to get you started,

Generating Test Data

  1. Some schema mods were made so run: migrate

  2. Take a look in c2g/ as there are some parameters that affect which data gets created. Note, if you choose the delete_current_data option it will delete your current django users so you'll have to recreate those users if you want.

  3. To run the script that populates the data do " help db_populate" first. This will tell you where to setup the params for the test data.

A helper script for this exists at main/ It drops/recreates your dev database and then does the syncdb / migrate / db_populate steps so you end up with a clean database. It requires a ~/.my.cnf file to know what database to talk to.

Jump to Line
Something went wrong with that request. Please try again.