From e75d2d2d995dad4eeed1bd306ef987adabac2bfc Mon Sep 17 00:00:00 2001 From: kkinnunen Date: Wed, 3 Dec 2014 04:38:46 -0800 Subject: Remove Google Storage scheme prefix correctly from gs base name in webpages_playback In python, str.lstrip([chars]) means "lstrip any of the chars from str", not "remove prefix". Thus "gs://skia".lstrip("gs://") yields "kia". Replace with custom function stripping the prefix from lstrip()ed gs base name. Review URL: https://codereview.chromium.org/780493002 --- tools/skp/webpages_playback.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tools/skp') diff --git a/tools/skp/webpages_playback.py b/tools/skp/webpages_playback.py index 99808eda32..d2df01f32d 100644 --- a/tools/skp/webpages_playback.py +++ b/tools/skp/webpages_playback.py @@ -109,6 +109,10 @@ GS_FINE_GRAINED_ACL_LIST = [ gs_utils.GSUtils.Permission.READ), ] +def remove_prefix(s, prefix): + if s.startswith(prefix): + return s[len(prefix):] + return s class SkPicturePlayback(object): """Class that archives or replays webpages and creates SKPs.""" @@ -177,7 +181,7 @@ class SkPicturePlayback(object): raw_input("Please press a key when you are ready to proceed...") elif not os.path.isfile(CREDENTIALS_FILE_PATH): # Download the credentials.json file from Google Storage. - gs_bucket = self._dest_gsbase.lstrip(gs_utils.GS_PREFIX) + gs_bucket = remove_prefix(self._dest_gsbase.lstrip(), gs_utils.GS_PREFIX) gs_utils.GSUtils().download_file(gs_bucket, CREDENTIALS_GS_PATH, CREDENTIALS_FILE_PATH) @@ -319,7 +323,7 @@ class SkPicturePlayback(object): if self._alternate_upload_dir: dest_dir_name = self._alternate_upload_dir - gs_bucket = self._dest_gsbase.lstrip(gs_utils.GS_PREFIX) + gs_bucket = remove_prefix(self._dest_gsbase.lstrip(), gs_utils.GS_PREFIX) gs_utils.GSUtils().upload_dir_contents( LOCAL_PLAYBACK_ROOT_DIR, gs_bucket, dest_dir_name, upload_if=gs_utils.GSUtils.UploadIf.IF_MODIFIED, @@ -382,7 +386,7 @@ class SkPicturePlayback(object): 'webpages_archive', page_set_json_name) gs = gs_utils.GSUtils() - gs_bucket = self._dest_gsbase.lstrip(gs_utils.GS_PREFIX) + gs_bucket = remove_prefix(self._dest_gsbase.lstrip(), gs_utils.GS_PREFIX) if (gs.does_storage_object_exist(gs_bucket, wpr_source) and gs.does_storage_object_exist(gs_bucket, page_set_source)): gs.download_file(gs_bucket, wpr_source, -- cgit v1.2.3