- Quickstart
- Monthly Process To Update Data and Build the Project
- Available Fabric Commands
- Building a Mac OS Python dev environment
-
Change into that directory
cd gauging_rainfall
-
Rename
TEMPLATE_development.yml
todevelopment.yml
-
Run
fab makesecret
and add the output on line 5 ofdevelopment.yml
-
Assuming you have MySQL installed, open
development.yml
and addgauging_rainfall
as the database name on line 17. Add in any username and password you might have for your MySQL install.database: host: "127.0.0.1" port: 3306 database: "gauging_rainfall" username: "root" password: ""
-
Assuming you have virtualenv and pip installed run
fab bootstrap
- This attempts to scaffold the project by:
- Creating virtualenv
- Activating the virtualenv
- Installing requirements
- Creating the database
- Applyin initial Django migrations
- Creating the Django superuser
- Running the Django development server
- This attempts to scaffold the project by:
-
Activate your virtualenv which should be named
gauging_rainfall
workon gauging_rainfall
-
At this point you should be able to run
fab run
and navigate to http://127.0.0.1:8000/ and see a Django page...
-
Run the tests
fab test
-
Use the Fabric command to fetch the latest batch of data.
fab ...
Data Functions
Development Functions
-
_run
: shortcut for base manage.py function to launch the Django development serverlocal("python manage.py runserver")
-
make
: shortcut for base manage.py function to make Django database migrations to sync the dev databaselocal("python manage.py makemigrations")
-
migrate
: shortcut for base manage.py function to apply Django database migrationslocal("python manage.py migrate")
-
superuser
: shortcut for base manage.py function to create a superuserlocal("python manage.py createsuperuser")
Bootstrapping Functions
-
requirements
: shortcut to install requirements from repository'srequirements.txt
local("pip install -r requirements.txt")
-
create_db
: Creates a database based on DATABASE variables insettings_development.py
fileconnection = None db_config = CONFIG["database"] logger.debug("Creating %s database for %s django project" % (db_config["database"], env.project_name)) create_statement = "CREATE DATABASE %s" % (db_config["database"]) try: connection = MySQLdb.connect( host = db_config["host"], user = db_config["username"], passwd = db_config["password"] ) cursor = connection.cursor(MySQLdb.cursors.DictCursor) cursor.execute(create_statement) connection.commit() except MySQLdb.DatabaseError, e: print "Error %s" % (e) sys.exit(1) finally: if connection: connection.close()
-
makesecret
: generates secret key for use in django settingskey = ''.join(random.choice(allowed_chars) for i in range(length)) print 'SECRET_KEY = "%s"' % key
-
deploy
Runsgit pull origin
on the server to pull the latest commits from the github repo. -
bootstrap
: Attempts to scaffold the project by: * Creating virtualenv * Activating the virtualenv * Installing requirements * Creating the database * Applying initial Django migrations * Creating the Django superuser * Running the Django development serverwith prefix("WORKON_HOME=$HOME/.virtualenvs"): with prefix("source /usr/local/bin/virtualenvwrapper.sh"): local("mkvirtualenv %s" % (env.project_name)) with prefix("workon %s" % (env.project_name)): requirements() time.sleep(2) create_db() time.sleep(2) migrate() time.sleep(2) local("python manage.py createsuperuser") run()
-
Assumming homebrew is installed...
-
Install homebrew python
cd /System/Library/Frameworks/Python.framework/Versions sudo rm Current brew install python brew doctor which python which pip pip install --upgrade setuptools pip install --upgrade distribute pip install virtualenv pip install virtualenvwrapper python --version source /usr/local/bin/virtualenvwrapper.sh sudo ln -s /usr/local/Cellar/python/2.7.8_2 /System/Library/Frameworks/Python.framework/Versions/Current
-
Configure $PATH variables for python, virtualenv
# homebrew path export PATH="/usr/local/bin:$PATH" # virtualenvwrapper settings export WORKON_HOME=$HOME/.virtualenvs export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_RESPECT_VIRTUALENV=true source /usr/local/bin/virtualenvwrapper.sh
-
Install MySQL via homebrew
brew remove mysql brew cleanup launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist sudo rm -rf /usr/local/var/mysql brew install mysql ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
-
Getting mysql up and running
mysql.server start mysql_secure_installation mysql -u root -p SHOW DATABASES; SET default_storage_engine=MYISAM;
-