summaryrefslogtreecommitdiffstats
path: root/scripts/getstats.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/getstats.py')
-rwxr-xr-xscripts/getstats.py102
1 files changed, 31 insertions, 71 deletions
diff --git a/scripts/getstats.py b/scripts/getstats.py
index 5527c46..feb665a 100755
--- a/scripts/getstats.py
+++ b/scripts/getstats.py
@@ -13,84 +13,42 @@ from getrankings import GetRankingsAsJSON
from settimeseriesnote import SetTimeSeriesNote
from dbaccess import setDatabase
-from misc import printErrorAsJSON
+from misc import getOptions, printErrorAsJSON
import sys
-import os
-import re
-import urllib
# === Global functions ===============================================
-# Returns a 2-tuple consisting of:
-# 1: an option dictionary, and
-# 2: a flag that is true iff the QUERY_STRING environment variable is
-# present (i.e. that the script is invoked as a CGI-script for a
-# HTTP GET request).
-#
-# The option dictionary is extracted from either the QUERY_STRING environment
-# variable (first priority) or command-line arguments (second priority).
-# In the latter case, the options must be of the form
-# ... --<opt1> <val1> ... --<optN> <valN> ...
-def getOptions():
-
- def getOptDictFromQueryString(qs):
- options = {}
- for sq in qs.split("&"):
- keyval = sq.split("=")
- options[keyval[0]] = urllib.unquote(keyval[1])
- return options
-
- def getOptDictFromCommandLine():
- options = {}
- p = re.compile("^--(.+)$")
- key = None
- for arg in sys.argv[1:]:
- if key != None:
- options[key] = arg
- m = p.match(arg)
- if m:
- key = m.group(1)
- else:
- key = None
- return options
-
- qs = "QUERY_STRING"
- if qs in os.environ:
- return (getOptDictFromQueryString(os.environ[qs]), True)
- else:
- return (getOptDictFromCommandLine(), False)
-
# Returns a command instance.
def createCommand(options, http_get):
def printUsageError():
error = (
- "usage: " + sys.argv[0] + " \\\n" +
- " --db D --cmd contexts [--rankedonly R] | \\\n" +
- " --db D --cmd testcases1 --host H --platform P --branch B " +
- "--sha1 S | \\\n" +
- " --db D --cmd testcases2 --host1 H --platform1 P --branch1 B " +
- "--sha11 S --host2 H --platform2 P --branch2 B --sha12 S | \\\n" +
- " --db D --cmd stats1 --host H --platform P --branch B " +
- "--sha1 S [--testcasefilter 'TC1 TC2 ...'] | \\\n" +
- " --db D --cmd stats2 --host1 H --platform1 P --branch1 B " +
- "--sha11 S --host2 H --platform2 P --branch2 B --sha12 S " +
- "[--testcasefilter 'TC1 TC2 ...'] | \\\n" +
- " --db D --cmd result_details2 --host1 H --platform1 P " +
- "--branch1 B --sha11 S --host2 H --platform2 P --branch2 B " +
- "--sha12 S --benchmark BM --metric M | \\\n" +
- " --db D --cmd timeseriesstats --host H --platform P --branch B " +
- "--sha11 S --sha12 S [--difftol T] [--durtolmin T] " +
- "[--durtolmax T] [--testcasefilter 'TC1 TC2 ...'] | \\\n" +
- " --db D --cmd timeseriesdetails --host H --platform P " +
- "--branch B --sha11 S --sha12 S --difftol T --durtolmin T " +
- "--durtolmax T --benchmark BM --metric M | \\\n" +
- " --db D --cmd snapshots --host H --platform P " +
- "--branch B --sha11 S --sha12 S | \\\n" +
- " --db D --cmd rankings --host H --platform P " +
- "--branch B --sha1 S [--testcasefilter 'TC1 TC2 ...'] " +
- "[--maxsize M] | \\\n" +
- " --db D --cmd settimeseriesnote --host H --platform P " +
+ "usage: " + sys.argv[0] + " [--dbhost H --dbport P] --db D + \\\n"
+ " --cmd contexts [--rankedonly R] | \\\n"
+ " --cmd testcases1 --host H --platform P --branch B "
+ "--sha1 S | \\\n"
+ " --cmd testcases2 --host1 H --platform1 P --branch1 B "
+ "--sha11 S --host2 H --platform2 P --branch2 B --sha12 S | \\\n"
+ " --cmd stats1 --host H --platform P --branch B "
+ "--sha1 S [--testcasefilter 'TC1 TC2 ...'] | \\\n"
+ " --cmd stats2 --host1 H --platform1 P --branch1 B "
+ "--sha11 S --host2 H --platform2 P --branch2 B --sha12 S "
+ "[--testcasefilter 'TC1 TC2 ...'] | \\\n"
+ " --cmd result_details2 --host1 H --platform1 P "
+ "--branch1 B --sha11 S --host2 H --platform2 P --branch2 B "
+ "--sha12 S --benchmark BM --metric M | \\\n"
+ " --cmd timeseriesstats --host H --platform P --branch B "
+ "--sha11 S --sha12 S [--difftol T] [--durtolmin T] "
+ "[--durtolmax T] [--testcasefilter 'TC1 TC2 ...'] | \\\n"
+ " --cmd timeseriesdetails --host H --platform P "
+ "--branch B --sha11 S --sha12 S --difftol T --durtolmin T "
+ "--durtolmax T --benchmark BM --metric M | \\\n"
+ " --cmd snapshots --host H --platform P "
+ "--branch B --sha11 S --sha12 S | \\\n"
+ " --cmd rankings --host H --platform P "
+ "--branch B --sha1 S [--testcasefilter 'TC1 TC2 ...'] "
+ "[--maxsize M] | \\\n"
+ " --cmd settimeseriesnote --host H --platform P "
"--branch B --benchmark B --metric M --note N")
if http_get:
@@ -100,8 +58,10 @@ def createCommand(options, http_get):
# Check for mandatory 'db' argument:
if "db" in options:
- db = options["db"]
- setDatabase(db)
+ setDatabase(
+ options["dbhost"] if "dbhost" in options else None,
+ options["dbport"] if "dbport" in options else None,
+ options["db"])
else:
printUsageError()
sys.exit(1)