1 #! /usr/bin/env python3
3 # Copyright (c) 2021 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 if csit_ansible_yaml is None:
44 cays = CsitAnsibleYamlStruct(**csit_ansible_yaml)
46 packages = [pkg for pkg in cays.packages_base if type(pkg) is str]
47 except AttributeError:
49 if arch in [*cays.packages_by_arch]:
50 packages += [pkg for pkg in cays.packages_by_arch[arch]
52 if distro in [*cays.packages_by_distro]:
53 packages += [pkg for pkg in cays.packages_by_distro[distro]
57 def is_csit_ansible_yaml_file(filename: str):
58 (root,ext) = os.path.splitext(filename)
60 and filename.find('csit/') >= 0 \
61 and filename.find('/ansible/') > 0 \
62 and os.path.isfile(filename):
67 def main(args: List[str]) -> None:
69 log.warning('Must have at least 1 file name')
76 if arg.lower() == '--ubuntu':
78 elif arg.lower() == '--x86_64':
80 elif arg.lower() == '--aarch64':
82 elif is_csit_ansible_yaml_file(arg):
83 pkg_list += packages_in_csit_ansible_yaml_file(arg, distro, arch)
85 log.warning(f'Invalid CSIT Ansible YAML file: {arg}')
86 pkg_list = list(set(pkg_list))
88 print(" ".join(pkg_list))
90 if __name__ == "__main__":