-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnormalizer.py
65 lines (58 loc) · 2.43 KB
/
normalizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import bugzilla
import configuration
import logging
URL = configuration.get_config(parameter_type='bugzilla-creds', parameter_name='bugzilla_url')
bzapi = bugzilla.Bugzilla(URL)
default_product = configuration.get_config(parameter_type='default-params', parameter_name='default_product')
default_component = configuration.get_config(parameter_type='default-params', parameter_name='default_component')
def normalize_component_new(selected_component, selected_product):
# TODO Temporary fix. Figure out why sometimes None product
# print('default product is: ' + default_product + ' and default component is: ' + default_component)
if not selected_product:
selected_product = default_product
components = bzapi.getcomponents(product=selected_product)
lowered_components = [item.lower() for item in components]
if not selected_component:
return ''
if selected_component in lowered_components:
index = lowered_components.index(selected_component)
return components[index]
else:
print('selected component is not in there')
def normalize_product_new(selected_product):
if not selected_product:
selected_product = default_product
include_fields = ["name", "id"]
products = bzapi.getproducts(include_fields=include_fields)
products_list = []
for product in products:
single_product1 = str(list(product.values())[0])
single_product2 = str(list(product.values())[1])
if not isproductalpha(single_product1) and not isproductalpha(single_product2):
print('name and id are numbers, need to skip this product ' + single_product1 + " " + single_product2)
else:
if isproductalpha(single_product1):
single_product = single_product1
else:
single_product = single_product2
products_list.append(single_product)
lowered_products = [item.lower() for item in products_list]
if selected_product.lower() in lowered_products:
index = lowered_products.index(selected_product.lower())
return products_list[index]
else:
print('something\'s wrong')
def isproductalpha(product):
# TODO Fix this ugly stuff
if ' ' in product:
return True
elif '-' in product:
return True
elif '.' in product:
return True
elif '_' in product:
return True
elif product.isalpha():
return True
else:
return False