|
@@ -21,7 +21,7 @@
|
|
|
import sys
|
|
|
import os
|
|
|
import time
|
|
|
-from optparse import OptionParser
|
|
|
+import argparse
|
|
|
|
|
|
try:
|
|
|
import simplejson as json
|
|
@@ -76,40 +76,38 @@ class TestContext(object):
|
|
|
|
|
|
def main():
|
|
|
|
|
|
- usage = "usage: %prog [options] <json file>"
|
|
|
- parser = OptionParser(usage=usage)
|
|
|
- parser.add_option("-t", "--target-ip", dest="ip", help="The IP address of the target machine. Use this to \
|
|
|
+ parser = argparse.ArgumentParser()
|
|
|
+ parser.add_argument("-t", "--target-ip", dest="ip", help="The IP address of the target machine. Use this to \
|
|
|
overwrite the value determined from TEST_TARGET_IP at build time")
|
|
|
- parser.add_option("-s", "--server-ip", dest="server_ip", help="The IP address of this machine. Use this to \
|
|
|
+ parser.add_argument("-s", "--server-ip", dest="server_ip", help="The IP address of this machine. Use this to \
|
|
|
overwrite the value determined from TEST_SERVER_IP at build time.")
|
|
|
- parser.add_option("-d", "--deploy-dir", dest="deploy_dir", help="Full path to the package feeds, that this \
|
|
|
+ parser.add_argument("-d", "--deploy-dir", dest="deploy_dir", help="Full path to the package feeds, that this \
|
|
|
the contents of what used to be DEPLOY_DIR on the build machine. If not specified it will use the value \
|
|
|
specified in the json if that directory actually exists or it will error out.")
|
|
|
- parser.add_option("-l", "--log-dir", dest="log_dir", help="This sets the path for TEST_LOG_DIR. If not specified \
|
|
|
+ parser.add_argument("-l", "--log-dir", dest="log_dir", help="This sets the path for TEST_LOG_DIR. If not specified \
|
|
|
the current dir is used. This is used for usually creating a ssh log file and a scp test file.")
|
|
|
+ parser.add_argument("json", help="The json file exported by the build system", default="testdata.json", nargs='?')
|
|
|
|
|
|
- (options, args) = parser.parse_args()
|
|
|
- if len(args) != 1:
|
|
|
- parser.error("Incorrect number of arguments. The one and only argument should be a json file exported by the build system")
|
|
|
+ args = parser.parse_args()
|
|
|
|
|
|
- with open(args[0], "r") as f:
|
|
|
+ with open(args.json, "r") as f:
|
|
|
loaded = json.load(f)
|
|
|
|
|
|
- if options.ip:
|
|
|
- loaded["target"]["ip"] = options.ip
|
|
|
- if options.server_ip:
|
|
|
- loaded["target"]["server_ip"] = options.server_ip
|
|
|
+ if args.ip:
|
|
|
+ loaded["target"]["ip"] = args.ip
|
|
|
+ if args.server_ip:
|
|
|
+ loaded["target"]["server_ip"] = args.server_ip
|
|
|
|
|
|
d = MyDataDict()
|
|
|
for key in loaded["d"].keys():
|
|
|
d[key] = loaded["d"][key]
|
|
|
|
|
|
- if options.log_dir:
|
|
|
- d["TEST_LOG_DIR"] = options.log_dir
|
|
|
+ if args.log_dir:
|
|
|
+ d["TEST_LOG_DIR"] = args.log_dir
|
|
|
else:
|
|
|
d["TEST_LOG_DIR"] = os.path.abspath(os.path.dirname(__file__))
|
|
|
- if options.deploy_dir:
|
|
|
- d["DEPLOY_DIR"] = options.deploy_dir
|
|
|
+ if args.deploy_dir:
|
|
|
+ d["DEPLOY_DIR"] = args.deploy_dir
|
|
|
else:
|
|
|
if not os.path.isdir(d["DEPLOY_DIR"]):
|
|
|
print("WARNING: The path to DEPLOY_DIR does not exist: %s" % d["DEPLOY_DIR"])
|