4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
20 # following libs are found from openssl, libgcrypto, openssh with rpm -qR
21 # in the future, the libs need to be updated with exact version number
23 input_capabilities = []
32 'python2-cryptography',
41 'python2-cryptography',
43 'xstatic-jsencrypt-common',
46 crypto_capabilities = [
52 def output_rpm_command(lib, command):
55 output = subprocess.check_output(command)
61 def build_capability_list_dynamically():
66 '[%{=NAME}-%{VERSION}-%{RELEASE}.%{ARCH} %{PROVIDES}\n]']
67 output = subprocess.check_output(command)
68 for item in output.splitlines():
69 items = item.split(' ')
71 if items[0] in map_dict:
72 capa_list = map_dict[items[0]]
73 capa_list.append(items[1])
74 map_dict[items[0]] = capa_list
76 map_dict[items[0]] = [items[1]]
77 for rpms, caps in map_dict.items():
79 for item in crypto_capabilities:
80 if cap.startswith(item):
81 if cap not in input_capabilities:
82 input_capabilities.append(cap)
83 command = ['rpm', '-q', '--whatprovides']
84 output = output_rpm_command(cap, command)
85 name = output.strip('\n')
86 result = filter(lambda rpm: rpm['name'] == name, output_rpms)
88 output_rpms.append({'name': name, 'provides': [cap]})
90 sources_list = result[0]['provides']
91 if cap not in sources_list:
92 sources_list.append(cap)
95 def capability_dependencies_with_whatrequires():
96 for capability in input_capabilities:
97 command = ['rpm', '-q', '--whatrequires']
98 output = output_rpm_command(capability, command)
100 for item in output.splitlines():
101 result = filter(lambda rpm: rpm['name'] == item, output_rpms)
103 output_rpms.append({'name': item, 'requires': [capability]})
105 sources_list = result[0]['requires']
106 if capability not in sources_list:
107 sources_list.append(capability)
110 def package_dependencies_with_provides():
111 for package in input_packages:
112 command = ['rpm', '-q']
113 name = output_rpm_command(package, command)
114 name = name.strip('\n')
115 output_rpms.append({'name': name, 'requires': []})
116 command = ['rpm', '-ql', '--provides']
117 output = output_rpm_command(package, command)
118 for item in output.splitlines():
119 input_capabilities.append(item)
122 if __name__ == '__main__':
123 build_capability_list_dynamically()
124 package_dependencies_with_provides()
125 capability_dependencies_with_whatrequires()
126 rpms_json = json.dumps(output_rpms, sort_keys=True, indent=4)
127 with open(sys.argv[1], "w") as f: