TAB completion for fabric tasks [on OS X]

Found an excellent bash script on foobar.lu that enables tab completion on the fabric tasks defined in fabfile.py script (in case you don’t know what Fabric is, try Yuji Tomita’s article to get started with it). I just had to modify a little bit to make it work on OS X. I actually wanted to post it in their comments section, but it seems the comments are blocked on that site. So here it goes:

Install bash-completion with Homebrew

brew install bash-completion

You’ll need to add some lines in your ~/.bash_profile file to finish the installation. This will create an etc/bash_completion file under /usr/local directory. Now open the ~/.bash_profile file and add the following lines at the end:

function _fab_complete() {
    local cur
    if [ -f "fabfile.py" ]; then
        cur="${COMP_WORDS[COMP_CWORD]}"
        COMPREPLY=( $(compgen -W "$(fab -F short -l)" -- ${cur}) )
        return 0
    else
        # no fabfile.py found. Don't do anything.        
        return 1
    fi
}
if [ -f /usr/local/etc/bash_completion ] && ! shopt -oq posix; then
    . /usr/local/etc/bash_completion
    complete -o nospace -F _fab_complete fab
fi

Reload the file with source ~/.bash_profile command, navigate to your project directory where your Fabric script is located and try it out yourself.

Advertisements

Making Chrome Canary the default browser [OS X]

This post is for Apple OS X users. This is a nice trick for setting Google Chrome Canary as the default browser in your OS X. You can’t do this within Canary itself. Since this is a nightly build edition of Chrome browser, the developers have intentionally disabled this feature. So to have Canary as your default browser:

  1. Launch Safari
  2. Click on Preferences
  3. Under the tab General, choose Google Chrome Canary as the value for Default web browser
That should do the trick!
Update: Since this post is getting quite a lot of attention I figured I should update this with a cautionary tale. You should know the Canary is an unstable and untested build of Google Chrome. When the browser gets updated behind the scene, you may be introduced to a few bugs. One such bug deleted all the links in the Bookmark bar! And since my bookmarks are synced across browsers and devices using Xmarks, I lost the bookmarks in all my browsers in all my machines! I launched Firefox and watched the links disappear before my eyes and cried out in horror! Fortunately Xmarks keeps backups of your links in the cloud, so I was able to download the backup files and restore them. But I stopped using Canary since then.
Morale of the story: use with caution!

Tethering Nokia N73 with Macbook Pro

Tethering

Tethering your laptop with an EDGE enabled cellphone is an ideal solution for “Internet on the go” problem.

I have a Nokia N73 which  I wished to connect via Bluetooth with my Macbook Pro running on OS X 10.5.7. Unfortunately, it wasn’t a walk in the park as I expected everything with Mac to be. After spending quite some time searching on Google and with the help of some very useful resources(which I’ve listed at the end of this post). I was finally able to browse the Net on the macbook through the phone. I’ll outline the process below

1. Download the Modem Scripts

Although OS X ships with modem scripts for Nokia phones, they don’t work for all the models. Ross Barkman to the rescue! His website contains customized modem scripts for a large array of cellphone brands and models. N73 is 3G enabled so you’ll need Nokia 3G scripts. Download the zip file and extract it, copy the scripts(Nokia 3G CID 1, 2 and 3) and paste them inside [RootDrive]/Library/Modem Scripts folder.

2. Pair the phone with the Macbook

This step is pretty easy to follow. Click on the Bluetooth icon on the Menu bar(go to System Preferences > Bluetooth if (it’s not there) and select “Set up Bluetooth Device”. Follow the steps to pair the phone, make sure you’ve chosen “Access the Internet” option at the final step.

3. Connect to Internet

  • Go to System Preferences > Network and select Bluetooth from the left pane.
  • Click on “Advanced” button. Under the “Modem” tab, select “Other” for “Vendor” option.
  • Select “Nokia 3G CID 1” for “Vendor” option.
  • Select “Ignore dial tone when dialing” from “Dial Mode” options
  • Click OK and now back to Network Menu. Enter your phone’s APN in the “Telephone Number” box. You can know your APN from your phone’s Menu > Tools > Settings > Connection menu.
  • Click “Apply” and then click “Connect”.

You should be connected to Net by now.

Resources

  1. Ross Barkman’s site. It has modem scripts for several phone brands.
  2. A similar post on tethering.

Update Tao of Mac has a very detailed post on this topic.

Deploying Django application on mod_python and Mini Mac

Server  : Apache 2.2
OS      : Mac OS X 10.5.4 
Python  : Version 2.5.1
Django  : Version 1.0.2 final
Machine : Mac Mini

mac finder

Mod_python is a loadable Apache module which embeds the Python interpreter, so Python code can be run in-process by Apache. To deploy and run your Django application in an Apache web server you have to

  1. Download and install mod_python
  2. Load it in Apache
  3. Configure Apache to run the Django app.

In this post I’m going to share my experience on how to do all that on a Mac Mini that runs on OS X 10.5.

The Software & Hardware

Here was my system configuration

  • Server  : Apache 2.2
  • OS      : Mac OS X 10.5.4 
  • Python  : Version 2.5.1
  • Django  : Version 1.0.2 final
  • Machine : Mac Mini running on 2.0 GHz Intel Core 2 Duo processor with 2GB RAM

1. Get the mod_python source

Check out the mod_python source code from the remote SVN repository*

$ svn co https://svn.apache.org/repos/asf/quetzalcoatl/mod_python/trunk/ mod_python_src/

*The reason I’m downloading the source from an SVN trunk and not from the Apache website, is because the source available at the later one isn’t properly patched for Mac Mini’s architecture. In my earlier attempts, when I downloaded and built mod_python from stable releases, Apache was failing to start whenever the mod_python module was being loaded using the LoadModule Directive.

2. Build the source

$ cd mod_python_src

$ ./configure --with-apxs=/usr/sbin/apxs

$ make

$ sudo make install

3. Configure Apache to load mod_python when it starts

Open the Apache configuration file

$ sudo vi /etc/apache2/httpd.conf

Add the following line to the file 

LoadModule python_module libexec/apache2/mod_python.so

Now restart Apache

$ sudo /usr/sbin/apachectl restart

4. Configure Apache for Django 

Let’s suppose you have a Django app callled “mysite”. Copy you the directory to the Apache DocumentRoot

$ cp -r /path/to/mysite /Library/WebServer/Document/

Add the following lines to the httpd.conf file

<Location "/mysite">

    SetHandler python-program

PythonPath "['/Library/WebServer/Documents'] + sys.path"

     PythonHandler django.core.handlers.modpython

     SetEnv DJANGO_SETTINGS_MODULE mysite.settings

PythonAutoReload On

PythonDebug On

</Location>

This’ll make Apache to route any requests under URL “/mysite” to the mod_python handler. It passes the value of DJANGO_SETTINGS_MODULE so mod_python knows which settings to use.

Now restart Apache and go to the site http://localhost/mysite

If it works then congratulations! You’ve just deployed your app on Apache!

Troubleshooting tip(s)

If Apache fails to launch after you’ve installed and loaded mod_python, run it in debugging mode

$ sudo /usr/sbin/httpd -X

Look for any error message printed in the terminal, copy it and google it. You may find a solution online.

You should also check out