changeset 29:8d86ba8dee42

Rename roundup_cc_display.py to display_issues.py and display_issues_demo.py to roundup_cc_display.py
author Magnus Schieder <mschieder@intevation.de>
date Thu, 22 Nov 2018 13:23:51 +0100
parents e2864dabdb8c
children 0d6504d02a6b
files display_issues.py display_issues_demo.py roundup_cc_display.py
diffstat 3 files changed, 145 insertions(+), 145 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display_issues.py	Thu Nov 22 13:23:51 2018 +0100
@@ -0,0 +1,109 @@
+#!/usr/bin/env python3
+
+""" Display previously saved issues from a database on webpage via CGI.
+
+author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
+author: Bernhard Reiter <bernhard@intevation.de>
+author: Sean Engelhardt <sean.engelhardt@intevation.de>
+
+(c) 2010,2015 by Intevation GmbH
+
+This is Free Software unter the terms of the
+GNU GENERAL PUBLIC LICENSE Version 3 or later.
+See http://www.gnu.org/licenses/gpl-3.0.txt for details
+
+
+##Usage Example: ##
+see display_issues_demo.py or __main__ section below.
+"""
+
+import sqlite3 as db
+import cgitb
+import roundup_content_data as rcd
+import os
+
+
+def make_js_object_string(array):
+    formated = []
+
+    for item in array:
+        formated.append("{points: " + str(item) + "}")
+
+    return ",".join(formated)
+
+
+def make_js_object_date(array):
+    formated = []
+
+    for item in array:
+        formated.append("{date : new Date('" + str(item) + "')}")
+
+    return ", ".join(formated)
+
+def get_webpage(data_dict, columns, status, keywords, graph=None):
+
+    if graph is None:
+        graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html'
+
+    with open(graph, "r") as html_chart_file:
+        base_html_data = html_chart_file.read()
+
+    if "None" not in columns:
+        data_dict["None"] = [0]
+
+
+    js_data_dickt ="{"
+    for col in columns.split(", "):
+        js_data_dickt += col + ":[" + make_js_object_string(data_dict[col]) + "],"
+    js_data_dickt += "}"
+
+    base_html_data = (base_html_data
+        .replace("status", status)
+        .replace("keywords", keywords)
+        .replace("js_data_dickt", js_data_dickt)
+        .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(data_dict["date"]) + "]"))
+
+    return base_html_data
+
+def compile_db_stats_html(db_file, sql_select, columns, status="", keywords="", graph=None):
+
+    data_dict = {"date": []}
+    status_list = columns.split(", ")
+    for x in status_list:
+        data_dict[x] = []
+
+    con = None
+    cur = None
+
+    try:
+        con = db.connect(db_file)
+        cur = con.cursor()
+        cur.execute(sql_select)
+
+        for row in cur.fetchall():
+            data_dict["date"].append(row[0])
+            for x in range(len(status_list)):
+                data_dict[status_list[x]].append(row[x+1])
+
+    finally:
+        if cur:
+            cur.close()
+        if con:
+            con.close()
+
+    return get_webpage(data_dict, columns, status, keywords, graph)
+
+def render_webpage(content):
+    for line in content.split("\n"):
+        print(line)
+
+def render_db_stats_as_html(db_file, sql_select, columns, status="", keywords=""):
+    render_webpage(compile_db_stats_html(db_file, sql_select, columns, status, keywords))
+
+if __name__ == '__main__':
+    cgitb.enable()
+    #spit out HTML file directly, thus no need to give headers to the server
+    #print("Content-Type: text/html")
+    #print()
+
+    render_db_stats_as_html("./demo3.db", rcd.SELECT_ALL)
--- a/display_issues_demo.py	Thu Nov 22 12:57:20 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#!/usr/bin/env python3
-
-""" Fetch issues from a roundup-tracker and save them in a databse.
-
-author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
-author: Bernhard Reiter <bernhard@intevation.de>
-author: Sean Engelhardt <sean.engelhardt@intevation.de>
-
-(c) 2010, 2015, 2018 by Intevation GmbH
-
-This is Free Software unter the terms of the
-GNU GENERAL PUBLIC LICENSE Version 3 or later.
-See http://www.gnu.org/licenses/gpl-3.0.txt for details
-"""
-import configparser
-import argparse
-from display_issues import *
-
-def main():
-    PRIO = "critical, urgent, bug, feature, wish"
-    STATES = "unread, deferred, chatting, need_eg, in_progress, testing, done_cbb, resolved"
-
-    parser = argparse.ArgumentParser()
-    parser.add_argument("config_file", type=str, metavar="[config file]")
-    args = parser.parse_args()
-
-    config = configparser.ConfigParser()
-    config.read(args.config_file)
-
-    db = config.get("DB", "DatabaseFile")
-    keywords = config.get("SEARCH", "Keywords", fallback="")
-
-
-    search = config.get("SEARCH", "Search", fallback="prio")
-    if search == "prio":
-        status = config.get("SEARCH", "Status", fallback="")
-        columns = config.get("SEARCH", "Priority", fallback=PRIO)
-        noPrio = config.get("SEARCH", "IncludeNoPrio", fallback=False)
-        if noPrio:
-            columns += ", None"
-
-    elif search == "status":
-        columns = config.get("SEARCH", "Status", fallback=STATES)
-        status = ""
-
-    else:
-        print("Incorrect [SEARCH]Search parameter. (prio, status)")
-        return
-
-    # roundup uses a "-" in its search parameters. Sql can't handle it.
-    columns = columns.replace("-", "_")
-
-    cgitb.enable() # (optional) HTML traceback to browser
-    #render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL)
-    render_db_stats_as_html(db,
-            rcd.build_sql_select(columns).format("timestamp > date('now', '-2 month')"),
-            columns, status, keywords)
-
-if __name__ == '__main__':
-    main()
--- a/roundup_cc_display.py	Thu Nov 22 12:57:20 2018 +0100
+++ b/roundup_cc_display.py	Thu Nov 22 13:23:51 2018 +0100
@@ -1,109 +1,60 @@
 #!/usr/bin/env python3
 
