Before unloading any criticism, first let me say congratulations on getting your first Python program working. Moving from one language to another can be a chore, constantly fumbling around with syntax issues and hunting through unfamiliar libraries.
The most quoted style guideline is PEP-8, but that's only a guide, and at least some part of it is ignored...no, I mean deemed not applicable to some specific situation with all due respect to the guideline authors and contributors :-).
I can't compare it to PHP, but compared to other Python applications it is pretty clear that you are following style conventions from other languages. I didn't always agree with many things that other developers said you must do, but over time I recognized why using conventions helps communicate what the application is doing and will help other developers help you.
Raise exceptions, not strings.
raise 'Server or group ' + sectionname + ' not found in ' + configfile
becomes
raise RuntimeError('Server or group ' + sectionname + ' not found in ' + configfile)
No space before the ':' at the end of an 'if' or 'for', and don't put multiple statements on the same line, and be consistent about putting spaces around operators. Use variable names for objects and stick with
i
and
j
for loop index variables (like our masterful FORTRAN forefathers):
for i in grouplist : servers+=getServers(i)
becomes:
for section in grouplist:
servers += getServers(section)
Containers can be tested for contents without getting their length:
while len(threadlist) > 0 :
becomes
while threadlist:
and
if command.strip() == "" :
becomes
if command.strip():
Splitting a tuple is usually not put in parenthesis on the left hand side of a statement, and the command logic is a bit convoluted. If there are no args then the " ".join(...) is going to be an empty string:
(options,args) = parser.parse_args()
if options.verbose : print "floep 0.1"
command = " ".join(args)
if command.strip() == "" : parser.error('no command given')
becomes
options, args = parser.parse_args()
if options.verbose:
print "floep 0.1"
if not args:
parser.error('no command given')
command = " ".join(args)
A python for loop has an unusual 'else' clause which is executed if the loop goes through all of the elements without a 'break':
for server in threadlist :
foundOne = False
if not server.isAlive() :
...snip...
foundOne = True
if not foundOne :
time.sleep(0.010)
becomes
for server in threadlist:
if not server.isAlive():
...snip...
break
else:
time.sleep(0.010)
Getting a list of lines and then joining them back together is a bit long winded:
result = proc.readlines()
strresult = ''
for line in result : strresult+=line
self.result = strresult
becomes
self.result = proc.read()
Your library use is good, check out the subprocess module, it's a little more up-to-date.
Your datatypes are fine.
And you'll get lots of other anwsers :-)