Skip to content

Commit

Permalink
Improve commandline global option parsing
Browse files Browse the repository at this point in the history
Addresses a TODO from Colin.
  • Loading branch information
MurphyMc committed Oct 23, 2011
1 parent cb3adda commit 1ef4100
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions pox.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,24 @@ def doLaunch ():
return True

cli = True
verbose = False

def _opt_no_cli (v):
if str(v).lower() == "true":
global cli
cli = False

def _opt_verbose (v):
verbose = str(v).lower() == "true"

def process_options ():
# TODO: define this list somewhere else. Or use an option-parsing library.
pox_options = ["no-cli", "verbose"]
for k,v in options.iteritems():
#print k,"=",v
if k == "no-cli":
if str(v).lower() == "true":
global cli
cli = False
elif k not in pox_options:
print "Unknown option: ", k
rk = '_opt_' + k.replace("-", "_")
if rk in globals():
globals()[rk](v)
else:
print "Unknown option:", k
import sys
sys.exit(1)

Expand Down Expand Up @@ -274,9 +280,13 @@ def prep (self):
pre_startup()
launchOK = doLaunch()
if launchOK:
process_options()
post_startup()
core.goUp()
try:
process_options()
except:
launchOK = False
if launchOK:
post_startup()
core.goUp()
except:
import traceback
traceback.print_exc()
Expand Down

0 comments on commit 1ef4100

Please sign in to comment.