-""" Display previously saved issues from a database on webpage via CGI.
+""" Fetch issues from a roundup-tracker and save them in a databse.
 
 author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
 author: Bernhard Reiter <bernhard@intevation.de>
 author: Sean Engelhardt <sean.engelhardt@intevation.de>
 
-(c) 2010,2015 by Intevation GmbH
+(c) 2010, 2015, 2018 by Intevation GmbH
 
 This is Free Software unter the terms of the
 GNU GENERAL PUBLIC LICENSE Version 3 or later.
 See http://www.gnu.org/licenses/gpl-3.0.txt for details
-
-
-##Usage Example: ##
-see display_issues_demo.py or __main__ section below.
 """
-
-import sqlite3 as db
-import cgitb
-import roundup_content_data as rcd
-import os
-
-
-def make_js_object_string(array):
-    formated = []
-
-    for item in array:
-        formated.append("{points: " + str(item) + "}")
+import configparser
+import argparse
+from display_issues import *
 
-    return ",".join(formated)
-
-
-def make_js_object_date(array):
-    formated = []
-
-    for item in array:
-        formated.append("{date : new Date('" + str(item) + "')}")
+def main():
+    PRIO = "critical, urgent, bug, feature, wish"
+    STATES = "unread, deferred, chatting, need_eg, in_progress, testing, done_cbb, resolved"
 
-    return ", ".join(formated)
-
-def get_webpage(data_dict, columns, status, keywords, graph=None):
+    parser = argparse.ArgumentParser()
+    parser.add_argument("config_file", type=str, metavar="[config file]")
+    args = parser.parse_args()
 
-    if graph is None:
-        graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html'
+    config = configparser.ConfigParser()
+    config.read(args.config_file)
 
-    with open(graph, "r") as html_chart_file:
-        base_html_data = html_chart_file.read()
-
-    if "None" not in columns:
-        data_dict["None"] = [0]
+    db = config.get("DB", "DatabaseFile")
+    keywords = config.get("SEARCH", "Keywords", fallback="")
 
 
-    js_data_dickt ="{"
-    for col in columns.split(", "):
-        js_data_dickt += col + ":[" + make_js_object_string(data_dict[col]) + "],"
-    js_data_dickt += "}"
-
-    base_html_data = (base_html_data
-        .replace("status", status)
-        .replace("keywords", keywords)
-        .replace("js_data_dickt", js_data_dickt)
-        .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(data_dict["date"]) + "]"))
-
-    return base_html_data
-
-def compile_db_stats_html(db_file, sql_select, columns, status="", keywords="", graph=None):
-
-    data_dict = {"date": []}
-    status_list = columns.split(", ")
-    for x in status_list:
-        data_dict[x] = []
-
-    con = None
-    cur = None
+    search = config.get("SEARCH", "Search", fallback="prio")
+    if search == "prio":
+        status = config.get("SEARCH", "Status", fallback="")
+        columns = config.get("SEARCH", "Priority", fallback=PRIO)
+        noPrio = config.get("SEARCH", "IncludeNoPrio", fallback=False)
+        if noPrio:
+            columns += ", None"
 
-    try:
-        con = db.connect(db_file)
-        cur = con.cursor()
-        cur.execute(sql_select)
-
-        for row in cur.fetchall():
-            data_dict["date"].append(row[0])
-            for x in range(len(status_list)):
-                data_dict[status_list[x]].append(row[x+1])
+    elif search == "status":
+        columns = config.get("SEARCH", "Status", fallback=STATES)
+        status = ""
 
-    finally:
-        if cur:
-            cur.close()
-        if con:
-            con.close()
+    else:
+        print("Incorrect [SEARCH]Search parameter. (prio, status)")
+        return
 
-    return get_webpage(data_dict, columns, status, keywords, graph)
+    # roundup uses a "-" in its search parameters. Sql can't handle it.
+    columns = columns.replace("-", "_")
 
-def render_webpage(content):
-    for line in content.split("\n"):
-        print(line)
-
-def render_db_stats_as_html(db_file, sql_select, columns, status="", keywords=""):
-    render_webpage(compile_db_stats_html(db_file, sql_select, columns, status, keywords))
+    cgitb.enable() # (optional) HTML traceback to browser
+    #render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL)
+    render_db_stats_as_html(db,
+            rcd.build_sql_select(columns).format("timestamp > date('now', '-2 month')"),
+            columns, status, keywords)
 
 if __name__ == '__main__':
-    cgitb.enable()
-    #spit out HTML file directly, thus no need to give headers to the server
-    #print("Content-Type: text/html")
-    #print()
-
-    render_db_stats_as_html("./demo3.db", rcd.SELECT_ALL)
+    main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)