示例#1
0
    def list_containers_iter(self, limit, marker, end_marker,
                             prefix, delimiter):
        """
        Return tuple of name, object_count, bytes_used, 0(is_subdir).
        Used by account server.
        """
        if delimiter and not prefix:
            prefix = ''

        self.update_container_count()

        containers, container_count = self.container_info

        if containers:
            containers.sort()

        if containers and prefix:
            containers = self.filter_prefix(containers, prefix)

        if containers and delimiter:
            containers = self.filter_delimiter(containers, delimiter, prefix)

        if containers and marker:
            containers = self.filter_marker(containers, marker)

        if containers and end_marker:
            containers = self.filter_end_marker(containers, end_marker)

        if containers and limit:
            if len(containers) > limit:
                containers = self.filter_limit(containers, limit)

        account_list = []
        if containers:
            for cont in containers:
                list_item = []
                metadata = None
                list_item.append(cont)
                cont_path = path_std(os.path.join(self.datadir, cont))
                cont_meta_path = '/'.join(cont_path.split('/')[:-1])+ '/' + self.metauuid+ '/' + cont_path.split('/')[-1]
                metadata = meta_read_metadata(cont_meta_path)
                if not metadata or not validate_container(metadata):
                    metadata = meta_create_container_metadata(cont_path,cont_meta_path)

                if metadata:
                    list_item.append(metadata[X_OBJECTS_COUNT])
                    list_item.append(metadata[X_BYTES_USED])
                    list_item.append(0)
                account_list.append(list_item)

        return account_list
示例#2
0
   def __init__(self, path, drive, account, container, logger,
                uid=DEFAULT_UID, gid=DEFAULT_GID):
       self.root = path
       
       
       
       self.container = container
       
       self.datadir = path_std(os.path.join(path, drive, self.container))
       
       self.account = account
       assert logger is not None
       self.logger = logger
       self.metadata = {}
       self.container_info = None
       self.object_info = None
       self.uid = int(uid)
       self.gid = int(gid)
       self.db_file = _db_file
       self.dir_exists = os.path.exists(self.datadir)
       
       self.metauuid = 'ff89f933b2ca8df40'
       self.fhr_path = parent_path(self.datadir)
       
       self.metafile = self.fhr_path+ '/' + self.metauuid+'/' + self.datadir.split('/')[-1]
       self.meta_fhr_path = parent_path(self.metafile) 
           
       if self.meta_fhr_dir_is_deleted():
           self.create_dir_object(self.meta_fhr_path)
           
       if not os.path.exists(self.datadir):
           return
 
       if self.dir_exists:
           try:
               self.metadata = meta_read_metadata(self.metafile)
           except EOFError:
               meta_create_container_metadata(self.datadir,self.metafile)
       else:
           return
       if self.container:
           if not self.metadata:
               meta_create_container_metadata(self.datadir,self.metafile)
               self.metadata = meta_read_metadata(self.metafile)
           else:
               if not validate_container(self.metadata):
                   meta_create_container_metadata(self.datadir,self.metafile)
                   self.metadata = meta_read_metadata(self.metafile)