Return files from bucket sorted by given keys.

    :param bucket: :class:`~invenio_files_rest.models.Bucket` containing the
        files.
    :param keys: Keys order to be used.
    :returns: Sorted list of bucket items.
5185
def sorted_files_from_bucket(bucket, keys=None):
    
    keys = keys or []
    total = len(keys)
    sortby = dict(zip(keys, range(total)))
    values = ObjectVersion.get_by_bucket(bucket).all()
    return sorted(values, key=lambda x: sortby.get(x.key, total))
1006312
def get(self, key):
    
    

    try:
      try:
        obj = self.bucket.get(key)
      except couchbase.exception.MemcachedError, inst: 
        if str(inst) == "Memcached error #1:  Not found":
          # for some reason the py cb client raises an error when
          # a key isnt found, instead we just want a none value.
          obj = None
        else:
          raise
      except:
        raise
      
      if obj:
        return json.loads(obj[2])
      else:
        return None

    except:
      raise
1253137
def sorted_converters_keys(self):
        
        keys = sorted(self.converters.keys(),
                      key=cmp_to_key(tuple_type_compare))
        return {k: self.converters[k] for k in keys}
666374
def _collection(self, key):
    ''''''
    collection = str(key.path)
    if not collection in self._items:
      self._items[collection] = dict()
    return self._items[collection]
733960
def keys(self, key=None, reverse=False):
        """"""
        ks = sorted(list(dict.keys(self)), key=key, reverse=reverse)
        return ks
902351
def get_preflist(self, bucket, key):
        
        if not self.preflists():
            raise NotImplementedError("fetching preflists is not supported.")
        msg_code = riak.pb.messages.MSG_CODE_GET_BUCKET_KEY_PREFLIST_REQ
        codec = self._get_codec(msg_code)
        msg = codec.encode_get_preflist(bucket, key)
        resp_code, resp = self._request(msg, codec)
        return [codec.decode_preflist(item) for item in resp.preflist]
1153524
def get_files(client, bucket, prefix=''):
    """"""
    bucket = client.get_bucket(bucket)
    files = list(bucket.list_blobs(prefix=prefix))    
    return files
730400
def delete(self, bucket: str, key: str):
        
        bucket_obj = self._ensure_bucket_loaded(bucket)
        try:
            bucket_obj.delete_blob(key)
        except NotFound:
            return False
1252563
def _gcs_get_keys(bucket, pattern):
  
  return [obj for obj in list(bucket.objects()) if fnmatch.fnmatch(obj.metadata.name, pattern)]
385205
def get_buckets(min_length, max_length, bucket_count):
    '''
    
    '''
    if bucket_count <= 0:
        return [max_length]
    unit_length = int((max_length - min_length) // (bucket_count))
    buckets = [min_length + unit_length *
               (i + 1) for i in range(0, bucket_count)]
    buckets[-1] = max_length
    return buckets
297346
def order_by(self, key):
        
        if key is None:
            raise NullArgumentError(u"No key for sorting given")
        kf = [OrderingDirection(key, reverse=False)]
        return SortedEnumerable3(kf, self._data)
188913
function (key) {
            var hash = hashFunction(key), ret = false;
            var bucket = null;
            if ((bucket = this.__map[hash]) != null) {
                ret = bucket.find(key) != null;
            }
            return ret;
        }
136149
def list_bucket(self, bucket):
    
    self.response.write('Listbucket result:\n')

    page_size = 1
    stats = gcs.listbucket(bucket + '/foo', max_keys=page_size)
    while True:
      count = 0
      for stat in stats:
        count += 1
        self.response.write(repr(stat))
        self.response.write('\n')

      if count != page_size or count == 0:
        break
      stats = gcs.listbucket(bucket + '/foo', max_keys=page_size,
                             marker=stat.filename)
786990
def _sorted_keys_items(dobj):
    """"""
    keys = sorted(dobj.keys())
    for key in keys:
        yield key, dobj[key]
739931
def sort_by(self, *ids):
        
        # Support sorting by file_ids or keys.
        files = {str(f_.file_id): f_.key for f_ in self}
        # self.record['_files'] = [{'key': files.get(id_, id_)} for id_ in ids]
        self.filesmap = OrderedDict([
            (files.get(id_, id_), self[files.get(id_, id_)].dumps())
            for id_ in ids
        ])
        self.flush()
881437
def order_by_descending(self, key):
        
        if key is None:
            raise NullArgumentError(u"No key for sorting given")
        kf = [OrderingDirection(key, reverse=True)]
        return SortedEnumerable3(kf, self._data)
66047
def list_objects(Bucket, Delimiter=None, EncodingType=None, Prefix=None,
                 FetchOwner=False, StartAfter=None, region=None, key=None,
                 keyid=None, profile=None):
    '''
    

    '''

    try:
        Contents = []
        args = {'Bucket': Bucket, 'FetchOwner': FetchOwner}
        args.update({'Delimiter': Delimiter}) if Delimiter else None
        args.update({'EncodingType': EncodingType}) if Delimiter else None
        args.update({'Prefix': Prefix}) if Prefix else None
        args.update({'StartAfter': StartAfter}) if StartAfter else None
        conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
        IsTruncated = True
        while IsTruncated:
            ret = conn.list_objects_v2(**args)
            IsTruncated = ret.get('IsTruncated', False)
            if IsTruncated in ('True', 'true', True):
                args['ContinuationToken'] = ret['NextContinuationToken']
            Contents += ret.get('Contents', [])
        return {'Contents': Contents}
    except ClientError as e:
        return {'error': __utils__['boto3.get_error'](e)}