Re: [Tutor] Newby Linux Program review + help with regular expressions

2009-03-10 Thread Lie Ryan

David wrote:
This program generates a report of a Linux System and some important 
..conf files. The goal is for users to be able to post their information 
and compare with others, ask for help etc. Am I using the subrocess 
module too much because I am comfortable with the commands? Should I 
just write this type of program in bash. I am trying to get rid of all 
the comments generated in the report. I got rid of blank lines and lines 
starting with #. But can not figure out how the get rid of a line like;

#This is a comment with 5 spaces
I never programed before so everything is new to me.
Here is my code;
http://asterisklinks.com/wiki/doku.php?id=wiki:gentoo_report
The report it generates is at the bottom. I didn't want to post it all 
here.

Thanks,
-david



Why are you piping the shell while you ordered the shell to redirect 
output to a file, then dumping the pipe?


def uname_report():
p = subprocess.Popen("uname -a >> /root/gentoo_report.txt",
shell=True, stdout=subprocess.PIPE)
return p.stdout.readlines()

You should choose either one, use the pipe and write to the report file 
yourself (more flexibility) or use the shell >> redirection. Also, I'd 
rather not use search and replace if I decided to put the report file 
somewhere else.


PS: for unix-style program, the report should be outputted to the stdout

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newby Linux Program review + help with regular expressions

2009-03-09 Thread Alan Gauld


"David"  wrote

and compare with others, ask for help etc. Am I using the subrocess 
module too much because I am comfortable with the commands? Should I 
just write this type of program in bash.


Personally I'd use bash for this kind of thing.
If you wanted to post process the report then I'd use Python.
You could do a faitr bit with Python commands, especially the
functions in the os module, but since the scripts already exist you 
might as well use them.


One thing though, you could use triple quoted strings and string 
formatting more:


fobj.write(nick)
fobj.write(" \n")
fobj.write(make)
fobj.write(" \n")
fobj.write(model)
fobj.write(" \n")
fobj.close()Could be:

fobj.write("%s\n%s\n%s\n" % (nick,make,model) )



#This is a comment with 5 spaces


you can use the lstrip() methjod of a string:

if line.lstrip().startswith('#'):
   isComment = True

HTH,


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Newby Linux Program review + help with regular expressions

2009-03-09 Thread David
This program generates a report of a Linux System and some important 
.conf files. The goal is for users to be able to post their information 
and compare with others, ask for help etc. Am I using the subrocess 
module too much because I am comfortable with the commands? Should I 
just write this type of program in bash. I am trying to get rid of all 
the comments generated in the report. I got rid of blank lines and lines 
starting with #. But can not figure out how the get rid of a line like;

#This is a comment with 5 spaces
I never programed before so everything is new to me.
Here is my code;
http://asterisklinks.com/wiki/doku.php?id=wiki:gentoo_report
The report it generates is at the bottom. I didn't want to post it all here.
Thanks,
-david

--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor