sean@0: #!/usr/bin/env python3 sean@0: sean@0: """ Display previously saved issues from a database on webpage via CGI. sean@0: sean@0: author: Sascha L. Teichmann sean@0: author: Bernhard Reiter sean@0: author: Sean Engelhardt sean@0: sean@0: (c) 2010,2015 by Intevation GmbH sean@0: sean@0: This is Free Software unter the terms of the sean@0: GNU GENERAL PUBLIC LICENSE Version 3 or later. sean@0: See http://www.gnu.org/licenses/gpl-3.0.txt for details sean@0: """ sean@0: sean@0: import sqlite3 as db sean@0: import cgitb sean@0: import roundup_content_data as rcd sean@0: sean@0: sean@0: def make_js_object_string(array): sean@0: formated = [] sean@0: sean@0: for item in array: sean@0: formated.append("{points: " + str(item) + "}") sean@0: sean@0: return ",".join(formated) sean@0: sean@0: sean@0: def make_js_object_date(array): sean@0: formated = [] sean@0: sean@0: for item in array: sean@0: formated.append("{date : new Date('" + str(item) + "')}") sean@0: sean@0: return ", ".join(formated) sean@0: sean@0: sean@0: def get_webpage(): sean@0: sean@0: with open ("graph.html", "r") as html_chart_file: sean@0: base_html_data = html_chart_file.read() sean@0: sean@0: base_html_data = (base_html_data sean@0: .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") sean@0: .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") sean@0: .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") sean@0: .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") sean@0: .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") sean@0: .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) sean@0: sean@0: return base_html_data sean@0: sean@0: sean@0: def render_webpage(content): sean@0: for line in content.split("\n"): sean@0: print(line) sean@0: sean@0: sean@0: def render_db_stats_as_html(): sean@0: sean@0: con = None sean@0: cur = None sean@0: sean@0: try: sean@0: con = db.connect(rcd.DATABASE_FILE) sean@0: cur = con.cursor() sean@0: cur.execute(rcd.SELECT_ALL) sean@0: sean@0: for row in cur.fetchall(): sean@0: rcd.data_dict["date"].append(row[0]) sean@0: rcd.data_dict["critical"].append(row[1]) sean@0: rcd.data_dict["urgent"].append(row[2]) sean@0: rcd.data_dict["bug"].append(row[3]) sean@0: rcd.data_dict["feature"].append(row[4]) sean@0: rcd.data_dict["wish"].append(row[5]) sean@0: finally: sean@0: if cur: sean@0: cur.close() sean@0: if con: sean@0: con.close() sean@0: sean@0: render_webpage(get_webpage()) sean@0: sean@0: sean@0: cgitb.enable() sean@0: print("Content-Type: text/html") sean@0: print() sean@0: sean@0: sean@0: render_db_stats_as_html()