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 if "GAUDI_QMTEST_HTML_OUTPUT" in os.environ:
00025 opts.html_output = os.path.normpath(os.path.expandvars(os.environ.get("GAUDI_QMTEST_HTML_OUTPUT")))
00026 else:
00027 opts.html_output = None
00028
00029
00030 if argv:
00031 opts.package = argv.pop(0)
00032
00033
00034
00035 if "QMTESTRESULTSDIR" in os.environ:
00036 opts.output = os.path.normpath(os.path.expandvars(os.environ["QMTESTRESULTSDIR"]))
00037 opts.output = os.path.join(opts.output,
00038 "%s.%s.qmr" % (opts.package, os.environ.get("CMTCONFIG", "noConfig")))
00039
00040
00041 opts.have_user_options = len(argv)
00042
00043 while argv:
00044 o = argv.pop(0)
00045 if o in ['-o','--output']:
00046
00047 opts.output = os.path.realpath(argv.pop(0))
00048 opts.have_user_options -= 2
00049 elif o in ["--no-output"]:
00050 opts.output = None
00051 opts.have_user_options -= 1
00052 elif o in ["--dry-run"]:
00053 opts.dry_run = True
00054 opts.have_user_options -= 1
00055 elif o in ["--html-output"]:
00056 opts.html_output = os.path.realpath(argv.pop(0))
00057 opts.have_user_options -= 2
00058 else:
00059 opts.qmtest_args.append(o)
00060
00061 if opts.output:
00062 opts.qmtest_args = ["-o", opts.output] + opts.qmtest_args
00063 else:
00064 opts.qmtest_args.insert(0, "--no-output")
00065 return opts
00066
00067 def main(argv = None):
00068 opts = parseOptions(argv)
00069
00070 print "==========> Running tests for package %s" % opts.package
00071
00072
00073 if opts.output:
00074 results_dest_dir = os.path.realpath(os.path.join(opts.qmtest_dir, os.path.dirname(opts.output)))
00075 if not os.path.exists(results_dest_dir):
00076 print "==========> Creating '%s'" % results_dest_dir
00077 os.makedirs(results_dest_dir, 0755)
00078
00079 print "==========> Entering '%s'" % opts.qmtest_dir
00080 os.chdir(opts.qmtest_dir)
00081
00082 if not os.path.isdir("QMTest"):
00083
00084 print "==========> Initializing QMTest database"
00085 os.system("qmtest create-tdb")
00086
00087 if opts.html_output:
00088 opts.qmtest_args.insert(0, """--result-stream 'GaudiTest.HTMLResultStream(dir="%s")'""" % opts.html_output)
00089
00090
00091 cmd = "qmtest run %s" % (" ".join(opts.qmtest_args))
00092
00093
00094 if not opts.have_user_options and os.path.exists("%s.qms" % opts.package.lower()):
00095 cmd += " %s" % opts.package.lower()
00096
00097 if opts.dry_run:
00098 print "==========> Would run '%s'"%cmd
00099 else:
00100 print "==========> Running '%s'"%cmd
00101 os.system(cmd)
00102
00103
00104
00105 if __name__ == '__main__':
00106 main()