def list(self, prefix='', delimiter='', marker=NOT_IMPL,
          headers=NOT_IMPL):
     prefix = prefix or '' # Turn None into '' for prefix match.
     # Return list instead of using a generator so we don't get
     # 'dictionary changed size during iteration' error when performing
     # deletions while iterating (e.g., during test cleanup).
     result = []
     key_name_set = set()
     for k in self.keys.itervalues():
         if k.name.startswith(prefix):
             k_name_past_prefix = k.name[len(prefix):]
             if delimiter:
               pos = k_name_past_prefix.find(delimiter)
             else:
               pos = -1
             if (pos != -1):
                 key_or_prefix = Prefix(
                     bucket=self, name=k.name[:len(prefix)+pos+1])
             else:
                 key_or_prefix = MockKey(bucket=self, name=k.name)
                 key_or_prefix.data = k.data
             if key_or_prefix.name not in key_name_set:
                 key_name_set.add(key_or_prefix.name)
                 result.append(key_or_prefix)
     return result
 def test_delete_mix(self):
     result = self.bucket.delete_keys([
         "king", ("mice", None),
         Key(name="regular"),
         Key(),
         Prefix(name="folder/"),
         DeleteMarker(name="deleted"), {
             "bad": "type"
         }
     ])
     self.assertEqual(len(result.deleted), 4)
     self.assertEqual(len(result.errors), 3)
Beispiel #3
0
 def getinfo(self,path):
     s3path = self._s3path(path)
     if path in ("","/"):
         k = Prefix(bucket=self._s3bukt,name="/")
     else:
         k = self._s3bukt.get_key(s3path)
         if k is None:
             ks = self._s3bukt.list(prefix=s3path,delimiter=self._separator)
             for k in ks:
                 if isinstance(k,Prefix):
                     break
             else:
                 raise ResourceNotFoundError(path)
     return self._get_key_info(k,path)
Beispiel #4
0
 def list(self, prefix='', delimiter='', marker=NOT_IMPL, headers=NOT_IMPL):
     prefix = prefix or ''  # Turn None into '' for prefix match.
     # Return list instead of using a generator so we don't get
     # 'dictionary changed size during iteration' error when performing
     # deletions while iterating (e.g., during test cleanup).
     result = []
     key_name_set = set()
     for k in six.itervalues(self.keys):
         if k.name.startswith(prefix):
             k_name_past_prefix = k.name[len(prefix):]
             if delimiter:
                 pos = k_name_past_prefix.find(delimiter)
             else:
                 pos = -1
             if (pos != -1):
                 key_or_prefix = Prefix(bucket=self,
                                        name=k.name[:len(prefix) + pos + 1])
             else:
                 key_or_prefix = MockKey(bucket=self, name=k.name)
             if key_or_prefix.name not in key_name_set:
                 key_name_set.add(key_or_prefix.name)
                 result.append(key_or_prefix)
     return result
Beispiel #5
0
                    regions_allowed = ['us-east-1']
                else:
                    regions_allowed = [location]

                if ec2_conn.region.name not in regions_allowed:
                    raise Exception(
                        "EC2 Region {} not in S3 region(s) {}. Excess charges will occur"
                        .format(ec2_conn.region.name, regions_allowed))

            # Try to download the latest file in bucket, sometimes some files are in glacier
            print "Checking Bucket for {} only access at prefix {}.  " \
                  "This may take a while for large buckets".format(access, "'{}'".format(bucket_prefix))

            result_iter = []
            max_files = 100
            next_prefixes = [Prefix(bucket, bucket_prefix)]
            while len(result_iter) == 0 and len(next_prefixes) > 0:
                prefixes = next_prefixes
                next_prefixes = []
                for prefix in sorted(prefixes, reverse=True):
                    print "Viewing folder {}".format(prefix.name)
                    for num, item in enumerate(
                            sorted(bucket.list(prefix.name, delim),
                                   reverse=True)):
                        if isinstance(item, Prefix) or item.name[-1] == '/':
                            print 'Folder={}'.format(item.name)
                            next_prefixes.append(item)
                            continue
                        if num >= max_files:
                            index = num % max_files
                            result_iter[index] = item