Force encoding while reading files in init scripts
[sdc.git] / catalog-be / src / main / resources / scripts / sdcBePy / tosca / models / normativeToUpdateList.py
1 import json
2
3 from sdcBePy.tosca.models.normativeTypeCandidate import NormativeTypeCandidate
4
5
6 class TypesToUpdate:
7
8     def __init__(self, files):
9         self.types_list = {}
10         self.load_files(files)
11
12     def load_files(self, files):
13         for file in files:
14             with open(file, 'r', encoding='utf-8') as stream:
15                 _types = json.load(stream)
16                 for type_key, type_value in _types.items():
17                     self.types_list[type_key] = type_value
18
19     def get_type(self, key):
20         return self.types_list[key]
21
22
23 def get_heat_and_normative_to_update_list(types, base_file_location):
24     return [
25         get_heat(types, base_file_location),
26         get_normative(types, base_file_location)
27     ]
28
29
30 def get_onap_sol_to_update_list(types, base_file_location):
31     return [
32         get_onap(types, base_file_location),
33         get_sol(types, base_file_location)
34     ]
35
36 def get_nfv_to_update_list(types, base_file_location):
37     return [
38         get_nfv(types, base_file_location),
39         get_nfv_2_7_1(types, base_file_location),
40         get_nfv_3_3_1(types, base_file_location),
41         get_nfv_4_1_1(types, base_file_location),
42     ]
43
44
45 def get_heat(types, base_location="/"):
46     return NormativeTypeCandidate(base_location + "heat-types/",
47                                   types.get_type("heat"))
48
49
50 def get_normative(types, base_location="/"):
51     return NormativeTypeCandidate(base_location + "normative-types/",
52                                   types.get_type("normative"))
53
54
55 def get_nfv(types, base_location="/"):
56     return NormativeTypeCandidate(base_location + "nfv-types/",
57                                   types.get_type("nfv"))
58                                   
59 def get_nfv_2_7_1(types, base_location="/"):
60     return NormativeTypeCandidate(base_location + "nfv-types/2.7.1/",
61                                   types.get_type("nfv_2_7_1"))
62
63 def get_nfv_3_3_1(types, base_location="/"):
64     return NormativeTypeCandidate(base_location + "nfv-types/3.3.1/",
65                                   types.get_type("nfv_3_3_1"))
66
67 def get_nfv_4_1_1(types, base_location="/"):
68     return NormativeTypeCandidate(base_location + "nfv-types/4.1.1/",
69                                   types.get_type("nfv_4_1_1"))
70
71 def get_onap(types, base_location="/"):
72     return NormativeTypeCandidate(base_location + "onap-types/",
73                                   types.get_type("onap"))
74
75
76 def get_sol(types, base_location="/"):
77     return NormativeTypeCandidate(base_location + "sol-types/",
78                                   types.get_type("sol"))