Painless deployment with Fabric

Deployment of code in test/staging/production  servers is one of the important part of modern web applications development cycle.

Deploying code were painful because its repetitive same tasks we have to do every time we want to push code, during deployment  if something goes wrong the application will go down too. But the scenario has changed, now we have many tools to make the deployment easier and fun. I have used Capistrano and Fabric for deployment. Found Fabric really painless and as its a Python battery, it was easier for me to adopt and get things done.

I am going to cover fundamental operations and finally a simple fabric script(like boilerplate) for writing your own fabric script.

env = its a Python dictionary like subclass where we define specific settings like password,user etc

local = runs command in  local host(where fabric script is being run)

run = runs command in a remote host

You can use these code tasks in many different ways, to do that check the Fabric Office Documentation from here.

First gist is a sample fabric script,second one is a bash script to install fabric in your ubuntu machine.

 After setting username,password and host information into the script you cab check your server’s access log by running  fab test_server latest_access_log 

I am using fabric for around two years and used for different small,medium and large projects.

There are many interesting open source projects going on top of Fabric. I found these two projects really promising.

1.Fabtools

2.Graphite_fabric

Search through github,you will find many advance level Fabric use.

Happy Coding!

Advertisements

Python Movie Data Crawler

Couple of days ago,I was talking with newly joined Engineer in our team.Suddenly I found he is a very resourceful person in terms of collecting movi.He has personal collection of movie archive which is 3TB !

So,I was really happy to find such a person as a teammate.He has three different lists of movies in text file.And shared one of the text file which contained more than couple of  hundreds movie name,I decided to write a script that scrapes movie rating from IMDB.com.I was googling if there is any public REST API available and found this website http://www.imdbapi.com/ which returns json as a search result.

The main task is couple of lines code like below:

import requests
import urllib
import json
BASE_URL = 'http://www.imdbapi.com/?'
query = {'i': '', 't': movi_name ,'tomatoes':'true'}
response = requests.get(BASE_URL+urllib.urlencode(query))
output = json.dumps(response.content, separators=(',',':'))

The output is the movie information,to grab specific result I have done some more formatting.You can check the whole script from here
Right now the script would print output like this:

Getting Movi The Pianist...
{'Plot': 'A Polish Jewish musician struggles to survive the destruction of the Warsaw ghetto of World War II.', 'Rating': '8.5', 'Title': 'The Pianist', 'Director': 'Roman Polanski', 'tomatoRating': '8.2', 'IMDB Rating': '8.5'}

In this script I have used amazing python module called Requests.

You can add more functionality like getting movie poster or writhing the movie data into
And if you want to run this script please add text file names movies.txt,like below:

The Pianist
The Avengers

Happy coding!

Activating Git Autocompletion

Git by default dont provide autocompletion,sometime its really seems boring to write the whole branch name or command.

Couple of days ago Rubayeet shared the way to activate it.

Go to this link ,copy the content of the file and save it as .git-completion.sh and add the path of the file to your bash profile.

like this

source ~/.git-completion.sh

And compile the bash profile by using following command:

source ~/.bash_profile

Write any git command and then press tab(like unix autocomplete)

you will see the branch name or command is automatically completing or showing suggestion like below

Happy coding 🙂

Fixing gitignore issue.

I faced this specific problem couple of times that in my project .gitignore file is not working,I mean not ignoring the files that I declared in the file.

After googling and browsing through the web the follwing solution worked very well for me.

git rm -r --cached .
git add .
git commit -a -m "your commit message"

Thats it, 1 st line removed already indexed files so you need to add those using “add” and need to commit the changes.