annotate roundup_content_data/__init__.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 99e2e0e17103
children 3bb3d9a9f1b7
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": [],
3f139db894f1 initial commit
sean
parents:
diff changeset
30 "wish": []
3f139db894f1 initial commit
sean
parents:
diff changeset
31 }
3f139db894f1 initial commit
sean
parents:
diff changeset
32
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
33 #SQL
0
3f139db894f1 initial commit
sean
parents:
diff changeset
34
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
35 #DEMO System
0
3f139db894f1 initial commit
sean
parents:
diff changeset
36 SELECT_ALL = """
3f139db894f1 initial commit
sean
parents:
diff changeset
37 SELECT strftime("%Y-%m-%dT%H:%M:%S", timestamp),
3f139db894f1 initial commit
sean
parents:
diff changeset
38 critical,
3f139db894f1 initial commit
sean
parents:
diff changeset
39 urgent,
3f139db894f1 initial commit
sean
parents:
diff changeset
40 bug,
3f139db894f1 initial commit
sean
parents:
diff changeset
41 feature,
3f139db894f1 initial commit
sean
parents:
diff changeset
42 wish
3f139db894f1 initial commit
sean
parents:
diff changeset
43 FROM issues
3f139db894f1 initial commit
sean
parents:
diff changeset
44 ORDER BY timestamp
3f139db894f1 initial commit
sean
parents:
diff changeset
45 """
3f139db894f1 initial commit
sean
parents:
diff changeset
46
7
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
47 SELECT_WHERE = """
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
48 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
49 critical,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
50 urgent,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
51 bug,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
52 feature,
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
53 wish
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
54 FROM issues
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
55 WHERE {}
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
56 ORDER BY timestamp
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
57 """
99e2e0e17103 Adding possibility and example to filter the entries.
Bernhard Reiter <bernhard@intevation.de>
parents: 1
diff changeset
58
0
3f139db894f1 initial commit
sean
parents:
diff changeset
59 CREATE_DB = """
3f139db894f1 initial commit
sean
parents:
diff changeset
60 CREATE TABLE issues (
3f139db894f1 initial commit
sean
parents:
diff changeset
61 timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp,
3f139db894f1 initial commit
sean
parents:
diff changeset
62 critical INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
63 urgent INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
64 bug INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
65 feature INTEGER NOT NULL DEFAULT 0,
3f139db894f1 initial commit
sean
parents:
diff changeset
66 wish INTEGER NOT NULL DEFAULT 0
3f139db894f1 initial commit
sean
parents:
diff changeset
67 )
3f139db894f1 initial commit
sean
parents:
diff changeset
68 """
3f139db894f1 initial commit
sean
parents:
diff changeset
69
3f139db894f1 initial commit
sean
parents:
diff changeset
70
3f139db894f1 initial commit
sean
parents:
diff changeset
71 INSERT_NEW = """
3f139db894f1 initial commit
sean
parents:
diff changeset
72 INSERT INTO issues (critical, urgent, bug, feature, wish)
3f139db894f1 initial commit
sean
parents:
diff changeset
73 VALUES (?, ?, ?, ?, ?)
1
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
74 """
2df45f6ecd81 new appereance (solid and dotted lines), resonsive layout, new legend,
sean
parents: 0
diff changeset
75
17
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
76
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
77 def build_sql_commands(list_of_columns: list):
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
78 """Build sql commands for use with collect_issues.
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
79 """
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
80 create_db = ("""CREATE TABLE issues (
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
81 timestamp TIMESTAMP NOT NULL UNIQUE DEFAULT current_timestamp,
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
82 """ +
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
83 ", ".join([c + " INTEGER NOT NULL DEFAULT 0"
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
84 for c in list_of_columns]) + ")")
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
85
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
86 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
87 "VALUES (" + ("?, "*len(list_of_columns))[:-2]+ ")")
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
88
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
89 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
90 ", ".join(list_of_columns))
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
91
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
92 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
93 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
94
adca5b3780d2 Add collecting no-prio issues. Restructure.
Bernhard Reiter <bernhard@intevation.de>
parents: 7
diff changeset
95 # 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
96 return select_all, select_where, create_db, insert_new
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)