HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/relenv/manifest.py
# Copyright 2022-2026 Broadcom.
# SPDX-License-Identifier: Apache-2.0
#
"""
Relenv manifest.
"""

from __future__ import annotations

import hashlib
import os
import pathlib
import sys


def manifest(root: str | os.PathLike[str] | None = None) -> None:
    """
    List all the file in a relenv and their hashes.
    """
    base = pathlib.Path(root) if root is not None else pathlib.Path(getattr(sys, "RELENV", os.getcwd()))
    for dirpath, _dirs, files in os.walk(base):
        directory = pathlib.Path(dirpath)
        for file in files:
            hsh = hashlib.sha256()
            file_path = directory / file
            try:
                with open(file_path, "rb") as fp:
                    while True:
                        chunk = fp.read(9062)
                        if not chunk:
                            break
                        hsh.update(chunk)
            except OSError:
                pass
            print(f"{file_path} => {hsh.hexdigest()}")


if __name__ == "__main__":
    manifest()