예제 #1
0
  def _rewrite_tmpfile(self, mainfile, tmpfile, writer_spec):
    """Copies contents of tmpfile (name) to mainfile (buffer)."""

    tmp_account_id = self._get_tmp_account_id(writer_spec)
    try:

      f = cloudstorage_api.open(tmpfile, _account_id=tmp_account_id)
    except cloud_errors.NotFoundError:











      account_id = self._get_account_id(writer_spec)
      if self._exists_in_gcs(mainfile.name, _account_id=account_id):
        return
      raise


    data = f.read(self._REWRITE_BLOCK_SIZE)
    while data:

      if not self.verify(data):
        raise errors.WriterValidationError("Unable to validate output data.")
      mainfile.write(data)
      data = f.read(self._REWRITE_BLOCK_SIZE)
    f.close()
    mainfile.flush()
예제 #2
0
 def _exists_in_gcs(self, filename, _account_id=None):
   """Checks if file exists in GCS already."""
   try:
     with cloudstorage_api.open(filename, _account_id=_account_id):
       return True
   except cloud_errors.NotFoundError:
     return False
  def _rewrite_tmpfile(self, mainfile, tmpfile, writer_spec):
    """Copies contents of tmpfile (name) to mainfile (buffer)."""

    account_id = self._get_tmp_account_id(writer_spec)
    try:

      f = cloudstorage_api.open(tmpfile, _account_id=account_id)
    except cloud_errors.NotFoundError:











      if self._exists_in_gcs(mainfile.name, _account_id=account_id):
        return
      raise


    data = f.read(self._REWRITE_BLOCK_SIZE)
    while data:

      mainfile.write(data)
      data = f.read(self._REWRITE_BLOCK_SIZE)
    f.close()
    mainfile.flush()
예제 #4
0
 def _exists_in_gcs(self, filename, _account_id=None):
     """Checks if file exists in GCS already."""
     try:
         with cloudstorage_api.open(filename, _account_id=_account_id):
             return True
     except cloud_errors.NotFoundError:
         return False
예제 #5
0
    def _rewrite_tmpfile(self, mainfile, tmpfile, writer_spec):
        """Copies contents of tmpfile (name) to mainfile (buffer)."""

        account_id = self._get_tmp_account_id(writer_spec)
        try:

            f = cloudstorage_api.open(tmpfile, _account_id=account_id)
        except cloud_errors.NotFoundError:

            if self._exists_in_gcs(mainfile.name, _account_id=account_id):
                return
            raise

        data = f.read(self._REWRITE_BLOCK_SIZE)
        while data:

            mainfile.write(data)
            data = f.read(self._REWRITE_BLOCK_SIZE)
        f.close()
        mainfile.flush()