7
7
# Read data files from this pattern.
8
8
# They are pickle files produced with "callgrind_parser.py -c"
9
DATA_FILE_TEMPLATE = "/path/to/results/{R_VAR}/reload-O0-g.cg.pickle"
9
DATA_FILE_TEMPLATE = "/path/to/results/{SNAP_VAR}/{TEST_VAR}.cg.pickle"
11
11
# Where the python source located, better don't serve this path with CGI exec
12
12
# allowed, or even don't serve it at all.
72
72
form = cgi.FieldStorage ()
74
r_var = form.getfirst ("r")
74
snap_var = form.getfirst ("snap")
75
test_var = form.getfirst ("test")
75
76
args.funcName = form.getfirst ("f")
76
77
f0 = form.getfirst ("F")
77
78
if (f0 is not None):
78
79
args.funcNo = int (f0)
79
80
args.typ = form.getfirst ("t", "pos")
81
print ("You must specify input file!", file=sys.stderr)
81
if (snap_var == None or test_var == None):
82
# TODO err function printing HTML instead of SVG
83
print ("You must specify snapshot name and test name!",
84
87
# Disallow all relative paths in r_var before actually creating filename
85
88
# with DATA_FILE_TEMPLATE.
86
89
# For simplicity don't allow anything other than [a-zA-Z0-9_\-\.]
87
good_chars = string.ascii_letters + string.digits + "_-."
88
if (r_var.lstrip (good_chars) != "") or (".." in r_var):
89
print ("Bad characters in filename:", var_r, file=sys.stderr)
90
def variable_clean (v):
91
good_chars = string.ascii_letters + string.digits + "_-."
92
if (v.lstrip (good_chars) != "") or (".." in v):
97
if (not variable_clean (snap_var) or not variable_clean (test_var)):
98
print ("Bad characters in snap or test variable!", file=sys.stderr)
92
args.infile = DATA_FILE_TEMPLATE.format (R_VAR=r_var)
101
args.infile = DATA_FILE_TEMPLATE.format (SNAP_VAR=snap_var,
94
104
# This will always be the base of our query string
95
args.query_string = "?r=" + r_var
105
args.query_string = "?snap=" + snap_var + "&test=" + test_var
97
107
print ("Content-Type: image/svg+xml")