コード例 #1
0
 def list(self, cloud_path, recursive=False):
     '''
     List all objects include folders and files in a cloud path.
     
     :param cloud_path: the path on the cloud, 'test' eg, not need to start with '/'
                        list the root path if set to blank('').
     :param recursive(Optional): if set to True, will return the objects recursively.
     
     :return: it doesn't return all the objects immediately,
              it returns an object each time, and then another, and goes on.
              you shoud iterate them by for loop.
              of course, you can use list() to put them all into memory,
              however, it is not recommended.
     '''
     
     cloud_path = self._ensure_cloud_path_legal(cloud_path)
     
     dir_path = '/' + cloud_path
     dir_id = self._get_cloud_dir_id(dir_path)
     
     has_next = True
     c_page = 1
     while has_next:
         result = self.client.getlist(dir_id, page=c_page)
         if c_page >= result.pageinfo.pageTotal:
             has_next = False
         else:
             c_page += 1
             
         for itm in result.list:
             path = join_path(cloud_path, itm.name)
             if self.holder:
                 path = path.split(self.holder+'/', 1)[1]
                 
             if 'url' in itm:
                 yield CloudFile(path, itm.type, itm.md5, id=itm.id)
             else:
                 yield CloudFolder(path, id=itm.id)
                 
                 if recursive and itm.file_num + itm.dir_num > 0:
                     for obj in self.list(path, recursive):
                         yield obj
コード例 #2
0
 def _ensure_cloud_path_legal(self, cloud_path):
     path = join_path(self.holder, cloud_path)
     return super(VdiskStorage, self)._ensure_cloud_path_legal(path)