Getting Python and Fabric Installed on Windows

Amazon’s Simple Storage Solution (S3) has changed the way the Internet works, but getting files onto it isn’t as straightforward as a simple SCP. This tutorial will show you how to setup Fabric and get some files up onto S3.

Getting Fabric Setup

Fabirc is lightweight deployment toolkit – the closet analogy that I can draw is that it’s the Apache ANT of deployment. Fabric makes it easy to create an interactive script that will guide you (or others!) through the steps involved in getting your application (and all of its supporting files) onto remote servers.

So, let’s get started; If you are starting from scratch on Windows then you will want to go ahead and install python, come back when you’re done :)

Now that you have python installed, you’ll want to get hold of Setup Tools which makes it easy to download and update python modules. Once installed, you will want to add your Python Directory/scripts folder added to your system path. Once done, you can just issue:

easy_install Fabric

However, if like me, you are rocking all this on windows, then you will be informed that Fabric has failed to install with the following error message:

error: Unable to find vcvarsall.bat

Luckily, this is not a show stopper, you just need to grab MinGW, add it to your PATH and then modify your distutils.cfg file to point to it – once you’ve done that Fabric will install just fine :)

Once Fabric is installed you can summon it by issuing `fab` at the command line. Again if you’re on Windows you may be greeted with a nasty stack trace ending with:

ImportError: No module named win32api

Don’t worry, this one’s simple as well – just go and grab PyWin32 extensions and you’ll be on your way :) (BTW: Who said development on Win32 was difficult ;)

fab-installed-win32

Writing Your First Fabric Script

So now you have fabric installed it’s time to roll up our sleeves and start writing out first fabric script. By convention, fabric scripts should be named `fabfile.py`, just in the same way that you name your ANT script `build.xml`, so let’s create a one:

from fabric.api import *
from fabric.contrib.console import confirm
 
def deploy() :
	puts("Hello World!")

You can now invoke it by issuing the following at the command line (ensuring your are in the same directory you’ve saved your fabfile.py script).

fab deploy

fab-hello-world

Getting Some S3 Action With Boto

Python really is awesome, not only is it a very well thought out language, but you can also get hold of a module for nearly anything! Point in case, Boto is a Python library for interacting with Amazon Web Services; so let’s get it installed so we can use it in our Fabric script!

easy_install boto

Well that was easy ;)

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">