summaryrefslogtreecommitdiff
path: root/buildstream/_cachekey.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-04 12:28:58 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2018-01-04 12:30:12 +0000
commit3628cbbe0ec04e4f6e202d473a04a8fb3cf60840 (patch)
tree80cde7c589f48caf663ba43da8a70af5a625c0d6 /buildstream/_cachekey.py
parentbb8f807bc6f5bcc6259bc06d6995b7f0bc2c6076 (diff)
downloadbuildstream-3628cbbe0ec04e4f6e202d473a04a8fb3cf60840.tar.gz
Move utils._generate_key() into a new 'cachekey' module
This avoids a circular dependency between the 'utils' and '_yaml' modules.
Diffstat (limited to 'buildstream/_cachekey.py')
-rw-r--r--buildstream/_cachekey.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/buildstream/_cachekey.py b/buildstream/_cachekey.py
new file mode 100644
index 000000000..3d0c19b44
--- /dev/null
+++ b/buildstream/_cachekey.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2018 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
+
+
+import hashlib
+import pickle
+
+from . import _yaml
+
+
+# generate_key()
+#
+# Generate an sha256 hex digest from the given value. The value
+# can be a simple value or recursive dictionary with lists etc,
+# anything simple enough to serialize.
+#
+# Args:
+# value: A value to get a key for
+#
+# Returns:
+# (str): An sha256 hex digest of the given value
+#
+def generate_key(value):
+ ordered = _yaml.node_sanitize(value)
+ string = pickle.dumps(ordered)
+ return hashlib.sha256(string).hexdigest()