permutations of string

I happen to see an movie where police inspector gets a jumbled word as clue , he writes all permutations
of string on paper. so I wrote an algorithm/python program so that it returns all permutations of given string. atleast now the police officer will save his time :) hehe just kidding .

here is the python program.

how to execute this ?
python ./permutations  "word"

'''
Created on Apr 29, 2012

@author: vedara
'''
import sys
if(len(sys.argv) < 2):
    print "enter ./permutations.py "
    exit(0)
 
s=str(sys.argv[1])
out=[]
s_len=len(s)
used=[]

 
def permute(in_s1,out,used,length,reclength):
    i=0
 
    if(reclength==length):
        output=""
        print(output.join(out))
         

    while i < length:
     
        if(used[i]):
            i=i+1
            continue
     
        out[reclength]=in_s1[i]
        used[i]=1
        permute(in_s1,out,used,length,reclength+1)
        used[i]=0    
        i=i+1
   
for i in s:
    out.append(i)
 
i=0

while i < len(s):
    used.append(0)
    i=i+1
   
permute(s,out,used,len(s),0)
out=[]
used=[]

email me if indentation of program changes...if indentation changes program wont compile in python.. 

example : python permutations.py hey

output:
 hey 
 hye
 ehy
 eyh
 yhe
 yeh

Python tips for Automation

Why python for Automation?
if we write shell scripts for automation, it wont work on windows. if we write batch scripts it wont work on Unix platforms. so lets choose language which is platform independent, fast and development time is less.
It is none other than Python :) . Python is used not only for Scripting. it is programming language can be used for GUI , sockets, scripting, web programming :) .

I have been automating many test cases for performance testing team . It saves 20 hours of time per week. Going in future , routine tasks will be automated using Python :) . no need of hiring testers to do routine tasks which keep repeating every week or every month .

common things we use while writing Python scripts for automation .

1) coping files from one location to other.
2) check whether file exists
3) check which OS it is
4) invoking shell script or other executable from Python script
5) reading the Configuration files which are of Windows Config files .INI format  like below
   [boot]
timeout=30
quick=yes


the Answers are below

1a) import shutil
      shutil.copy(src,dest)

2a) import os
       file="/tmp/file1.txt"
      os.access(file, os.F_OK)

3a)
   import sys
  print(sys.platform)

4a)
    import subprocess
   p=subprocess.Popen(command,shell=True)
        p.wait() '''waits until process is done '''

5a) 
here is the program called ConfigChanger.py which takes 2 files as command line args. 
invoke as  $python ./ConfigChanger  file1.INI file2.INI . This changes file1.INI according to file2.INI . the common attributes present in file2.INI will be moved to file1.INI and new attributes present in file1.INI will not be changed . its like set operations file1 n file2 in file1 and file1 - file2 in file1. 

import ConfigParser
import sys 

if(len(sys.argv) < 3):
    print "\n python ./NQSConfigParser.py "
config=ConfigParser.ConfigParser() # source file2.INI
config.read(sys.argv[2]);   

config1=ConfigParser.ConfigParser() # destination file1.INI
config1.read(sys.argv[1]); 


list_sections=[ ];
i=0
j=0
index=()
Source={}
Dest={}
#element=[ ];
key=" "
values=" "

sec=config.sections() # source
sec1=config1.sections() 
tmpfile="%s_tmp"%(sys.argv[1])
nqsconfig_tmp=open(tmpfile,"wb") #destination file
for section in sec1:
    
    Dest_items=config1.items(section)
    if section in sec:
        Source_items=config.items(section)
    print "\n[%s]" %section
    section_write="[%s]\n" %section
    nqsconfig_tmp.write(section_write)
    
    for f in Source_items:
        key=str(f[0]).upper()
        value=f[1::]
        values=" "
        for val in value:
            values = values + val
        
        if values.find(";")== -1:
            values= values+";"    
        Source[key]=values
        

    for f in Dest_items:
        key=str(f[0]).upper()
        value=f[1::]
        values=" "
        for val in value:
            values = values + val
            if values.find(";")== -1:
                values= values+";"
        Dest[key]=values
        if key in Source:
            attribute="%s = %s\n" %(key, Source[key])
            nqsconfig_tmp.write(attribute)
        else:
            attribute="%s = %s\n" %(key, Dest[key])
            nqsconfig_tmp.write(attribute)

Dest={}
Source={}
nqsconfig_tmp.close()

Solaris - IO benchmarking - vdbench

