Mercurial > roundup-cc
annotate roundup_cc.py @ 26:761ee2351f58
Change the parameter read in.
* The structure was changed and better names used.
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Tue, 13 Nov 2018 17:55:10 +0100 |
parents | 7161ce4e7ab1 |
children | e2864dabdb8c |
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" |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
14 STATES = "unread, deferred, chatting, need_eg, in_progress, testing, done_cbb, resolved" |
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(", ") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
39 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
40 search = config.get("SEARCH", "Search", fallback="prio") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
41 if search == "prio": |
26
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
42 list_of_columns = config.get("SEARCH", "Priority", fallback=PRIO).split(", ") |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
43 status = config.get("SEARCH", "Status", fallback="").split(", ") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
44 include_no_prio = config.getboolean("SEARCH", "IncludeNoPrio", fallback= False) |
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(", ") |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
50 status = [""] |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
51 |
26
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
52 else: |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
53 print("Incorrect [SEARCH]Search parameter. (prio, status)") |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
54 return |
761ee2351f58
Change the parameter read in.
Magnus Schieder <mschieder@intevation.de>
parents:
25
diff
changeset
|
55 |
25
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
56 select_all, select_where, create_db, insert_new = \ |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
57 rcd.build_sql_commands(list_of_columns) |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
58 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
59 save_stats_in_db(search, login_parameters, base_url, database_file, |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
60 list_of_columns, create_db, insert_new, keywords, status) |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
61 |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
62 if __name__ == '__main__': |
7161ce4e7ab1
The web-based display is dynamically generated.
Magnus Schieder <mschieder@intevation.de>
parents:
diff
changeset
|
63 main() |