|
| 1 | +#!/bin/env python3 |
| 2 | + |
| 3 | +# MIT License |
| 4 | +# |
| 5 | +# Copyright (c) 2018-2019 Red Hat, Inc. |
| 6 | + |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | + |
| 25 | +import json |
| 26 | +import os |
| 27 | + |
| 28 | +from pathlib import Path |
| 29 | +from typing import Dict, Any |
| 30 | + |
| 31 | +IMAGESTREAMS_DIR: str = "imagestreams" |
| 32 | + |
| 33 | + |
| 34 | +class ShowAllImageStreams(object): |
| 35 | + version: str = "" |
| 36 | + |
| 37 | + def __init__(self): |
| 38 | + pass |
| 39 | + |
| 40 | + def load_json_file(self, filename: Path) -> Any: |
| 41 | + with open(str(filename)) as f: |
| 42 | + data = json.load(f) |
| 43 | + isinstance(data, Dict) |
| 44 | + return data |
| 45 | + |
| 46 | + def show_all_imagestreams(self): |
| 47 | + p = Path(".") |
| 48 | + json_files = p.glob(f"{IMAGESTREAMS_DIR}/*.json") |
| 49 | + if not json_files: |
| 50 | + print(f"No json files present in {IMAGESTREAMS_DIR}.") |
| 51 | + return 0 |
| 52 | + for f in json_files: |
| 53 | + if os.environ.get("TARGET") in ("rhel7", "centos7") and "aarch64" in str(f): |
| 54 | + print("Imagestream aarch64 is not supported on rhel7") |
| 55 | + continue |
| 56 | + json_dict = self.load_json_file(f) |
| 57 | + print(f"Tags in the image stream {f}:") |
| 58 | + for tag in json_dict["spec"]["tags"]: |
| 59 | + print(f"- {tag['name']} -> {tag['from']['name']}") |
| 60 | + |
| 61 | + |
| 62 | +if __name__ == "__main__": |
| 63 | + isc = ShowAllImageStreams() |
| 64 | + isc.show_all_imagestreams() |
0 commit comments