Chromium Code Reviews| Index: mojo/tools/mopy/transitive_hash.py |
| diff --git a/mojo/tools/mopy/transitive_hash.py b/mojo/tools/mopy/transitive_hash.py |
| index 48b6a60b21898fafd36a8c5a7bd41ef18168a3fb..23059ab54376b76e082494e00c5ed004db98bbb3 100644 |
| --- a/mojo/tools/mopy/transitive_hash.py |
| +++ b/mojo/tools/mopy/transitive_hash.py |
| @@ -2,7 +2,6 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -import hashlib |
| import logging |
| import platform |
| import subprocess |
| @@ -10,39 +9,14 @@ import sys |
| # pylint: disable=E0611 |
| from hashlib import sha256 |
| +from mopy.file_hash import file_hash |
|
viettrungluu
2014/11/25 16:45:09
I'd list the mopy imports separately from the stan
qsr
2014/11/25 17:17:49
Done.
|
| +from mopy.memoize import memoize |
| # pylint: enable=E0611 |
| from os.path import basename, realpath |
|
viettrungluu
2014/11/25 16:45:09
"
qsr
2014/11/25 17:17:49
Done.
|
| _logging = logging.getLogger() |
| -# pylint: disable=C0301 |
| -# Based on/taken from |
| -# http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/ |
| -# (with cosmetic changes). |
| -# pylint: enable=C0301 |
| -def _memoize(f): |
| - """Memoization decorator for a function taking a single argument.""" |
| - class Memoize(dict): |
| - def __missing__(self, key): |
| - rv = self[key] = f(key) |
| - return rv |
| - return Memoize().__getitem__ |
| - |
| -@_memoize |
| -def _file_hash(filename): |
| - """Returns a string representing the hash of the given file.""" |
| - _logging.debug("Hashing %s ...", filename) |
| - with open(filename, mode='rb') as f: |
| - m = hashlib.sha256() |
| - while True: |
| - block = f.read(4096) |
| - if not block: |
| - break |
| - m.update(block) |
| - _logging.debug(" => %s", m.hexdigest()) |
| - return m.hexdigest() |
| - |
| -@_memoize |
| +@memoize |
| def _get_dependencies(filename): |
| """Returns a list of filenames for files that the given file depends on.""" |
| if platform.system() == 'Windows': |
| @@ -69,7 +43,7 @@ def transitive_hash(filename): |
| to_hash = [filename] |
| while to_hash: |
| current_filename = realpath(to_hash.pop()) |
| - current_hash = _file_hash(current_filename) |
| + current_hash = file_hash(current_filename) |
| if current_hash in hashes: |
| _logging.debug("Already seen %s (%s) ...", current_filename, current_hash) |
| continue |