Bug 1391789 - Make hash_path() a "public" API; r?dustin
So we can use it from another module without feeling dirty.
MozReview-Commit-ID: 1TCk9dda6mL
--- a/taskcluster/taskgraph/util/hash.py
+++ b/taskcluster/taskgraph/util/hash.py
@@ -5,17 +5,21 @@
from __future__ import absolute_import, print_function, unicode_literals
from mozbuild.util import memoize
from mozpack.files import FileFinder
import mozpack.path as mozpath
import hashlib
@memoize
-def _hash_path(path):
+def hash_path(path):
+ """Hash a single file.
+
+ Returns the SHA-256 hash in hex form.
+ """
with open(path) as fh:
return hashlib.sha256(fh.read()).hexdigest()
def hash_paths(base_path, patterns):
"""
Give a list of path patterns, return a digest of the contents of all
the corresponding files, similarly to git tree objects or mercurial
@@ -30,12 +34,12 @@ def hash_paths(base_path, patterns):
for pattern in patterns:
found = list(finder.find(pattern))
if found:
files.update(found)
else:
raise Exception('%s did not match anything' % pattern)
for path in sorted(files.keys()):
h.update('{} {}\n'.format(
- _hash_path(mozpath.abspath(mozpath.join(base_path, path))),
+ hash_path(mozpath.abspath(mozpath.join(base_path, path))),
mozpath.normsep(path)
))
return h.hexdigest()