How to handle calling functions from cli

Discussion in 'Python' started by Rodrick Brown, Feb 24, 2012.

  1. I have a bunch of sub routines that run independently to perform various system checks on my servers. I wanted to get an opinion on the following code Ihave about 25 independent checks and I'm adding the ability to disable certain checks that don't apply to certain hosts.


    m = { 'a': 'checkDisks()',
    'b': 'checkMemSize()',
    'c': 'checkBondInterfaces()'
    }

    parser = argparse.ArgumentParser(description='Parse command line args.')
    parser.add_argument('-x', action="store", dest="d")
    r = parser.parse_args(sys.argv[1:])

    runlist = [ c for c in m.keys() if c not in r.d ]
    for runable in runlist:
    eval(m[runable])

    I'm using temp variable names for now until I find an approach I like.

    Is this a good approach ? It doesn't look too pretty and to be honest feels awkward?

    Sent from my iPhone
     
    Rodrick Brown, Feb 24, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    660
    Joe Smith
    Jul 22, 2004
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,645
    Victor Bazarov
    Jun 21, 2004
  3. Daniel Vallstrom
    Replies:
    2
    Views:
    1,988
    Kevin Bracey
    Nov 21, 2003
  4. S?ren Gammelmark
    Replies:
    1
    Views:
    1,961
    Eric Sosman
    Jan 7, 2005
  5. Ross A. Finlayson
    Replies:
    19
    Views:
    633
    Keith Thompson
    Mar 10, 2005
Loading...

Share This Page