<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Talk Funnel &#187; programming</title>
	<atom:link href="http://ramin.firoozye.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://ramin.firoozye.com</link>
	<description>Talk Funnel: Ramin Firoozye&#039;s (occasional) Public Whisperings</description>
	<lastBuildDate>Fri, 21 Oct 2011 14:14:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Django bash shell shortcuts</title>
		<link>http://ramin.firoozye.com/2008/03/03/django-bash-shell-shortcuts/</link>
		<comments>http://ramin.firoozye.com/2008/03/03/django-bash-shell-shortcuts/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 20:45:08 +0000</pubDate>
		<dc:creator>ramin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://ramin.firoozye.com/2008/03/03/django-bash-shell-shortcuts/</guid>
		<description><![CDATA[SmileyChris had a post up recently on setting up bash aliases for Django. He uses the classic alias command which works for one-line shortcuts. I got inspired to put mine up too, but if you want to do something more elaborate, bash gives you this handy scripting language along with &#8216;shell commands&#8217; so you can [...]]]></description>
			<content:encoded><![CDATA[<p>SmileyChris had <a href="http://smileychris.tactful.co.nz/ramblings/django-managepy-alias/" target="_blank">a post</a> up recently on setting up bash aliases for Django. He uses the classic <code>alias</code> command which works for one-line shortcuts. I got inspired to put mine up too, but if you want to do something more elaborate, <code>bash</code> gives you this handy scripting language along with &#8216;shell commands&#8217; so you can do something a bit more involved.</p>
<p>What I tried to do with these shortcuts was to create a set of mini-commands that quickly do what you need to do when developing Django. It might help someone out and squeeze an extra 2-3.5 microseconds each time you run a Django command. Hey, it all adds up.</p>
<p>In my case, I keep the directory for all my Django projects in a single &#8216;source&#8217; directory so I can quickly jump in and out of them. The shell commands makes that assumption too. If your projects are all over the place, you&#8217;ll have to tweak things &#8212; but I&#8217;d suggest doing some housekeeping and moving everything to a common directory to help keep things neat and tidy.</p>
<p>To use these, copy the lines to the bottom of your <code>~/.bashrc</code> or <code>~/.bash_profile</code>. If you don&#8217;t see one of these in your home directory, remember that most *nix shells ignore files starting with a &#8216;.&#8217; (period) so you&#8217;ll want to do something like:</p>
<p><code>% ls -al</code></p>
<p>To see all your files in the current directory. If you really don&#8217;t have one, then create a <code>.bash_profile</code> and put the following lines inside. You&#8217;ll want to customize the first four environment variables to point them to directories in your system. The ones there are samples, but once you set it up once, you&#8217;ll never have to worry about it again.</p>
<p>A minor caveat: These have been tested on a Mac OS-X Leopard. YM-will-most-likely-V. On with the code.<br />
<code><br />
<blockquote>
# Django shortcuts</p>
<p># CHANGE: to directory where you installed Django sources.<br />
DJANGOROOT=/dev/djangoproject <br />
export DJANGOROOT</p>
<p># CHANGE: to admin bin scripts directory under Django.<br />
# This should work for the svn version.<br />
DJANGOBIN=$DJANGOROOT/django/bin<br />
export DJANGOBIN<br />
PATH=$PATH:$DJANGOBIN:<br />
export PATH</p>
<p># CHANGE: to TCP port for testing.<br />
# You go to http://localhost:8008 to hit the test sever.<br />
DJANGOTESTPORT=8008<br />
export DJANGOTESTPORT</p>
<p># CHANGE: to base directory where you keep your Django projects.<br />
DJANGOPROJECTBASE=~/Work/django<br />
export DJANGOPROJCTBASE</p>
<p># ---------------- Django shell commands ------------------</p>
<p>function django() {<br />
&nbsp;&nbsp;echo "dadmin&nbsp;- Basic django-admin"<br />
&nbsp;&nbsp;echo "dproj&nbsp;&nbsp;- set up (show) default django project"<br />
&nbsp;&nbsp;echo "dsrc&nbsp;&nbsp;&nbsp;- jump to Django projects home directory"<br />
&nbsp;&nbsp;echo "dls&nbsp;&nbsp;&nbsp;&nbsp;- list current projects in Django projects home directory"<br />
&nbsp;&nbsp;echo "dcd&nbsp;&nbsp;&nbsp;&nbsp;- jump to current project directory"<br />
&nbsp;&nbsp;echo "dstart&nbsp;- start a new project in the home directory"<br />
&nbsp;&nbsp;echo "dapp&nbsp;&nbsp;&nbsp;- create a new application under the current project"<br />
&nbsp;&nbsp;echo "dsync&nbsp;&nbsp;- Run syncdb and synchronize model with DBMS"<br />
&nbsp;&nbsp;echo "drun&nbsp;&nbsp;&nbsp;- run current project in test server"<br />
}</p>
<p>function dsrc() {<br />
&nbsp;&nbsp;cd $DJANGOPROJECTBASE;<br />
}</p>
<p>function dls() {<br />
&nbsp;&nbsp;ls $DJANGOPROJECTBASE;<br />
}</p>
<p>function dadmin() {<br />
&nbsp;&nbsp;python django-admin.py $*;<br />
}</p>
<p>function dstart() {<br />
&nbsp;&nbsp;src;<br />
&nbsp;&nbsp;python django-admin.py startproject $*;<br />
}</p>
<p>function dproj() {<br />
&nbsp;&nbsp;if [ $# -eq 0 ]<br />
&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;if [ $DJANGOCURRENTPROJECT ]<br />
&nbsp;&nbsp;&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "Current project is: $DJANGOCURRENTPROJECT";<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "Run 'dproj
<projectname>' first";<br />
&nbsp;&nbsp;&nbsp;&nbsp;fi<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;if [ -d $DJANGOPROJECTBASE/$1 ]<br />
&nbsp;&nbsp;&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DJANGOCURRENTPROJECT=$1;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export DJANGOCURRENTPROJECT;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DJANGO_SETTINGS_MODULE="$DJANGOPROJECTBASE/$DJANGOCURRENTPROJECT";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;export DJANGO_SETTINGS_MODULE;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "Current project set to: $1";<br />
&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo "Project directory '$1' doesn't exist."<br />
&nbsp;&nbsp;&nbsp;&nbsp;fi<br />
&nbsp;&nbsp;fi<br />
}</p>
<p>function dcheck() {<br />
&nbsp;&nbsp;if [ $DJANGOCURRENTPROJECT ]<br />
&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;cd $DJANGO_SETTINGS_MODULE;<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 0;<br />
&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo "Run 'dproj
<projectname>' first";<br />
&nbsp;&nbsp;&nbsp;&nbsp;return 1;<br />
&nbsp;&nbsp;fi<br />
}</p>
<p>function dapp() {<br />
&nbsp;&nbsp;if [ dcheck ]<br />
&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;python manage.py startapp $*;<br />
&nbsp;&nbsp;fi<br />
}</p>
<p>function dcd() {<br />
&nbsp;&nbsp;dcheck;<br />
}</p>
<p>function dsync() {<br />
&nbsp;&nbsp;if [ dcheck ]<br />
&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;python manage.py syncdb;<br />
&nbsp;&nbsp;fi<br />
}</p>
<p>function drun() {<br />
&nbsp;&nbsp;if [ dcheck ]<br />
&nbsp;&nbsp;then<br />
&nbsp;&nbsp;&nbsp;&nbsp;python manage.py runserver $DJANGOTESTPORT$*;<br />
&nbsp;&nbsp;fi<br />
}
</p></blockquote>
<p></code><br />
To get a reminder of how it all works, just type</p>
<blockquote><p><code>% django</code></p></blockquote>
<p>To see a list of current projects, use:</p>
<blockquote><p><code>% dls</code></p></blockquote>
<p>To start a new Django project, just go:</p>
<blockquote><p><code>% dstart <i>projectname</i></code></p></blockquote>
<p>To set the current active project:</p>
<blockquote><p><code>% dproj <i>projectname</i></code></p></blockquote>
<p>This checks to make sure the project exists under the base project directory. To quickly jump to the current project directory, you use:</p>
<blockquote><p><code>% dcd</code></p></blockquote>
<p>To create a new application under the current project use:</p>
<blockquote><p><code>% dapp <i>appname</i></code></p></blockquote>
<p>Then you add the <i>appname</i> to your project&#8217;s <code>settings.py</code> file and you&#8217;re good to go. Once you&#8217;ve defined your model, run this to sync up the database and the model:</p>
<blockquote><p><code>% dsync</code></p></blockquote>
<p>And every time you want to run the test server for the current project, just run:</p>
<blockquote><p><code>% drun</code></p></blockquote>
<p>And assuming you didn&#8217;t change the <code>DJANGOTESTPORT</code> variable above, in the browser you go to:</p>
<blockquote><p><code>http://localhost:8008/</code></p></blockquote>
<p>or if <code>localhost</code> isn&#8217;t defined in your <code>/etc/hosts</code> file, you can also use:</p>
<blockquote><p><code>http://127.0.0.1:8008</code></p></blockquote>
<p>Under Windows, the easiest way to run this is to install <a href="http://cygwin.com/" target="_blank">Cygwin</a> and then run <code>bash</code> from there.</p>
<p>Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://ramin.firoozye.com/2008/03/03/django-bash-shell-shortcuts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: ramin.firoozye.com @ 2012-02-05 03:04:42 -->
