Mercurial > roundup-cc
annotate display_issues.py @ 17:adca5b3780d2
Add collecting no-prio issues. Restructure.
* Move usage examples from collect_issues.py to examples/.
Also add a section about this to the readme. This should
make it easier to understand how it all works together.
As we have two examples now, hardcode the database filenames.
* Add a function to create the necessary database command from a list
of columns. This makes it easier to work with tracker that have
customized their priorities,
* Add an example how to collect no-prio issues in a database.
Note that the display part is not included.
* Cleanup roundup_content_data by removing db file name suggestions
and unused "reference db" command. This could be re-added for specific
installations if they need it, however it probably should be separated
as configuration.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 09 Jul 2018 12:28:28 +0200 |
parents | b5f7a439bddd |
children | 3bb3d9a9f1b7 |
rev | line source |
---|---|
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
2 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
3 """ Display previously saved issues from a database on webpage via CGI. |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
4 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
5 author: Sascha L. Teichmann <sascha.teichmann@intevation.de> |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
6 author: Bernhard Reiter <bernhard@intevation.de> |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
7 author: Sean Engelhardt <sean.engelhardt@intevation.de> |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
8 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
9 (c) 2010,2015 by Intevation GmbH |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
10 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
11 This is Free Software unter the terms of the |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
12 GNU GENERAL PUBLIC LICENSE Version 3 or later. |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
13 See http://www.gnu.org/licenses/gpl-3.0.txt for details |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
14 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
15 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
16 ##Usage Example: ## |
7
99e2e0e17103
Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents:
3
diff
changeset
|
17 see display_issues_demo.py or __main__ section below. |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
18 """ |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
19 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
20 import sqlite3 as db |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
21 import cgitb |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
22 import roundup_content_data as rcd |
13
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
23 import os |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
24 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
25 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
26 def make_js_object_string(array): |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
27 formated = [] |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
28 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
29 for item in array: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
30 formated.append("{points: " + str(item) + "}") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
31 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
32 return ",".join(formated) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
33 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
34 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
35 def make_js_object_date(array): |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
36 formated = [] |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
37 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
38 for item in array: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
39 formated.append("{date : new Date('" + str(item) + "')}") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
40 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
41 return ", ".join(formated) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
42 |
14
b5f7a439bddd
Allow to override default graph.html file
Gernot Schulz <gernot@intevation.de>
parents:
13
diff
changeset
|
43 def get_webpage(graph=None): |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
44 |
14
b5f7a439bddd
Allow to override default graph.html file
Gernot Schulz <gernot@intevation.de>
parents:
13
diff
changeset
|
45 if graph is None: |
b5f7a439bddd
Allow to override default graph.html file
Gernot Schulz <gernot@intevation.de>
parents:
13
diff
changeset
|
46 graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html' |
13
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
47 |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
48 with open(graph, "r") as html_chart_file: |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
49 base_html_data = html_chart_file.read() |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
50 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
51 base_html_data = (base_html_data |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
52 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
53 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
54 .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
55 .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
56 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
57 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
58 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
59 return base_html_data |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
60 |
14
b5f7a439bddd
Allow to override default graph.html file
Gernot Schulz <gernot@intevation.de>
parents:
13
diff
changeset
|
61 def compile_db_stats_html(db_file, sql_select, graph=None): |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
62 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
63 con = None |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
64 cur = None |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
65 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
66 try: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
67 con = db.connect(db_file) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
68 cur = con.cursor() |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
69 cur.execute(sql_select) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
70 |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
71 for row in cur.fetchall(): |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
72 rcd.data_dict["date"].append(row[0]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
73 rcd.data_dict["critical"].append(row[1]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
74 rcd.data_dict["urgent"].append(row[2]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
75 rcd.data_dict["bug"].append(row[3]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
76 rcd.data_dict["feature"].append(row[4]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
77 rcd.data_dict["wish"].append(row[5]) |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
78 finally: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
79 if cur: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
80 cur.close() |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
81 if con: |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
82 con.close() |
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
83 |
14
b5f7a439bddd
Allow to override default graph.html file
Gernot Schulz <gernot@intevation.de>
parents:
13
diff
changeset
|
84 return get_webpage(graph) |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
85 |
13
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
86 def render_webpage(content): |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
87 for line in content.split("\n"): |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
88 print(line) |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
89 |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
90 def render_db_stats_as_html(db_file, sql_select): |
149d01f43e31
Split up render_db_stats_as_html function
Gernot Schulz <gernot@intevation.de>
parents:
7
diff
changeset
|
91 render_webpage(compile_db_stats_html(db_file, sql_select)) |
1
2df45f6ecd81
new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents:
diff
changeset
|
92 |
3
99c68ebfb3b9
Streamlined to example use.
Bernhard Reiter <bernhard@intevation.de>
parents:
2
diff
changeset
|
93 if __name__ == '__main__': |
99c68ebfb3b9
Streamlined to example use.
Bernhard Reiter <bernhard@intevation.de>
parents:
2
diff
changeset
|
94 cgitb.enable() |
7
99e2e0e17103
Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents:
3
diff
changeset
|
95 #spit out HTML file directly, thus no need to give headers to the server |
99e2e0e17103
Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents:
3
diff
changeset
|
96 #print("Content-Type: text/html") |
99e2e0e17103
Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents:
3
diff
changeset
|
97 #print() |
3
99c68ebfb3b9
Streamlined to example use.
Bernhard Reiter <bernhard@intevation.de>
parents:
2
diff
changeset
|
98 |
17
adca5b3780d2
Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents:
14
diff
changeset
|
99 render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL) |