Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1919)

Unified Diff: mojo/tools/mopy/file_hash.py

Issue 728783003: Add infrastructure to run tests on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/tools/mopy/file_hash.py
diff --git a/mojo/tools/mopy/file_hash.py b/mojo/tools/mopy/file_hash.py
new file mode 100644
index 0000000000000000000000000000000000000000..63809694547beb778dcd228635ee28c71446ad9f
--- /dev/null
+++ b/mojo/tools/mopy/file_hash.py
@@ -0,0 +1,26 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+
+# pylint: disable=E0611
+from hashlib import sha256
+from mopy.memoize import memoize
+# pylint: enable=E0611
viettrungluu 2014/11/25 16:45:09 I think you can re-enable this after the hashlib i
qsr 2014/11/25 17:17:49 Done.
+
+_logging = logging.getLogger()
+
+@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 = sha256()
+ while True:
+ block = f.read(4096)
+ if not block:
+ break
+ m.update(block)
+ _logging.debug(" => %s", m.hexdigest())
+ return m.hexdigest()

Powered by Google App Engine
This is Rietveld 408576698