Example #1
0
 def parent_path(path):
   parent_dir = S3FileSystem._append_separator(path)
   if not s3.is_root(parent_dir):
     bucket_name, key_name, basename = s3.parse_uri(path)
     if not basename:  # bucket is top-level so return root
       parent_dir = S3_ROOT
     else:
       bucket_path = '%s%s' % (S3_ROOT, bucket_name)
       key_path = '/'.join(key_name.split('/')[:-1])
       parent_dir = s3.abspath(bucket_path, key_path)
   return parent_dir
Example #2
0
  def _stats(self, path):
    if s3.is_root(path):
      return S3Stat.for_s3_root()

    try:
      key = self._get_key(path, validate=True)
    except S3ResponseError as e:
      if e.status == 404:
        return None
      else:
        exc_class, exc, tb = sys.exc_info()
        raise exc_class, exc, tb

    if key is None:
      key = self._get_key(path, validate=False)
    return self._stats_key(key)
Example #3
0
  def _stats(self, path):
    if s3.is_root(path):
      return S3Stat.for_s3_root()

    try:
      key = self._get_key(path, validate=True)
    except S3ResponseError as e:
      if e.status == 404:
        return None
      elif e.status == 403:
        raise S3FileSystemException(_('User is not authorized to access path: "%s"') % path)
      else:
        raise S3FileSystemException(_('Failed to access path "%s": %s') % (path, e.reason))

    if key is None:
      key = self._get_key(path, validate=False)
    return self._stats_key(key)
Example #4
0
  def listdir_stats(self, path, glob=None):
    if glob is not None:
      raise NotImplementedError(_("Option `glob` is not implemented"))

    if s3.is_root(path):
      self._init_bucket_cache()
      return [S3Stat.from_bucket(b) for b in self._bucket_cache.values()]

    bucket_name, prefix = s3.parse_uri(path)[:2]
    bucket = self._get_bucket(bucket_name)
    prefix = self._append_separator(prefix)
    res = []
    for item in bucket.list(prefix=prefix, delimiter='/'):
      if isinstance(item, Prefix):
        res.append(S3Stat.from_key(Key(item.bucket, item.name), is_dir=True))
      else:
        if item.name == prefix:
          continue
        res.append(self._stats_key(item))
    return res
Example #5
0
    def _stats(self, path):
        if s3.is_root(path):
            return S3Stat.for_s3_root()

        try:
            key = self._get_key(path, validate=True)
        except BotoClientError as e:
            raise S3FileSystemException(
                _('Failed to access path "%s": %s') % (path, e.reason))
        except S3ResponseError as e:
            if e.status == 404:
                return None
            elif e.status == 403:
                raise S3FileSystemException(
                    _('User is not authorized to access path: "%s"') % path)
            else:
                raise S3FileSystemException(
                    _('Failed to access path "%s": %s') % (path, e.reason))
        except Exception as e:  # SSL errors show up here, because they've been remapped in boto
            raise S3FileSystemException(
                _('Failed to access path "%s": %s') % (path, e.message))
        if key is None:
            key = self._get_key(path, validate=False)
        return self._stats_key(key, self.fs)
Example #6
0
 def isroot(path):
     return s3.is_root(path)
Example #7
0
 def isroot(path):
   return s3.is_root(path)