Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
Zonr Chang | fa52e20 | 2012-04-12 15:38:42 +0800 | [diff] [blame] | 2 | # |
| 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 Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 17 | |
Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 18 | import sys |
| 19 | |
Daniel Sandler | 1c13147 | 2011-07-18 10:59:17 -0400 | [diff] [blame] | 20 | try: |
| 21 | import hashlib |
| 22 | sha1 = hashlib.sha1 |
| 23 | except ImportError, e: |
| 24 | import sha |
| 25 | sha1 = sha.sha |
| 26 | |
Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 27 | def 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 | |
| 36 | def compute_sha1_list(path_list): |
Stephen Hines | 6975a66 | 2012-05-03 12:26:44 -0700 | [diff] [blame] | 37 | h = sha1() |
Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 38 | for path in path_list: |
| 39 | compute_sha1(h, path) |
Stephen Hines | 6975a66 | 2012-05-03 12:26:44 -0700 | [diff] [blame] | 40 | return h.digest() |
Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 41 | |
| 42 | def main(): |
| 43 | if len(sys.argv) < 2: |
| 44 | print 'USAGE:', sys.argv[0], '[OUTPUT] [INPUTs]' |
| 45 | sys.exit(1) |
| 46 | |
Stephen Hines | 6975a66 | 2012-05-03 12:26:44 -0700 | [diff] [blame] | 47 | f = open(sys.argv[1], 'wb') |
| 48 | f.write(compute_sha1_list(sys.argv[2:])) |
| 49 | f.close() |
Logan Chien | 6888aae | 2011-07-12 16:47:10 +0800 | [diff] [blame] | 50 | |
| 51 | if __name__ == '__main__': |
| 52 | main() |