common mistakes in this simple program
Ganesh Pal
ganesh1pal at gmail.com
Mon Feb 29 10:18:57 EST 2016
Iam on python 2.6 , need inputs on the common mistakes in this program
, may be you suggest what need to be improved from
1. usage of try- expect
2. Return of True/ False
3. Other improvement
#!/usr/bin/env python
"""
"""
import os
import shlex
import subprocess
import sys
import time
import logging
import run
import pdb
def run_cmd_and_verify(cmd, timeout=1000):
try:
pdb.set_trace()
out, err, ret = run(cmd, timeout=timeout)
assert ret ==0,"ERROR (ret %d): " \
" \nout: %s\nerr: %s\n" % (ret, out, err)
except Exception as e:
print("Failed to run %s got %s" % (cmd, e))
return False
return True
def prep_host():
"""
Prepare clustering
"""
for cmd in ["ls -al",
"touch /tmp/file1",
"mkdir /tmp/dir1"]:
try:
if not run_cmd_and_verify(cmd, timeout=3600):
return False
except:
print("Error: While preparing cluster !!!")
return False
print("Preparing Cluster.....Done !!!")
return True
def main():
functions = [prep_host]
for func in functions:
try:
func()
except Exception as e:
print(e)
return False
if __name__ == '__main__':
main()
Regards,
Gpal
More information about the Python-list
mailing list