xlsxwriter considering worksheet.write as tuple ???

2016-09-26 Thread M2
Hello
The program is designed to collect different statistics from servers across the 
network and populate in excel sheet.
Library : xlsxwriter.0.9.3

Below is the Snip of code being used
#! /usr/bin/python

import xlsxwriter
import os;
import subprocess;
import sys;
import os.path;


workbook=xlsxwriter.Workbook('Turnover_sheet.xlsx');

tools_sheet=workbook.add_worksheet('Citi Tools Verification');

hw_sheet=workbook.add_worksheet('Hardware Verification');

os_sheet=workbook.add_worksheet('OS Verification');

build_spec_sheet=workbook.add_worksheet('Build Specs Verification');

info_sheet=workbook.add_worksheet('Server Handover Info');

stan_sheet=workbook.add_worksheet('Standards');

sup_sheet=workbook.add_worksheet('Support Information');

tools_sheet.write('A3', 'Device Name', table_head);

tools_sheet.write('B3', 'Machine Category', table_head);

tools_sheet.write('C3', 'OS Platform', table_head);


hw_sheet.merge_range('A1:N1', 'Hardware Information', head);

hw_sheet.merge_range('A2:A3', 'Device Name', table_head);

hw_sheet.merge_range('B2:B3', 'CPU / vCPU Count', table_head);


os_sheet.merge_range('A2:A3', 'Server Name', table_head);

os_sheet.merge_range('B2:B3', 'Kdump Config', table_head);
os_sheet.merge_range('C2:C3', 'Grub Config', table_head);


info_sheet.write('A1', 'Server Name', table_head);

info_sheet.write('B1', 'Serial Number', table_head);

info_sheet.write('C1', 'Backup Type', table_head);


stan_sheet.write('A1', 'Item', table_head);

stan_sheet.write('B1', 'Standard', table_head);

stan_sheet.write('C1', 'Comments', table_head);


def data_collection(fqdn,counter):
counter=int(counter);
red_counter=(int(counter))-2;
s_count='A'+str(counter);
s_r_count='A'+str(red_counter);
tools_sheet.write(s_count,fqdn,cell_format);
hw_sheet.write(s_count,fqdn,cell_format);
os_sheet.write(s_count,fqdn,cell_format);
info_sheet.write(s_r_count,fqdn,cell_format);
s_count='D'+str(red_counter);
sup_sheet.write(s_count,fqdn,cell_format);

I get the following error 
sup_sheet.write(s_count,fqdn,cell_format);
TypeError: 'tuple' object is not callable

What I do not understand is why is python thinking  sup_sheet.write as tuple.
I tired to debug the program and added the following line
print "\ts_count is ", type(s_count)," and value",s_count,"\n\tfqdn is ", 
type(fqdn), " and value is ",fqdn,"\n\tcell_format is ", type(cell_format), " 
and value is ",cell_format,"\n\t sup_sheet is ",type(sup_sheet)," and value is 
",sup_sheet,"\n\n\n";

just before 
sup_sheet.write(s_count,fqdn,cell_format);

And I got the following output:
 s_count isand value D2 
fqdn isand value is  Sample1.xyz.com
cell_format isand value is  
 
 sup_sheet isand value is  
 



s_count isand value D3 
fqdn isand value is  sample2.xyz.com
cell_format isand value is  
 
 sup_sheet isand value is  
 



Traceback (most recent call last):
  File "./turnover_sheet.py", line 398, in 
data_population(str(sys.argv[1]));
  File "./turnover_sheet.py", line 380, in data_population
data_collection(fqdn,count);
  File "./turnover_sheet.py", line 219, in data_collection
sup_sheet.write(s_count,fqdn,cell_format);
TypeError: 'tuple' object is not callable

I also saw the sheet populated with the first server and when it went to the 
second server and while populating it considered
sup_sheet.write as a tuple which makes no sense because the rest of the writes 
are working fine.

I have no clue why is it doing it ?
Thoughts ?

--
Regards
Mohan Mohta



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple thread program problem

2015-06-03 Thread M2
On Wednesday, June 3, 2015 at 6:56:47 PM UTC-5, [email protected] wrote:
> On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote:
> > On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote:
> > > You think "(f)" makes a tuple, but it does not.
> > > the parentesis is not the tuple constructor, the comma is
> > > try:
> > > t=thread.start_new_thread(proc,(f,))
> > 
> > Thanks for the pointer waffle.
> > The program executes now but still not the way I want it.
> > I think I will need to tweak it a bit as the code is executing with the 
> > same argument from the file /tmp/python/1 multiple times whereas it needs 
> > to be executed only ones but in parallel. Let me figure that out.
> > 
> > 
> > Once again thanks for all the help provided on this thread.
> 
> Check your usages of "line" and "f".  You have spots where you probably meant 
> "line" instead of "f", and others where you have "f" where you probably meant 
> "line".

Here is my logic:
f is where the entire file is getting loaded
which is also passed as argument in the function proc
line has a single line from the file which is then stripped off the new line 
character and assigned to com2 variable which helps in using it in the 
subprocess.call

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple thread program problem

