run_qmtest.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 import os, sys
00009
00010 class Options(object):
00011 pass
00012
00013 def parseOptions(argv = None):
00014 if argv is None:
00015 argv = sys.argv[1:]
00016
00017 opts = Options()
00018 opts.package = "Unknown"
00019 opts.qmtest_args = []
00020 opts.have_user_options = False
00021 opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTS"]))
00022 opts.qmtest_dir = os.path.normpath(os.path.expandvars(os.environ["QMTESTLOCALDIR"]))
00023 opts.dry_run = False
00024
00025 if argv:
00026 opts.package = argv.pop(0)
00027
00028
00029
00030 if "QMTESTRESULTSDIR" in os.environ:
00031 opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
00032 opts.output = os.path.join(opts.output,
00033 "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
00034
00035
00036 opts.have_user_options = len(argv)
00037
00038 while argv:
00039 o = argv.pop(0)
00040 if o in ['-o','--output']:
00041
00042 opts.output = os.path.realpath(argv.pop(0))
00043 opts.have_user_options -= 2
00044 elif o in ["--no-output"]:
00045 opts.output = None
00046 opts.have_user_options -= 1
00047 elif o in ["--dry-run"]:
00048 opts.dry_run = True
00049 opts.have_user_options -= 1
00050 else:
00051 opts.qmtest_args.append(o)
00052
00053 if opts.output:
00054 opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
00055 else:
00056 opts.qmtest_args.insert(0, "--no-output")
00057 return opts
00058
00059 def main(argv = None):
00060 opts = parseOptions(argv)
00061
00062 print "==========> Running tests for package %s" % opts.package
00063
00064
00065 if opts.output:
00066 results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
00067 if not os.path.exists(results_dest_dir):
00068 print "==========> Creating '%s'" % results_dest_dir
00069 os.makedirs(results_dest_dir, 0755)
00070
00071 print "==========> Entering '%s'" % opts.qmtest_dir
00072 os.chdir(opts.qmtest_dir)
00073
00074 if not os.path.isdir("QMTest"):
00075
00076 print "==========> Initializing QMTest database"
00077 os.system("qmtest create-tdb")
00078
00079
00080 cmd = "qmtest run %s" % (" ".join(opts.qmtest_args))
00081
00082
00083 if not opts.have_user_options and os.path.exists("%s.qms" % opts.package.lower()):
00084 cmd += " %s" % opts.package.lower()
00085
00086 if opts.dry_run:
00087 print "==========> Would run '%s'"%cmd
00088 else:
00089 print "==========> Running '%s'"%cmd
00090 os.system(cmd)
00091
00092
00093
00094 if __name__ == '__main__':
00095 main()