diff options
| author | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2018-11-29 15:45:33 +0000 |
|---|---|---|
| committer | Raoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk> | 2018-12-05 15:32:22 +0000 |
| commit | 9ef1a8a261061eb7d44ca2ae91cb84cd24f0c11e (patch) | |
| tree | 63af2af209bdf8d9c249a3be70ebb13bd74af229 /buildstream/utils.py | |
| parent | eb1ed4108b75ed919f471e448fa6088b1503a328 (diff) | |
| download | buildstream-9ef1a8a261061eb7d44ca2ae91cb84cd24f0c11e.tar.gz | |
utils.py: Add message digest function
Get cascache.py to use this
Diffstat (limited to 'buildstream/utils.py')
| -rw-r--r-- | buildstream/utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index 94c990357..2fe9ab7dc 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -41,6 +41,7 @@ import psutil from . import _signals from ._exceptions import BstError, ErrorDomain +from ._protos.build.bazel.remote.execution.v2 import remote_execution_pb2 # The magic number for timestamps: 2011-11-11 11:11:11 _magic_timestamp = calendar.timegm([2011, 11, 11, 11, 11, 11]) @@ -1242,3 +1243,19 @@ def _deduplicate(iterable, key=None): def _get_link_mtime(path): path_stat = os.lstat(path) return path_stat.st_mtime + + +# _message_digest() +# +# Args: +# message_buffer (str): String to create digest of +# +# Returns: +# (remote_execution_pb2.Digest): Content digest +# +def _message_digest(message_buffer): + sha = hashlib.sha256(message_buffer) + digest = remote_execution_pb2.Digest() + digest.hash = sha.hexdigest() + digest.size_bytes = len(message_buffer) + return digest |
