Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103719 > unrolled thread

common mistakes in this simple program

Started byGanesh Pal <ganesh1pal@gmail.com>
First post2016-02-29 20:48 +0530
Last post2016-02-29 20:48 +0530
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  common mistakes in this simple program Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-29 20:48 +0530

#103719 — common mistakes in this simple program

FromGanesh Pal <ganesh1pal@gmail.com>
Date2016-02-29 20:48 +0530
Subjectcommon mistakes in this simple program
Message-ID<mailman.15.1456759145.20602.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web