Hi,
I got this code snippet with the following usage:
def main():
# sample usage
manager = LoadManager()
manager.msg = ('www.example.com', '/')
manager.start(threads=5, interval=2, rampup=2)
if __name__ == '__main__':
main()
Works fine,but i would like to supply the following arguments through command line:
msg
threads
interval
rampup
Plz could anyone tell me how to accomplish this
i tried:
def main():
# default parameters
threads = 1
rampup = 0
interval = 0
msg='www.example.com'
# parse command line arguments
opt, args = optionparse.parse(__doc__)
if not opt and not args:
print "sorry"
optionparse.exit()
try:
if opt.threads:
threads = int(opt.threads)
if opt.rampup:
rampup = int(opt.rampup)
if opt.interval:
interval = int(opt.interval)
if opt.duration:
msg = str(opt.msg)
except:
print 'Invalid Argument'
sys.exit(1)
manager = LoadManager()
manager.msg = ('argv[1]', '/')
manager.start(argv[2],argv[3], argv[4])
if __name__ == '__main__':
main()
This doesnt work...It gives me the error msg cant find module optionparse.
i included import optionparse,but still gives me the same error....Plz advise on the rest of the code as well,i'm unsure whether this is methos is correct for passing the arguments...
Cheers
David