Mercurial > roundup-cc
annotate roundup_cc.py @ 36:59e1659a0a0b tip
Update 'TODO.creole'
* Old TODOs moved to 'doc/old_TODO.creole'
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Mon, 26 Nov 2018 16:52:45 +0100 |
parents | 80bbd06fe8ec |
children |
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 |
32 | 13 # Default priorities of 'roundup'. |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
14 PRIO = "critical, urgent, bug, feature, wish" |
32 | 15 # Default statuses of 'roundup'. |
28
e2864dabdb8c
fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents:
26
diff
changeset
|
16 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
|
17 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
18 def main(): |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
19 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
20 parser = argparse.ArgumentParser() |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
21 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
|
22 args = parser.parse_args() |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
23 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
24 config = configparser.ConfigParser() |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
25 config.read(args.config_file) |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
26 |
32 | 27 # URL of the issue tracker |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
28 base_url = config.get("URL", "BaseURL") |
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 user = config.get("LOGIN","Username") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
31 password = config.get("LOGIN", "Password") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
32 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
33 login_parameters = ( |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
34 ("__login_name", user), |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
35 ("__login_password", password), |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
36 ("@action", "Login"), |
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 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
39 database_file = config.get("DB", "DatabaseFile") |
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 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
|
42 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
|
43 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
44 search = config.get("SEARCH", "Search", fallback="prio") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
45 if search == "prio": |
26
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
46 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
|
47 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
|
48 if include_no_prio: |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
49 list_of_columns += ["None"] |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
50 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
51 elif search == "status": |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
52 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
|
53 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
|
54 if include_no_prio: |
9aca070c86bd
Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents:
28
diff
changeset
|
55 search_parameters += ["None"] |
9aca070c86bd
Add the filter 'priority' for the search by status.
Magnus Schieder <mschieder@intevation.de>
parents:
28
diff
changeset
|
56 |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
57 |
26
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
58 else: |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
59 print("Incorrect [SEARCH]Search parameter. (prio, status)") |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
60 return |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
61 |
28
e2864dabdb8c
fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents:
26
diff
changeset
|
62 # 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
|
63 sql_list_of_columns = [] |
e2864dabdb8c
fixes a logical error in the filtering of columns.
Magnus Schieder <mschieder@intevation.de>
parents:
26
diff
changeset
|
64 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
|
65 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
|
66 |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
67 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
|
68 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
|
69 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
70 save_stats_in_db(search, login_parameters, base_url, database_file, |
32 | 71 list_of_columns, create_db, insert_new, keywords, |
72 search_parameters, include_no_prio) | |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
73 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
74 if __name__ == '__main__': |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
75 main() |