Exemplo n.º 1
0
 def _bucketExists(self, bucketName):
     resp = self._client.headBucket(bucketName)
     if resp is None:
         noRespError = 'Head bucket [%s] failed. error message [response is None].' % bucketName
         self._logClient.log(logging.ERROR, noRespError)
         self._ar.update({'obs_ret_detail': str(resp)})
         raise Exception(noRespError)
     if resp.status < 300:
         self._logClient.log(logging.INFO, 'Head bucket [%s] successfully. %s.', bucketName,
                             ObsSftpUtil.makeResponseMessage(resp))
         return True
     if resp.status == 404:
         self._logClient.log(logging.DEBUG, 'Head bucket [%s] failed. error message [bucket is not exists] - %s.',
                             bucketName, ObsSftpUtil.makeResponseMessage(resp))
         return False
     self._ar.update({'obs_ret_detail': str(resp)})
     respError = 'Head bucket [%s] failed. %s.' % (bucketName, ObsSftpUtil.makeErrorMessage(resp))
     self._logClient.log(logging.ERROR, respError)
     raise Exception(respError)
Exemplo n.º 2
0
 def _listUserBuckets(self):
     resp = self._client.listBuckets()
     if resp is None:
         self._logClient.log(logging.ERROR, 'List buckets failed. error message [response is None].')
         self._ar.update({'obs_ret_detail': str(resp)})
         return SFTP_FAILURE
     if resp.status < 300:
         self._logClient.log(logging.INFO, 'List buckets successfully. %s.', ObsSftpUtil.makeResponseMessage(resp))
         buckets = []
         for bucket in resp.body.buckets:
             attr = SFTPAttributes()
             attr.st_mode = S_IFDIR
             createTime = bucket.create_date
             attr.st_mtime = ObsSftpUtil.strToTimestamp(createTime)
             attr.filename = bucket.name
             buckets.append(attr)
         self._ar.update({'obs_ret_detail': str(resp)})
         return buckets
     self._ar.update({'obs_ret_detail': str(resp)})
     self._logClient.log(logging.ERROR,
                         'List buckets failed. %s.', ObsSftpUtil.makeErrorMessage(resp))
     return SFTP_FAILURE