do you want to measure performance of disks on solaris ?. then we have excellent tool called vdbench.

Initially I used to write c++ program which read/writes chunks of data and measure the Input/Output using iostat command. then i came across called vdbench which simulates read/write on given partition of hard disk .


go to http://sourceforge.net/projects/vdbench/ to download the tool and unzip it. 


1) create a file of 100 MB . $mkfile 100m /benchmark/file1 
2)now lets generate read/writes on this file /benchmark/file1 which is mounted on partition you want to benchmark IO. 

there are example files that come with installation like example1, example2 etc. we can edit example1 file ,

*Example 1: Single run, one raw disk

*SD:    Storage Definition
*WD:    Workload Definition
*RD:    Run Definition
*
sd=sd1,lun=/benchmark/file1
wd=wd1,sd=sd1,xfersize=4194304,rdpct=50
rd=run1,wd=wd1,iorate=100,elapsed=10,interval=1

* lun specifies the file, rawdisks etc.
*rdpct means read percentage. here i gave rdpct=50 means read % is 50, write % is 50. 
*xfersize is 4194304 bytes which means vdbench generates 4 MB of load. 
*elapsed is how many samples we need . we get 10 samples here 

3) issue the command $ vdbench -f example1 
Apr 20, 2012  interval        i/o   MB/sec   bytes   read     resp     resp     resp    cpu%  cpu%
                             rate  1024**2     i/o    pct     time      max   stddev sys+usr   sys
07:25:53.061         1      92.00  1559.74 4194304  53.26   13.379   26.133    2.459     2.1   2.0
07:25:54.021         2     108.00  1831.00 4194304  50.00   12.848   16.296    1.704     2.5   2.3
07:25:55.019         3     114.00  1932.72 4194304  54.39   12.824   24.141    2.158     2.5   2.4
07:25:56.018         4      93.00  1576.69 4194304  46.24   12.893   27.468    2.312     2.1   2.0
07:25:57.017         5     103.00  1746.23 4194304  52.43   12.491   15.294    1.514     2.2   2.1
07:25:58.016         6     118.00  2000.53 4194304  43.22   13.324   30.540    2.848     2.7   2.5
07:25:59.018         7     103.00  1746.23 4194304  44.66   12.661   16.723    1.527     2.2   2.1
07:26:00.016         8     102.00  1729.27 4194304  44.12   12.657   15.030    1.419     2.2   2.1
07:26:01.016         9     116.00  1966.63 4194304  45.69   12.635   16.636    1.483     2.5   2.5
07:26:02.019        10      90.00  1525.83 4194304  47.78   12.499   14.357    1.419     1.9   1.8
07:26:02.026  avg_2-10     105.22  1783.90 4194304  47.62   12.770   30.540    1.908     2.3   2.2
07:26:02.489 Vdbench execution completed successfully

the last line avg_2-10 is avg of all samples.

for 4mb read/writes here the response time is 12 secs. cpu usage is 2.3%


BITS Pilani MS Dissertation experience


I went to BITS Pilani hyderabad campus, I had instructed by security guys who

told me room number for Viva attendance. I took 20 mins to locate the room :) as campus is very

big .

we need to fill attendance form, and will be given evaluation sheet from BITS

representative . we need to carry the sheet with us when we go for viva and handover to

professor. The BITS representative will collect the evaluation sheet given by your Supervisor + Additional examiner. so grade given by BITS faculty + grade given by your supervisor will be final result.

each student is assigned to a faculty member and time slot is arranged for each student.

Student need to carry his/her own laptop to give presentation (or demo if any ) as they cant trust

pendrive or CDs due to viruses.

my time slot was 11:30 am and faculty chamber number was given. so at 11:30 I went to
faculty room and met the Professor. I gave the context of my project and started presentation .

The professor raised few questions and I answered them . Luckily I
got a very cool professor who has good knowledge and expert in operating systems. so she
grapsed my project technical details easily.

After completing my presentation/viva, I gave demo about my project .

By 12:00 pm the process is over, and professor said that i can visit BITS campus and library. I just

roamed in campus for 1 hour and campus is awesome.

Again I took 15 mins to come out from huge campus :) .

Finally I completed my MS in 2012, which I started in 2010.

I Thank my guide Nathan Reynolds for his Ideas, my manager for giving me excellent grade

from his evaluation and finally my wife for not asking for outings when I was reading,

coding etc.

I thank my parents who funded for my 1st sem :) .