1 #! /usr/bin/env python3
3 # Copyright (c) 2020 Cisco and/or its affiliates.
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.
19 from typing import List
23 logging.basicConfig(format='%(message)s')
24 log = logging.getLogger(__name__)
26 def print_yaml_struct(yaml_struct, depth=0):
28 for k,v in sorted(yaml_struct.items(), key=lambda x: x[0]):
29 if isinstance(v, dict):
30 log.warning(f"{indent}{k}")
31 print_yaml_struct(v, depth+1)
33 log.warning(f"{indent}{k} {v}")
35 class CsitAnsibleYamlStruct:
36 def __init__(self, **entries):
37 self.__dict__.update(entries)
39 def packages_in_csit_ansible_yaml_file(yamlfile: str, distro, arch) -> list:
40 with open(yamlfile) as yf:
41 csit_ansible_yaml = yaml.safe_load(yf)
42 cays = CsitAnsibleYamlStruct(**csit_ansible_yaml)
43 packages = [pkg for pkg in cays.packages_base if type(pkg) is str]
44 if arch in [*cays.packages_by_arch]:
45 packages += [pkg for pkg in cays.packages_by_arch[arch]
47 if distro in [*cays.packages_by_distro]:
48 packages += [pkg for pkg in cays.packages_by_distro[distro]
52 def is_csit_ansible_yaml_file(filename: str):
53 (root,ext) = os.path.splitext(filename)
55 and filename.find('csit/') >= 0 \
56 and filename.find('/ansible/') > 0 \
57 and os.path.isfile(filename):
62 def main(args: List[str]) -> None:
64 log.warning('Must have at least 1 file name')
71 if arg.lower() == '--ubuntu':
73 elif arg.lower() == '--centos':
75 elif arg.lower() == '--x86_64':
77 elif arg.lower() == '--aarch64':
79 elif is_csit_ansible_yaml_file(arg):
80 pkg_list += packages_in_csit_ansible_yaml_file(arg, distro, arch)
82 log.warning(f'Invalid CSIT Ansible YAML file: {arg}')
83 pkg_list = list(set(pkg_list))
85 print(" ".join(pkg_list))
87 if __name__ == "__main__":