• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import hashlib
4import subprocess
5
6def RunCommand(cmd: list[str]) -> None:
7  """Construct a command line from parts and run it."""
8  try:
9    res = subprocess.run(
10        cmd,
11        check=True,
12        stdout=subprocess.PIPE,
13        universal_newlines=True,
14        stderr=subprocess.PIPE)
15  except subprocess.CalledProcessError as err:
16    print(err.stderr)
17    print(err.output)
18    raise err
19
20def GetDigest(file_path: str) -> str:
21  """Get sha512 digest of a file """
22  digester = hashlib.sha512()
23  with open(file_path, 'rb') as f:
24    bytes_to_digest = f.read()
25    digester.update(bytes_to_digest)
26    return digester.hexdigest()
27