def verify_bucket_writable(bucket_name):
  path = '/gs/%s' % bucket_name
  try:
    file_names = files.gs.listdir(path,
                                  {'prefix': TEST_WRITE_FILENAME_PREFIX,
                                   'max_keys': MAX_KEYS_LIST_SIZE})
  except (files.InvalidParameterError, files.PermissionDeniedError):
    raise BackupValidationException('Bucket "%s" not accessible' % bucket_name)
  except files.InvalidFileNameError:
    raise BackupValidationException('Bucket "%s" does not exist' % bucket_name)
  file_name = '%s/%s.tmp' % (path, TEST_WRITE_FILENAME_PREFIX)
  file_name_try = 0
  while True:
    if file_name_try >= MAX_TEST_FILENAME_TRIES:


      return
    if file_name not in file_names:
      break
    gen = random.randint(0, 9999)
    file_name = '%s/%s_%s.tmp' % (path, TEST_WRITE_FILENAME_PREFIX, gen)
    file_name_try += 1
  try:
    test_file = files.open(files.gs.create(file_name), 'a', exclusive_lock=True)
    try:
      test_file.write('test')
    finally:
      test_file.close(finalize=True)
  except files.PermissionDeniedError:
    raise BackupValidationException('Bucket "%s" is not writable' % bucket_name)
  try:
    files.delete(file_name)
  except (files.InvalidArgumentError, files.InvalidFileNameError, IOError):
    logging.warn('Failed to delete test file %s', file_name)
Verify the application can write to the specified bucket.
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/ext/datastore_admin/backup_handler.py/verify_bucket_writable