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

Side by Side Diff: build/android/gyp/util/md5_check.py

Issue 13432002: Add input content checking to some build scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import hashlib
6 import os
7
8
9 def UpdateMd5ForFile(md5, path, block_size=2**16):
10 with open(path, 'rb') as infile:
11 while True:
12 data = infile.read(block_size)
13 if not data:
14 break
15 md5.update(data)
16
17
18 def UpdateMd5ForDirectory(md5, dir_path):
19 for root, _, files in os.walk(dir_path):
20 for f in files:
21 UpdateMd5ForFile(md5, os.path.join(root, f))
22
23
24 def UpdateMd5ForPath(md5, path):
25 if os.path.isdir(path):
26 UpdateMd5ForDirectory(md5, path)
27 else:
28 UpdateMd5ForFile(md5, path)
29
30
31 class Md5Checker(object):
32 def __init__(self, stamp=None, inputs=[], command=[]):
33 self.stamp = stamp
34
35 md5 = hashlib.md5()
36 for i in inputs:
37 UpdateMd5ForPath(md5, i)
38 for s in command:
39 md5.update(s)
40 self.new_digest = md5.hexdigest()
41
42 self.old_digest = ''
43 if os.path.exists(stamp):
44 with open(stamp, 'r') as old_stamp:
45 self.old_digest = old_stamp.read()
46
47 def IsStale(self):
48 return self.old_digest != self.new_digest
49
50 def Write(self):
51 with open(self.stamp, 'w') as new_stamp:
52 new_stamp.write(self.new_digest)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698