OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 import hashlib | 7 import hashlib |
8 import imp | 8 import imp |
9 import os | 9 import os |
10 import platform | 10 import platform |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 def remove(self, remote_path, recursive=False): | 307 def remove(self, remote_path, recursive=False): |
308 assert remote_path.startswith('gs://') | 308 assert remote_path.startswith('gs://') |
309 | 309 |
310 args = ['rm'] | 310 args = ['rm'] |
311 if recursive: | 311 if recursive: |
312 args += ['-R'] | 312 args += ['-R'] |
313 args += [remote_path] | 313 args += [remote_path] |
314 self.execute(args) | 314 self.execute(args) |
315 | 315 |
316 def CalculateChecksum(filename): | 316 def CalculateMD5Checksum(filename): |
317 """Calculate the MD5 checksum for filename.""" | 317 """Calculate the MD5 checksum for filename.""" |
318 | 318 |
319 md5 = hashlib.md5() | 319 md5 = hashlib.md5() |
320 | 320 |
321 with open(filename, 'rb') as f: | 321 with open(filename, 'rb') as f: |
322 data = f.read(65536) | 322 data = f.read(65536) |
323 while len(data) > 0: | 323 while len(data) > 0: |
324 md5.update(data) | 324 md5.update(data) |
325 data = f.read(65536) | 325 data = f.read(65536) |
326 | 326 |
327 return md5.hexdigest() | 327 return md5.hexdigest() |
328 | 328 |
329 def CreateChecksumFile(filename, mangled_filename=None): | 329 def CalculateSha256Checksum(filename): |
| 330 """Calculate the sha256 checksum for filename.""" |
| 331 |
| 332 sha = hashlib.sha256() |
| 333 |
| 334 with open(filename, 'rb') as f: |
| 335 data = f.read(65536) |
| 336 while len(data) > 0: |
| 337 sha.update(data) |
| 338 data = f.read(65536) |
| 339 |
| 340 return sha.hexdigest() |
| 341 |
| 342 def CreateMD5ChecksumFile(filename, mangled_filename=None): |
330 """Create and upload an MD5 checksum file for filename.""" | 343 """Create and upload an MD5 checksum file for filename.""" |
331 if not mangled_filename: | 344 if not mangled_filename: |
332 mangled_filename = os.path.basename(filename) | 345 mangled_filename = os.path.basename(filename) |
333 | 346 |
334 checksum = CalculateChecksum(filename) | 347 checksum = CalculateMD5Checksum(filename) |
335 checksum_filename = '%s.md5sum' % filename | 348 checksum_filename = '%s.md5sum' % filename |
336 | 349 |
337 with open(checksum_filename, 'w') as f: | 350 with open(checksum_filename, 'w') as f: |
338 f.write('%s *%s' % (checksum, mangled_filename)) | 351 f.write('%s *%s' % (checksum, mangled_filename)) |
339 | 352 |
340 return checksum_filename | 353 return checksum_filename |
341 | 354 |
| 355 def CreateSha256ChecksumFile(filename, mangled_filename=None): |
| 356 """Create and upload an sha256 checksum file for filename.""" |
| 357 if not mangled_filename: |
| 358 mangled_filename = os.path.basename(filename) |
| 359 |
| 360 checksum = CalculateSha256Checksum(filename) |
| 361 checksum_filename = '%s.sha256sum' % filename |
| 362 |
| 363 with open(checksum_filename, 'w') as f: |
| 364 f.write('%s *%s' % (checksum, mangled_filename)) |
| 365 |
| 366 return checksum_filename |
| 367 |
342 def GetChannelFromName(name): | 368 def GetChannelFromName(name): |
343 """Get the channel from the name. Bleeding edge builders don't | 369 """Get the channel from the name. Bleeding edge builders don't |
344 have a suffix.""" | 370 have a suffix.""" |
345 channel_name = string.split(name, '-').pop() | 371 channel_name = string.split(name, '-').pop() |
346 if channel_name in Channel.ALL_CHANNELS: | 372 if channel_name in Channel.ALL_CHANNELS: |
347 return channel_name | 373 return channel_name |
348 return Channel.BLEEDING_EDGE | 374 return Channel.BLEEDING_EDGE |
OLD | NEW |