Pages

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, November 19, 2013

Storing Shell Command Output using Python

In my development setup I need to reserve lot of corporate systems/resources to carry out the scenario testing. Once the development is frozen, I used to manually release all the reserved resources. If a development cycle for a particular release goes beyond 3 months, the number of entries which needs to be released would be more than 50(sometimes 100+). Its a big pain for me when we all were in party mode. So the simple way to automate this repeated less interesting manual task.

The manual steps which I followed earlier is given below.


(1) Run a shell command which will display the list of reserved resources with descriptions.

# mycommand -x -u siva

entry1         description1
entry2         description2
entry3         description3
entry4         description4

entryN         descriptionN
(2) Run another shell command multiple times which releases the given resource.
# commandx -d entry1  
# commandx -d entry2

# commandx -d entryN

Note: entry* is not allowed in the commandx. So I have to run this command individually for each entry.

My python script requirement is very simple.
  • Store the output of mycommand in a file
  • Read the entries one by one (first part of each line from the file)
  • Run a commandx with the above  entry

Initially I was trying with the following snippet. But it was very hard to provide multiple options and write to a file.

from subprocess import call
call(["command", "option1"]) 

Finally, I used commands to module to create a python script in a simpler way.

import commandsf = open("entries.txt", "w")
f.write(commands.getstatusoutput('mycommand -x -u siva')[1])
f.close()
f = open("entries.txt")
for line in f.readlines():
    print commands.getstatusoutput('commandx -d '+ line.split()[0])
f.close()

Sunday, November 17, 2013

Eclipse Sublime Text 2 Theme (Dark Theme)

I always like black background on my text editors while programming and working with console. Now a days, most of my time (and life) is spent with Eclipse in writing Java and Python code. For a long time, I was dreaming about Eclipse should be like Vim (or) Emacs. But recent days I like Sublime Text very much just because its theme and easy of use without knowing the keyboard shortcuts. Few days before there was a tweet which triggers me to start searching about Eclipse dark theme. Oops. There are lot of questions in StackOverflow points me to variety of solutions. I was trying to install lot of plugins from different sources. Some of them are not compatible with my Eclipse version(4.2) and most of them are not fit to my needs.

Finally found an interesting stuff from eclipsecolorthemes.org/ which is exactly what I was looking for a long time. It's the theme of Sublime Text 2. No plugin needs to be installed. Here are the steps to install and activate the same.

  1. Download the EPF from http://eclipsecolorthemes.org/?view=theme&id=66 
  2. Open your Eclipse, Import -> Preferences and choose the downloaded EPF file.
That's all. You are done. Here is how my Java and Python code area looks now.




Monday, May 18, 2009

Which Language is best for writing Linux Distro's and Applications?

The simple article from brighthub considers three popular programming languages C, Python and Java and discusses their own strength and weakness. Finally the author says that Java is the best choice.

Read out more @ http://www.brighthub.com/computing/linux/articles/34968.aspx