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 """Archives or replays webpages and creates SKPs in a Google Storage location. | 6 """Archives or replays webpages and creates SKPs in a Google Storage location. |
7 | 7 |
8 To archive webpages and store SKP files (archives should be rarely updated): | 8 To archive webpages and store SKP files (archives should be rarely updated): |
9 | 9 |
10 cd skia | 10 cd skia |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 fine_grained_acl_list=GS_FINE_GRAINED_ACL_LIST) | 368 fine_grained_acl_list=GS_FINE_GRAINED_ACL_LIST) |
369 | 369 |
370 print '\n\n=======New SKPs have been uploaded to %s =======\n\n' % ( | 370 print '\n\n=======New SKPs have been uploaded to %s =======\n\n' % ( |
371 posixpath.join(self.gs.target_name(), dest_dir_name, | 371 posixpath.join(self.gs.target_name(), dest_dir_name, |
372 SKPICTURES_DIR_NAME)) | 372 SKPICTURES_DIR_NAME)) |
373 | 373 |
374 if self._upload_to_partner_bucket: | 374 if self._upload_to_partner_bucket: |
375 print '\n\n=======Uploading to Partner bucket %s =======\n\n' % ( | 375 print '\n\n=======Uploading to Partner bucket %s =======\n\n' % ( |
376 PARTNERS_GS_BUCKET) | 376 PARTNERS_GS_BUCKET) |
377 partner_gs = GoogleStorageDataStore(PARTNERS_GS_BUCKET) | 377 partner_gs = GoogleStorageDataStore(PARTNERS_GS_BUCKET) |
| 378 partner_gs.delete_path(SKPICTURES_DIR_NAME) |
378 partner_gs.upload_dir_contents( | 379 partner_gs.upload_dir_contents( |
379 os.path.join(LOCAL_PLAYBACK_ROOT_DIR, SKPICTURES_DIR_NAME), | 380 os.path.join(LOCAL_PLAYBACK_ROOT_DIR, SKPICTURES_DIR_NAME), |
380 dest_dir=SKPICTURES_DIR_NAME, | 381 dest_dir=SKPICTURES_DIR_NAME, |
381 upload_if=gs_utils.GSUtils.UploadIf.IF_MODIFIED) | 382 upload_if=gs_utils.GSUtils.UploadIf.IF_MODIFIED) |
382 print '\n\n=======New SKPs have been uploaded to %s =======\n\n' % ( | 383 print '\n\n=======New SKPs have been uploaded to %s =======\n\n' % ( |
383 posixpath.join(partner_gs.target_name(), SKPICTURES_DIR_NAME)) | 384 posixpath.join(partner_gs.target_name(), SKPICTURES_DIR_NAME)) |
384 else: | 385 else: |
385 print '\n\n=======Not Uploading to %s=======\n\n' % self.gs.target_type() | 386 print '\n\n=======Not Uploading to %s=======\n\n' % self.gs.target_type() |
386 print 'Generated resources are available in %s\n\n' % ( | 387 print 'Generated resources are available in %s\n\n' % ( |
387 LOCAL_PLAYBACK_ROOT_DIR) | 388 LOCAL_PLAYBACK_ROOT_DIR) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 self._data_store_url = data_store_url | 487 self._data_store_url = data_store_url |
487 self._bucket = remove_prefix(self._data_store_url.lstrip(), | 488 self._bucket = remove_prefix(self._data_store_url.lstrip(), |
488 gs_utils.GS_PREFIX) | 489 gs_utils.GS_PREFIX) |
489 self.gs = gs_utils.GSUtils() | 490 self.gs = gs_utils.GSUtils() |
490 def target_name(self): | 491 def target_name(self): |
491 return self._data_store_url | 492 return self._data_store_url |
492 def target_type(self): | 493 def target_type(self): |
493 return 'Google Storage' | 494 return 'Google Storage' |
494 def does_storage_object_exist(self, *args): | 495 def does_storage_object_exist(self, *args): |
495 return self.gs.does_storage_object_exist(self._bucket, *args) | 496 return self.gs.does_storage_object_exist(self._bucket, *args) |
| 497 def delete_path(self, path): |
| 498 return self.gs.delete_file(self._bucket, path) |
496 def download_file(self, *args): | 499 def download_file(self, *args): |
497 self.gs.download_file(self._bucket, *args) | 500 self.gs.download_file(self._bucket, *args) |
498 def upload_dir_contents(self, source_dir, **kwargs): | 501 def upload_dir_contents(self, source_dir, **kwargs): |
499 self.gs.upload_dir_contents(source_dir, self._bucket, **kwargs) | 502 self.gs.upload_dir_contents(source_dir, self._bucket, **kwargs) |
500 | 503 |
501 class LocalFileSystemDataStore(DataStore): | 504 class LocalFileSystemDataStore(DataStore): |
502 def __init__(self, data_store_location): | 505 def __init__(self, data_store_location): |
503 self._base_dir = data_store_location | 506 self._base_dir = data_store_location |
504 def target_name(self): | 507 def target_name(self): |
505 return self._base_dir | 508 return self._base_dir |
506 def target_type(self): | 509 def target_type(self): |
507 return self._base_dir | 510 return self._base_dir |
508 def does_storage_object_exist(self, name, *args): | 511 def does_storage_object_exist(self, name, *args): |
509 return os.path.isfile(os.path.join(self._base_dir, name)) | 512 return os.path.isfile(os.path.join(self._base_dir, name)) |
| 513 def delete_path(self, path): |
| 514 shutil.rmtree(path) |
510 def download_file(self, name, local_path, *args): | 515 def download_file(self, name, local_path, *args): |
511 shutil.copyfile(os.path.join(self._base_dir, name), local_path) | 516 shutil.copyfile(os.path.join(self._base_dir, name), local_path) |
512 def upload_dir_contents(self, source_dir, dest_dir, **kwargs): | 517 def upload_dir_contents(self, source_dir, dest_dir, **kwargs): |
513 def copytree(source_dir, dest_dir): | 518 def copytree(source_dir, dest_dir): |
514 if not os.path.exists(dest_dir): | 519 if not os.path.exists(dest_dir): |
515 os.makedirs(dest_dir) | 520 os.makedirs(dest_dir) |
516 for item in os.listdir(source_dir): | 521 for item in os.listdir(source_dir): |
517 source = os.path.join(source_dir, item) | 522 source = os.path.join(source_dir, item) |
518 dest = os.path.join(dest_dir, item) | 523 dest = os.path.join(dest_dir, item) |
519 if os.path.isdir(source): | 524 if os.path.isdir(source): |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 '--skia_tools is specified then the debugger is not run.', | 590 '--skia_tools is specified then the debugger is not run.', |
586 default=False) | 591 default=False) |
587 option_parser.add_option( | 592 option_parser.add_option( |
588 '', '--skp_prefix', | 593 '', '--skp_prefix', |
589 help='Prefix to add to the names of generated SKPs.', | 594 help='Prefix to add to the names of generated SKPs.', |
590 default=None) | 595 default=None) |
591 options, unused_args = option_parser.parse_args() | 596 options, unused_args = option_parser.parse_args() |
592 | 597 |
593 playback = SkPicturePlayback(options) | 598 playback = SkPicturePlayback(options) |
594 sys.exit(playback.Run()) | 599 sys.exit(playback.Run()) |
OLD | NEW |