blob: 9f9b72839353184c6bc9e30a2047f4c11c8cf8ca [file] [log] [blame]
Logan Chien6888aae2011-07-12 16:47:10 +08001#!/usr/bin/env python
Zonr Changfa52e202012-04-12 15:38:42 +08002#
3# Copyright (C) 2011-2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Logan Chien6888aae2011-07-12 16:47:10 +080017
Logan Chien6888aae2011-07-12 16:47:10 +080018import sys
19
Daniel Sandler1c131472011-07-18 10:59:17 -040020try:
21 import hashlib
22 sha1 = hashlib.sha1
23except ImportError, e:
24 import sha
25 sha1 = sha.sha
26
Logan Chien6888aae2011-07-12 16:47:10 +080027def compute_sha1(h, path):
28 f = open(path, 'rb')
29 while True:
30 buf = f.read(1024)
31 h.update(buf)
32 if len(buf) < 1024:
33 break
34 f.close()
35
36def compute_sha1_list(path_list):
Stephen Hines6975a662012-05-03 12:26:44 -070037 h = sha1()
Logan Chien6888aae2011-07-12 16:47:10 +080038 for path in path_list:
39 compute_sha1(h, path)
Stephen Hines6975a662012-05-03 12:26:44 -070040 return h.digest()
Logan Chien6888aae2011-07-12 16:47:10 +080041
42def main():
43 if len(sys.argv) < 2:
44 print 'USAGE:', sys.argv[0], '[OUTPUT] [INPUTs]'
45 sys.exit(1)
46
Stephen Hines6975a662012-05-03 12:26:44 -070047 f = open(sys.argv[1], 'wb')
48 f.write(compute_sha1_list(sys.argv[2:]))
49 f.close()
Logan Chien6888aae2011-07-12 16:47:10 +080050
51if __name__ == '__main__':
52 main()