annotate roundup_content_data/__init__.py @ 27:cdab667c6abb

Delete Code Duplication and Clean Up. * The search for the status does not require the "-1". * If the parameter you are looking for is not available in the tracker, an error message is issued and the program terminates, to avoid incorrect entries in the database
author Magnus Schieder <mschieder@intevation.de>
date Tue, 13 Nov 2018 21:04:22 +0100
parents 3bb3d9a9f1b7
children
rev   line source
0
3f139db894f1 initial commit
sean
parents:
diff changeset
1 #!/usr/bin/env python
3f139db894f1 initial commit
sean
parents:
diff changeset
2
3f139db894f1 initial commit
sean
parents:
diff changeset
3 """ supplys the data needed to comunicate with the roundup-server,
3f139db894f1 initial commit
sean
parents:
diff changeset
4 and the sqlite database. Represents the types of errors used in roundup.
3f139db894f1 initial commit
sean
parents:
diff changeset
5
3f139db894f1 initial commit
sean
parents:
diff changeset
6 author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
3f139db894f1 initial commit
sean
parents:
diff changeset
7 author: Bernhard Reiter <bernhard@intevation.de>
3f139db894f1 initial commit
sean
parents:
diff changeset
8 author: Sean Engelhardt <sean.engelhardt@intevation.de>
3f139db894f1 initial commit
sean
parents:
diff changeset
9
17
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
10 (c) 2010, 2015, 2018 by Intevation GmbH
0
3f139db894f1 initial commit
sean
parents:
diff changeset
11
3f139db894f1 initial commit
sean
parents:
diff changeset
12 This is Free Software unter the terms of the
3f139db894f1 initial commit
sean
parents:
diff changeset
13 GNU GENERAL PUBLIC LICENSE Version 3 or later.
3f139db894f1 initial commit
sean
parents:
diff changeset
14 See http://www.gnu.org/licenses/gpl-3.0.txt for details
3f139db894f1 initial commit
sean
parents:
diff changeset
15 """
3f139db894f1 initial commit
sean
parents:
diff changeset
16
3f139db894f1 initial commit
sean
parents:
diff changeset
17 import os
17
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
18 from typing import List
0
3f139db894f1 initial commit
sean
parents:
diff changeset
19
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
20 COLUMNS= [
0
3f139db894f1 initial commit
sean
parents:
diff changeset
21 "critical", "urgent", "bug", "feature", "wish",
3f139db894f1 initial commit
sean
parents:
diff changeset
22 ]
3f139db894f1 initial commit
sean
parents:
diff changeset
23
3f139db894f1 initial commit
sean
parents:
diff changeset
24 data_dict = {
3f139db894f1 initial commit
sean
parents:
diff changeset
25 "date": [],
3f139db894f1 initial commit
sean
parents:
diff changeset
26 "critical": [],
3f139db894f1 initial commit
sean
parents:
diff changeset
27 "urgent": [],
3f139db894f1 initial commit
sean
parents:
diff changeset
28 "bug": [],
3f139db894f1 initial commit
sean
parents:
diff changeset
29 "feature": [],
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
30 "wish": [],
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
31 "noPrio": []
0
3f139db894f1 initial commit
sean
parents:
diff changeset
32 }
3f139db894f1 initial commit
sean
parents:
diff changeset
33
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
34 #SQL
0
3f139db894f1 initial commit
sean
parents:
diff changeset
35
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
36 #DEMO System
0
3f139db894f1 initial commit
sean
parents:
diff changeset
37 SELECT_ALL = """
3f139db894f1 initial commit
sean
parents:
diff changeset
38 SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),
3f139db894f1 initial commit
sean
parents:
diff changeset
39 critical,
3f139db894f1 initial commit
sean
parents:
diff changeset
40 urgent,
3f139db894f1 initial commit
sean
parents:
diff changeset
41 bug,
3f139db894f1 initial commit
sean
parents:
diff changeset
42 feature,
3f139db894f1 initial commit
sean
parents:
diff changeset
43 wish
3f139db894f1 initial commit
sean
parents:
diff changeset
44 FROM issues
3f139db894f1 initial commit
sean
parents:
diff changeset
45 ORDER BY timestamp
3f139db894f1 initial commit
sean
parents:
diff changeset
46 """
3f139db894f1 initial commit
sean
parents:
diff changeset
47
7
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
48 SELECT_WHERE = """
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
49 SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
50 critical,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
51 urgent,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
52 bug,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
53 feature,
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
54 wish,
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
55 None
7
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
56 FROM issues
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
57 WHERE {}
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
58 ORDER BY timestamp
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
59 """
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
60
0
3f139db894f1 initial commit
sean
parents:
diff changeset
61 CREATE_DB = """
3f139db894f1 initial commit
sean
parents:
diff changeset
62 CREATE TABLE issues (
3f139db894f1 initial commit
sean
parents:
diff changeset
63 timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp,
3f139db894f1 initial commit
sean
parents:
diff changeset
64 critical INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
65 urgent INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
66 bug INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
67 feature INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
68 wish INTEGER NOT NULL DEFAULT 0
3f139db894f1 initial commit
sean
parents:
diff changeset
69 )
3f139db894f1 initial commit
sean
parents:
diff changeset
70 """
3f139db894f1 initial commit
sean
parents:
diff changeset
71
3f139db894f1 initial commit
sean
parents:
diff changeset
72
3f139db894f1 initial commit
sean
parents:
diff changeset
73 INSERT_NEW = """
3f139db894f1 initial commit
sean
parents:
diff changeset
74 INSERT INTO issues (critical, urgent, bug, feature, wish)
3f139db894f1 initial commit
sean
parents:
diff changeset
75 VALUES (?, ?, ?, ?, ?)
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
76 """
20
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
77 def build_sql_select(columns):
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
78 return """
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
79 SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
80 """+ columns + """
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
81 FROM issues
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
82 WHERE {}
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
83 ORDER BY timestamp
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
84 """
3bb3d9a9f1b7 Filter by keywords and states.
Magnus Schieder <mschieder@intevation.de>
parents: 17
diff changeset
85
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
86
17
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
87
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
88 def build_sql_commands(list_of_columns: list):
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
89 """Build sql commands for use with collect_issues.
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
90 """
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
91 create_db = ("""CREATE TABLE issues (
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
92 timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp,
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
93 """ +
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
94 ", ".join([c + " INTEGER NOT NULL DEFAULT 0"
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
95 for c in list_of_columns]) + ")")
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
96
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
97 insert_new = ("INSERT INTO issues (" + ", ".join(list_of_columns) + ") " +
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
98 "VALUES (" + ("?, "*len(list_of_columns))[:-2]+ ")")
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
99
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
100 select_tmpl = ("""SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),""" +
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
101 ", ".join(list_of_columns))
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
102
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
103 select_all = select_tmpl + "FROM issues ORDER BY timestamp"
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
104 select_where = select_tmpl + "FROM issues WHERE {} ORDER BY timestamp"
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
105
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
106 # print(select_all, select_where, create_db, insert_new)
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
107 return select_all, select_where, create_db, insert_new
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)