OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Download files from Google Storage based on SHA1 sums.""" | 6 """Download files from Google Storage based on SHA1 sums.""" |
7 | 7 |
8 | 8 |
9 import hashlib | 9 import hashlib |
10 import optparse | 10 import optparse |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 if message: | 231 if message: |
232 print >> sys.stderr, message | 232 print >> sys.stderr, message |
233 if not max_ret_code: | 233 if not max_ret_code: |
234 print 'Success!' | 234 print 'Success!' |
235 | 235 |
236 print 'Downloading %d files took %1f second(s)' % ( | 236 print 'Downloading %d files took %1f second(s)' % ( |
237 work_queue_size, time.time() - download_start) | 237 work_queue_size, time.time() - download_start) |
238 return max_ret_code | 238 return max_ret_code |
239 | 239 |
240 | 240 |
241 def ifexists(a): | |
242 return a if os.path.exists(a) else None | |
243 | |
244 | |
241 def main(args): | 245 def main(args): |
242 usage = ('usage: %prog [options] target\n' | 246 usage = ('usage: %prog [options] target\n' |
243 'Target must be:\n' | 247 'Target must be:\n' |
244 ' (default) a sha1 sum ([A-Za-z0-9]{40}).\n' | 248 ' (default) a sha1 sum ([A-Za-z0-9]{40}).\n' |
245 ' (-s or --sha1_file) a .sha1 file, containing a sha1 sum on ' | 249 ' (-s or --sha1_file) a .sha1 file, containing a sha1 sum on ' |
246 'the first line.\n' | 250 'the first line.\n' |
247 ' (-d or --directory) A directory to scan for .sha1 files.') | 251 ' (-d or --directory) A directory to scan for .sha1 files.') |
248 parser = optparse.OptionParser(usage) | 252 parser = optparse.OptionParser(usage) |
249 parser.add_option('-o', '--output', | 253 parser.add_option('-o', '--output', |
250 help='Specify the output file name. Defaults to: ' | 254 help='Specify the output file name. Defaults to: ' |
251 '(a) Given a SHA1 hash, the name is the SHA1 hash. ' | 255 '(a) Given a SHA1 hash, the name is the SHA1 hash. ' |
252 '(b) Given a .sha1 file or directory, the name will ' | 256 '(b) Given a .sha1 file or directory, the name will ' |
253 'match (.*).sha1.') | 257 'match (.*).sha1.') |
254 parser.add_option('-b', '--bucket', | 258 parser.add_option('-b', '--bucket', |
255 help='Google Storage bucket to fetch from.') | 259 help='Google Storage bucket to fetch from.') |
256 parser.add_option('-e', '--boto', | 260 parser.add_option('-e', '--boto', |
257 help='Specify a custom boto file.') | 261 help='Specify a custom boto file.', |
262 default=ifexists(os.path.expanduser('~/.boto.depot_tools'))) | |
Ryan Tseng
2013/06/26 17:44:57
Instead of hardcoding ~/.boto.depot_toos, i'd rath
Peter Mayo
2013/06/26 18:20:54
The .netrc and .ssh configs are in the home direct
Ryan Tseng
2013/06/26 19:24:37
We have some code in run_slave.py that checks to s
| |
258 parser.add_option('-c', '--no_resume', action='store_true', | 263 parser.add_option('-c', '--no_resume', action='store_true', |
259 help='Resume download if file is partially downloaded.') | 264 help='Resume download if file is partially downloaded.') |
260 parser.add_option('-f', '--force', action='store_true', | 265 parser.add_option('-f', '--force', action='store_true', |
261 help='Force download even if local file exists.') | 266 help='Force download even if local file exists.') |
262 parser.add_option('-i', '--ignore_errors', action='store_true', | 267 parser.add_option('-i', '--ignore_errors', action='store_true', |
263 help='Don\'t throw error if we find an invalid .sha1 file.') | 268 help='Don\'t throw error if we find an invalid .sha1 file.') |
264 parser.add_option('-r', '--recursive', action='store_true', | 269 parser.add_option('-r', '--recursive', action='store_true', |
265 help='Scan folders recursively for .sha1 files. ' | 270 help='Scan folders recursively for .sha1 files. ' |
266 'Must be used with -d/--directory') | 271 'Must be used with -d/--directory') |
267 parser.add_option('-t', '--num_threads', default=1, type='int', | 272 parser.add_option('-t', '--num_threads', default=1, type='int', |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 return code | 334 return code |
330 | 335 |
331 return download_from_google_storage( | 336 return download_from_google_storage( |
332 input_filename, base_url, gsutil, options.num_threads, options.directory, | 337 input_filename, base_url, gsutil, options.num_threads, options.directory, |
333 options.recursive, options.force, options.output, options.ignore_errors, | 338 options.recursive, options.force, options.output, options.ignore_errors, |
334 options.sha1_file) | 339 options.sha1_file) |
335 | 340 |
336 | 341 |
337 if __name__ == '__main__': | 342 if __name__ == '__main__': |
338 sys.exit(main(sys.argv)) | 343 sys.exit(main(sys.argv)) |
OLD | NEW |