Changes between Version 3 and Version 4 of SimpleBashScriptToSetupDevelopmentEnvironment


Ignore:
Timestamp:
Dec 14, 2005, 9:29:58 PM (19 years ago)
Author:
Pedro Algarvio <ufs@…>
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SimpleBashScriptToSetupDevelopmentEnvironment

    v3 v4  
    1 Don't know why the '''sh''' wiki processor ain't workin, so to view the script, edit this page.
     1Don't know why the '''sh''' wiki processor ain't workin', maybe the server doesn't have `enscript` installed, so here's a plain and not that neat view of the script:
    22{{{
    33#!sh
    44#!/bin/bash
    55
    6 DJANGO_PROJECT="$(basename `pwd`)"
     6# Project Name, for example:
     7# DJANGO_PROJECT="$(basename `pwd`)"
     8DJANGO_PROJECT=''
     9
     10# Django's HTTP server settings
    711#SERVER_ADDR="10.1.0.1"
    8 #SERVER_PORT="8000"
     12#SERVER_PORT="8080"
    913
     14# Database Settings
    1015DJANGO_DB_NAME="${DJANGO_PROJECT}"
    1116DJANGO_DB_USER=''
    1217DJANGO_DB_PASS=''
    1318
    14 DJANGO_SECRET_UNIQUE_ID='YOUR_SECRET_UNIQUE_ID_HERE'
     19# Project's unique ID setting
     20DJANGO_SECRET_KEY='YOUR_SECRET_UNIQUE_ID_HERE'
    1521
    16 
    17 
     22# Update our Python path
    1823PYTHONPATH="$(echo $PYTHONPATH):$(dirname `pwd`)"
    1924
     25# Setup DJANGO_SETTINGS_MODULE
    2026DJANGO_SETTINGS_MODULE="${DJANGO_PROJECT}.settings"
    2127
     28# Check argument passed to script, if '-S', it starts Django's HTTP server
    2229if [ "$1" == "-S" ]; then
     30    # If SERVER_ADDR is not setup, use the default
    2331    if [ -z "${SERVER_ADDR}" ]; then
    2432        SERVER_ADDR="localhost"
    2533    fi
     34    # If SERVER_PORT is not setup, use the default
    2635    if [ -z "${SERVER_PORT}" ]; then
    2736        SERVER_PORT="8000"
    2837    fi
     38    # Start the Django's HTTP Server
    2939    django-admin.py runserver ${SERVER_ADDR}:${SERVER_PORT} \
    3040        --settings="${DJANGO_PROJECT}.settings"
     
    3444#!/bin/bash
    3545
    36 DJANGO_PROJECT="$(basename `pwd`)"
     46# Project Name, for example:
     47# DJANGO_PROJECT="$(basename `pwd`)"
     48DJANGO_PROJECT=''
     49
     50# Django's HTTP server settings
    3751#SERVER_ADDR="10.1.0.1"
    38 #SERVER_PORT="8000"
     52#SERVER_PORT="8080"
    3953
     54# Database Settings
    4055DJANGO_DB_NAME="${DJANGO_PROJECT}"
    4156DJANGO_DB_USER=''
    4257DJANGO_DB_PASS=''
    4358
    44 DJANGO_SECRET_UNIQUE_ID='YOUR_SECRET_UNIQUE_ID_HERE'
     59# Project's unique ID setting
     60DJANGO_SECRET_KEY='YOUR_SECRET_UNIQUE_ID_HERE'
    4561
    46 
    47 
     62# Update our Python path
    4863PYTHONPATH="$(echo $PYTHONPATH):$(dirname `pwd`)"
    4964
     65# Setup DJANGO_SETTINGS_MODULE
    5066DJANGO_SETTINGS_MODULE="${DJANGO_PROJECT}.settings"
    5167
     68# Check argument passed to script, if '-S', it starts Django's HTTP server
    5269if [ "$1" == "-S" ]; then
     70    # If SERVER_ADDR is not setup, use the default
    5371    if [ -z "${SERVER_ADDR}" ]; then
    5472        SERVER_ADDR="localhost"
    5573    fi
     74    # If SERVER_PORT is not setup, use the default
    5675    if [ -z "${SERVER_PORT}" ]; then
    5776        SERVER_PORT="8000"
    5877    fi
     78    # Start the Django's HTTP Server
    5979    django-admin.py runserver ${SERVER_ADDR}:${SERVER_PORT} \
    6080        --settings="${DJANGO_PROJECT}.settings"
    6181fi
    6282}}}
     83
     84To use it, just source it to update environment variables:
     85{{{
     86source env.sh
     87}}}
     88
     89To run the server:
     90{{{
     91./env -S
     92}}}
     93
     94This is of course, a file that you won't get into your revision control system, it has private data.
     95
     96Now, on your project's '''`settings.py`''', you can use(these are just parts of '''`settings.py`''' of couse):
     97{{{
     98#!python
     99DATABASE_NAME = os.environ['DJANGO_DB_NAME']
     100DATABASE_USER = os.environ['DJANGO_DB_USER']
     101DATABASE_PASSWORD = os.environ['DJANGO_DB_PASS']
     102
     103SECRET_KEY = os.environ['DJANGO_SECRET_KEY']
     104}}}
     105
     106And now, you can safely commit '''`settings.py`''' to your revision control system without double checking to see if you forgot to delete the private parts.
Back to Top