annotate roundup_cc.py @ 31:9aca070c86bd

Add the filter 'priority' for the search by status.
author Magnus Schieder <mschieder@intevation.de>
date Thu, 22 Nov 2018 19:34:53 +0100
parents e2864dabdb8c
children 80bbd06fe8ec
rev   line source
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python3
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
2 """Connect to roundup-tracker and save status to db.
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
3
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
4 Run periodically as often as you want data points to be saved.
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
5 """
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
6
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
7 import configparser
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
8 import argparse
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
9
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
10 from collect_issues import save_stats_in_db
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
11 import roundup_content_data as rcd
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
12
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
13 PRIO = "critical, urgent, bug, feature, wish"
28
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
14 STATES = "unread, deferred, chatting, need-eg, in-progress, testing, done-cbb, resolved"
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
15
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
16 def main():
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
17
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
18 parser = argparse.ArgumentParser()
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
19 parser.add_argument("config_file", type=str, metavar="[config file]")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
20 args = parser.parse_args()
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
21
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
22 config = configparser.ConfigParser()
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
23 config.read(args.config_file)
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
24
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
25 base_url = config.get("URL", "BaseURL")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
26
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
27 user = config.get("LOGIN","Username")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
28 password = config.get("LOGIN", "Password")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
29
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
30 login_parameters = (
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
31 ("__login_name", user),
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
32 ("__login_password", password),
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
33 ("@action", "Login"),
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
34 )
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
35
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
36 database_file = config.get("DB", "DatabaseFile")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
37
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
38 keywords = config.get("SEARCH", "Keywords", fallback="").split(", ")
31
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
39 include_no_prio = config.getboolean("SEARCH", "IncludeNoPrio", fallback= False)
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
40
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
41 search = config.get("SEARCH", "Search", fallback="prio")
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
42 if search == "prio":
26
761ee2351f58 Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents: 25
diff changeset
43 list_of_columns = config.get("SEARCH", "Priority", fallback=PRIO).split(", ")
31
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
44 search_parameters = config.get("SEARCH", "Status", fallback="").split(", ")
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
45 if include_no_prio:
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
46 list_of_columns += ["None"]
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
47
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
48 elif search == "status":
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
49 list_of_columns = config.get("SEARCH", "Status", fallback=STATES).split(", ")
31
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
50 # statsu = columns Must change
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
51 search_parameters = config.get("SEARCH", "Priority", fallback="").split(", ")
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
52 if include_no_prio:
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
53 search_parameters += ["None"]
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
54
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
55
26
761ee2351f58 Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents: 25
diff changeset
56 else:
761ee2351f58 Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents: 25
diff changeset
57 print("Incorrect [SEARCH]Search parameter. (prio, status)")
761ee2351f58 Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents: 25
diff changeset
58 return
761ee2351f58 Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents: 25
diff changeset
59
28
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
60 # roundup uses a "-" in its search parameters. Sql can't handle it.
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
61 sql_list_of_columns = []
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
62 for column in list_of_columns:
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
63 sql_list_of_columns.append(column.replace("-", "_"))
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
64
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
65 select_all, select_where, create_db, insert_new = \
28
e2864dabdb8c fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents: 26
diff changeset
66 rcd.build_sql_commands(sql_list_of_columns)
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
67
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
68 save_stats_in_db(search, login_parameters, base_url, database_file,
31
9aca070c86bd Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents: 28
diff changeset
69 list_of_columns, create_db, insert_new, keywords, search_parameters, include_no_prio)
25
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
70
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
71 if __name__ == '__main__':
7161ce4e7ab1 The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff changeset
72 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)