comparison collect_issues.py @ 15:d0c439d1e833

Prepare for tracker entries without priority. * Extend issues_to_quantities to count entries with priority 'None'. The regular classic template enforces a priority value, but some trackers don't, e.g. the 'fast-decomposed' variant used by Intevation (https://hg.intevation.de/roundup/fast-decomposed/) uses other fields for a scrum like workflow that show the order of issues as a float value. In order to get all issues, we also have to collect them. Implement it in a backwards compatible manner for save_stats_in_db() by a keyword argument that is off by default. This is just a preparation as the database must also accept an additional column. * Cleanup some superfluous whitespace, remove an unused import and add copyright 208 year.
author Bernhard Reiter <bernhard@intevation.de>
date Fri, 06 Jul 2018 17:36:21 +0200
parents e95f7bee8643
children adca5b3780d2
comparison
equal deleted inserted replaced
14:b5f7a439bddd 15:d0c439d1e833
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2
3 """ Fetch issues from a roundup-tracker and save them in a databse. 2 """ Fetch issues from a roundup-tracker and save them in a databse.
4 3
5 author: Sascha L. Teichmann <sascha.teichmann@intevation.de> 4 author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
6 author: Bernhard Reiter <bernhard@intevation.de> 5 author: Bernhard Reiter <bernhard@intevation.de>
7 author: Sean Engelhardt <sean.engelhardt@intevation.de> 6 author: Sean Engelhardt <sean.engelhardt@intevation.de>
8 7
9 (c) 2010,2015 by Intevation GmbH 8 (c) 2010, 2015, 2018 by Intevation GmbH
10 9
11 This is Free Software unter the terms of the 10 This is Free Software unter the terms of the
12 GNU GENERAL PUBLIC LICENSE Version 3 or later. 11 GNU GENERAL PUBLIC LICENSE Version 3 or later.
13 See http://www.gnu.org/licenses/gpl-3.0.txt for details 12 See http://www.gnu.org/licenses/gpl-3.0.txt for details
14 13
32 import urllib.request 31 import urllib.request
33 import csv 32 import csv
34 import io 33 import io
35 import sqlite3 as db 34 import sqlite3 as db
36 import os 35 import os
37 import roundup_content_data as rcd
38 36
39 37
40 CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order" 38 CHECK_ROUNDUP_ORDER = "priority?@action=export_csv&@columns=id,order"
41 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id&@filter=open&open=1" 39 CHECK_ROUNDUP_SEARCH_VALUES = "status?@action=export_csv&@columns=id&@filter=open&open=1"
42 SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status&@pagesize=500&@startwith=0&status=-1,{search_values}" 40 SEARCH_ROUNDUP = "issue?@action=export_csv&@columns=priority&@filter=status&@pagesize=500&@startwith=0&status=-1,{search_values}"
90 if con: 88 if con:
91 con.close() 89 con.close()
92 90
93 91
94 def issues_to_quantities(issue_csv, columns, orders_csv): 92 def issues_to_quantities(issue_csv, columns, orders_csv):
93 """Count issues per priority.
95 94
96 quantities = [0] * len(columns) 95 Returns: a list of ints, containing how often a prio occurred [:-1]
96 in order of the priorities, with the last being the "None" prio
97 """
98
99 quantities = [0] * (len(columns) +1)
97 order_dict = {} 100 order_dict = {}
98 101
99 #convert the csv-dict reader to real dict 102 #convert the csv-dict reader to real dict
100 for row in orders_csv: 103 for row in orders_csv:
101 order_dict[row["id"]] = int(float(row["order"])) # int(float()) because the order-value is indeed "1.0, 2.0" etc 104 order_dict[row["id"]] = int(float(row["order"])) # int(float()) because the order-value is indeed "1.0, 2.0" etc
103 for issue in issue_csv: 106 for issue in issue_csv:
104 priority = issue["priority"] 107 priority = issue["priority"]
105 108
106 if priority.isdigit() == True : 109 if priority.isdigit() == True :
107 quantities[order_dict[priority] -1 ] += 1 110 quantities[order_dict[priority] -1 ] += 1
111 else: # no priority set
112 quantities[-1] += 1
108 113
109 # print("quantities : " + str(quantities)) 114 # print("quantities : " + str(quantities))
110 115
111 return quantities 116 return quantities
112 117
113 118
114 def save_issues_to_db(quantities, database_file, sql_create_db, sql_insert_in_db): 119 def save_issues_to_db(quantities, database_file, sql_create_db, sql_insert_in_db):
131 cur.close() 136 cur.close()
132 if con: 137 if con:
133 con.close() 138 con.close()
134 139
135 140
136 def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, searchurl=False): 141 def save_stats_in_db(login_parmeters, baseurl, db_file, columns, sql_create_db, sql_insert_in_db, searchurl=False, include_no_prio=False):
137 try: 142 try:
138 143
139 opener = connect_to_server(login_parmeters, baseurl) 144 opener = connect_to_server(login_parmeters, baseurl)
140 145
141 search_operators_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES) 146 search_operators_csv = get_csv_from_server(opener, baseurl, CHECK_ROUNDUP_SEARCH_VALUES)
149 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url) 154 current_issues_csv = get_csv_from_server(opener, baseurl, formated_search_url)
150 155
151 opener.close() 156 opener.close()
152 157
153 quantities = issues_to_quantities(current_issues_csv, columns, order_csv) 158 quantities = issues_to_quantities(current_issues_csv, columns, order_csv)
159 if not include_no_prio:
160 quantities = quantities[:-1]
154 161
155 save_issues_to_db(quantities, db_file, sql_create_db, sql_insert_in_db) 162 save_issues_to_db(quantities, db_file, sql_create_db, sql_insert_in_db)
156 163
157 except urllib.error.URLError as e: 164 except urllib.error.URLError as e:
158 print("No Valid Connection to server : " + baseurl + "\nerror: " + str(e)) 165 print("No Valid Connection to server : " + baseurl + "\nerror: " + str(e))
159
160
161
162
163
164
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)