def _PromoteDartArchiveBuild(channel, source_channel, revision): # These namer objects will be used to create GCS object URIs. For the # structure we use, please see tools/bots/bot_utils.py:GCSNamer raw_namer = bot_utils.GCSNamer(source_channel, bot_utils.ReleaseType.RAW) signed_namer = bot_utils.GCSNamer(source_channel, bot_utils.ReleaseType.SIGNED) release_namer = bot_utils.GCSNamer(channel, bot_utils.ReleaseType.RELEASE) def promote(to_revision): def safety_check_on_gs_path(gs_path, revision, channel): if not (revision != None and len(channel) > 0 and ('%s' % revision) in gs_path and channel in gs_path): raise Exception( 'InternalError: Sanity check failed on GS URI: %s' % gs_path) def exists(gs_path): (_, _, exit_code) = Gsutil(['ls', gs_path], throw_on_error=False) # gsutil will exit 0 if the "directory" exists return exit_code == 0 # Google cloud storage has read-after-write, read-after-update, # and read-after-delete consistency, but not list after delete consistency. # Because gsutil uses list to figure out if it should do the unix styly # copy to or copy into, this means that if the directory is reported as # still being there (after it has been deleted) gsutil will copy # into the directory instead of to the directory. def wait_for_delete_to_be_consistent_with_list(gs_path): if DRY_RUN: return while exists(gs_path): time.sleep(1) def remove_gs_directory(gs_path): safety_check_on_gs_path(gs_path, to_revision, channel) # Only delete existing directories if exists(gs_path): Gsutil(['-m', 'rm', '-R', '-f', gs_path]) wait_for_delete_to_be_consistent_with_list(gs_path) # Copy the signed sdk directory. from_loc = signed_namer.sdk_directory(revision) to_loc = release_namer.sdk_directory(to_revision) remove_gs_directory(to_loc) has_signed = exists(from_loc) if has_signed: Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Because gsutil copies differently to existing directories, we need # to use the base directory for the next recursive copy. to_loc = release_namer.base_directory(to_revision) # Copy the unsigned sdk directory without clobbering signed files. from_loc = raw_namer.sdk_directory(revision) Gsutil(['-m', 'cp', '-n', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy api-docs zipfile. from_loc = raw_namer.apidocs_zipfilepath(revision) to_loc = release_namer.apidocs_zipfilepath(to_revision) Gsutil(['-m', 'cp', '-a', 'public-read', from_loc, to_loc]) # Copy wheezy linux deb and src packages. from_loc = raw_namer.linux_packages_directory(revision) to_loc = release_namer.linux_packages_directory(to_revision) remove_gs_directory(to_loc) Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy VERSION file. from_loc = raw_namer.version_filepath(revision) to_loc = release_namer.version_filepath(to_revision) Gsutil(['cp', '-a', 'public-read', from_loc, to_loc]) promote(revision) promote('latest')
def _PromoteDartArchiveBuild(channel, revision): # These namer objects will be used to create GCS object URIs. For the # structure we use, please see tools/bots/bot_utils.py:GCSNamer raw_namer = bot_utils.GCSNamer(channel, bot_utils.ReleaseType.RAW) signed_namer = bot_utils.GCSNamer(channel, bot_utils.ReleaseType.SIGNED) release_namer = bot_utils.GCSNamer(channel, bot_utils.ReleaseType.RELEASE) def promote(to_revision): def safety_check_on_gs_path(gs_path, revision, channel): if not ((revision == 'latest' or int(revision) > 0) and len(channel) > 0 and ('%s' % revision) in gs_path and channel in gs_path): raise Exception( "InternalError: Sanity check failed on GS URI: %s" % gs_path) # Google cloud storage has read-after-write, read-after-update, # and read-after-delete consistency, but not list after delete consistency. # Because gsutil uses list to figure out if it should do the unix styly # copy to or copy into, this means that if the directory is reported as # still being there (after it has been deleted) gsutil will copy # into the directory instead of to the directory. def wait_for_delete_to_be_consistent_with_list(gs_path): while True: if DRY_RUN: break (_, _, exit_code) = Gsutil(['ls', gs_path], throw_on_error=False) # gsutil will exit 1 if the "directory" does not exist if exit_code != 0: break time.sleep(1) def remove_gs_directory(gs_path): safety_check_on_gs_path(gs_path, to_revision, channel) Gsutil(['-m', 'rm', '-R', '-f', gs_path]) wait_for_delete_to_be_consistent_with_list(gs_path) # Copy sdk directory. from_loc = raw_namer.sdk_directory(revision) to_loc = release_namer.sdk_directory(to_revision) remove_gs_directory(to_loc) Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy eclipse update directory. from_loc = raw_namer.editor_eclipse_update_directory(revision) to_loc = release_namer.editor_eclipse_update_directory(to_revision) remove_gs_directory(to_loc) Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy api-docs zipfile. from_loc = raw_namer.apidocs_zipfilepath(revision) to_loc = release_namer.apidocs_zipfilepath(to_revision) Gsutil(['-m', 'cp', '-a', 'public-read', from_loc, to_loc]) # Copy dartium directory. from_loc = raw_namer.dartium_directory(revision) to_loc = release_namer.dartium_directory(to_revision) remove_gs_directory(to_loc) Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy wheezy linux deb and src packages. from_loc = raw_namer.linux_packages_directory(revision, 'debian_wheezy') to_loc = release_namer.linux_packages_directory( to_revision, 'debian_wheezy') remove_gs_directory(to_loc) Gsutil(['-m', 'cp', '-a', 'public-read', '-R', from_loc, to_loc]) # Copy VERSION file. from_loc = raw_namer.version_filepath(revision) to_loc = release_namer.version_filepath(to_revision) Gsutil(['cp', '-a', 'public-read', from_loc, to_loc]) promote(revision) promote('latest')