from myPopen import run def configure_network(): """ Prepare network for test """ try: cmd = ("netadm enable -p ncp DefaultFixed") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret)) return False cmd = ("ipadm create-ip net3") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret)) return False cmd = ("ipadm create-addr -a 192.168.84.3/24 net3") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret)) return False cmd = (" route -p add default 192.168.84.1") out, err, ret = run(cmd, timeout=60) if ret != "": logging.error("Can't run %s got %s (%d)!" % (cmd, err, ret)) return False except Exception, e: logging.exception("Failed to run %s got %s" % (cmd, e)) return False logging.info("Configuring network .Done !!!") return True
Q1.How to make this code look better (in terms of quality) Q2. Iam using the except clause, just to maintain the syntax, will any exception be caught in this case. Q3. Any other observations made Thanks, Iam on Python 2.7 and freebsd. -- https://mail.python.org/mailman/listinfo/python-list