Пример #1
0
def _UploadGsutil(files, destination):
    """Upload a list of local files to GCS.

  Args:
    files: The list of local files to upload.
    destination: A GCS "directory" to copy the files into.
  """
    args = files
    args += [destination]
    exit_code = storage_util.RunGsutilCommand('cp', args)
    if exit_code != 0:
        raise dp_exceptions.FileUploadError(
            "Failed to upload files ['{0}'] to '{1}' using gsutil.".format(
                "', '".join(files), destination))
def _UploadStorageClient(files, destination, storage_client=None):
  """Upload a list of local files to GCS.

  Args:
    files: The list of local files to upload.
    destination: A GCS "directory" to copy the files into.
    storage_client: Storage api client used to copy files to gcs.
  """
  client = storage_client or storage_api.StorageClient()
  for file_to_upload in files:
    file_name = os.path.basename(file_to_upload)
    dest_url = os.path.join(destination, file_name)
    dest_object = storage_util.ObjectReference.FromUrl(dest_url)
    try:
      client.CopyFileToGCS(file_to_upload, dest_object)
    except exceptions.BadFileException:
      raise dp_exceptions.FileUploadError(
          "Failed to upload files ['{0}'] to '{1}'.".format(
              "', '".join(files), destination))