2015-06-03 Thread M2
On Wednesday, June 3, 2015 at 7:38:22 PM UTC-5, Cameron Simpson wrote:
> On 03Jun2015 17:04, M2  wrote:
> >On Wednesday, June 3, 2015 at 6:56:47 PM UTC-5, [email protected] wrote:
> >> On Wednesday, June 3, 2015 at 4:45:52 PM UTC-7, M2 wrote:
> >> > On Wednesday, June 3, 2015 at 5:34:31 PM UTC-5, Waffle wrote:
> >> > > You think "(f)" makes a tuple, but it does not.
> >> > > the parentesis is not the tuple constructor, the comma is
> >> > > try:
> >> > > t=thread.start_new_thread(proc,(f,))
> >> >
> >> > Thanks for the pointer waffle.
> >> > The program executes now but still not the way I want it.
> >> > I think I will need to tweak it a bit as the code is executing with the 
> >> > same argument from the file /tmp/python/1 multiple times whereas it 
> >> > needs to be executed only ones but in parallel. Let me figure that out.
> >> >
> >> >
> >> > Once again thanks for all the help provided on this thread.
> >>
> >> Check your usages of "line" and "f".  You have spots where you probably 
> >> meant "line" instead of "f", and others where you have "f" where you 
> >> probably meant "line".
> >
> >Here is my logic:
> >f is where the entire file is getting loaded
> 
> In the main code, yes.
> 
> >which is also passed as argument in the function proc
> 
> But why? f is not using in proc. Only line is.
> 
> >line has a single line from the file which is then stripped off the new line 
> >character and assigned to com2 variable which helps in using it in the 
> >subprocess.call
> 
> That end is fine.
> 
> I would be passing only "line" to proc, not "f" at all.
> 
> Suggestion: move your main code into its own function. That will make all the 
> variables in it "local". Your proc function is presently relying on "line" 
> being global, which generally bad and a recipe for disaster in multithreaded 
> code.
> 
> Moving the main code into its own function will (1) get rid of the global 
> variables and (2) force you to consider exactly what you need to pass to 
> "proc", and that will help reveal various logic issues.
> 
> Cheers,
> Cameron Simpson 
> 
> >>>How do you blip the throttle and wave? Do you blip it real high, then wave
> >>>before the revs drop back?
> >>Blip = right hand; Wave = left hand.  Do both simultaneously.  QED.
> >Doesnt this make the bike lurch forward thru the intersection?
> Not if the disk lock is in place...
> - Dean Woodward 

Thanks Cameron.
I do not see the duplication in the execution now.
I do see it is not consistent by executing all the threads ; it might be due to 
the fact I am using 
subprocess.call(co,shell=True) 
Per my understanding the above does not keep track of threads it just spawns a 
thread and leaves it there.
I might need to use the function start(), join() to ensure it picks up all the 
argument

For the record now my new code is 
#! /usr/bin/python
import os
import subprocess
import thread
import threading
import sys
from thread import start_new_thread
 
def proc(col) :
subprocess.call(col,shell=True)
return
 
f = open('/tmp/python/1')
for line in f:
com1="ssh -B "
com2=line.strip('\n')
com3= " uname -a  "
co=str("ssh -B ")+ str(com2) + str(" uname -a")
t=thread.start_new_thread(proc,(co,))
f.close()


Thanks again for the help
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Multiple thread program problem

2015-06-04 Thread M2
On Wednesday, June 3, 2015 at 3:41:15 PM UTC-5, M2 wrote:
> Hello
> I am trying to create multiple thread through the below program but I am 
> getting an error 
> 
> #! /usr/bin/python
> import os
> import subprocess
> import thread
> import threading
> from thread import start_new_thread
> 
> def proc(f) :
> com1="ssh -B "
> com2=line.strip('\n')
> com3= " uname -a"
> co=str("ssh -B ")+ str(com2) + str(" uname -a")
> subprocess.call(co,shell=True)
> print ""
> return
> 
> f = open('/tmp/python/1')
> for line in f:
> t=thread.start_new_thread(proc(f),())
> t.start()
> f.close()
> c = raw_input(" Type anything to quit")
> 
> 
> Execution output:
> Linux abc.myhomenetwork.com 2.6.18-348.25.1.el5 #1 SMP Thu Apr 10 06:32:45 
> EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
> 
> Traceback (most recent call last):
>   File "./readfile1.py", line 19, in 
> t=thread.start_new_thread(proc(f),())
> TypeError: first arg must be callable

Awesome Cameron.
It works the way I want it to work.

Thanks a lot guys.
Here is the new code:
#! /usr/bin/python
import os
import subprocess
import thread
import threading
from thread import start_new_thread

def proc(col) :
P=subprocess.Popen(col, shell=True)
return

f = open('/tmp/python/1')
for line in f:
com1="ssh -B "
com2=line.strip('\n')
#com3= " /var/scripts/health/health.sh"
com3= " uname -a "
co=str("ssh -B ")+ str(com2) + str(com3)
P=proc(co)
f.close()


Thanks a ton guys this should get me started on the greater program I am trying 
to write.
-- 
https://mail.python.org/mailman/listinfo/python-list