Logo Search packages:      
Sourcecode: calibre version File versions

def calibre::devices::prs500::driver::PRS500::list (   self,
  path,
  recurse = False,
  end_session = True 
)

Return a listing of path. See the code for details. See L{DirOpen},
L{DirRead} and L{DirClose} for details on the command packets used.

@type path: string
@param path: The path to list
@type recurse: boolean
@param recurse: If true do a recursive listing
@return: A list of tuples. The first element of each tuple is a path.
The second element is a list of L{Files<File>}.
The path is the path we are listing, the C{Files} are the
files/directories in that path. If it is a recursive list, then the first
element will be (C{path}, children), the next will be
(child, its children) and so on. If it is not recursive the length of the
outermost list will be 1.

Definition at line 516 of file driver.py.

00516                                                          :
        """
        Return a listing of path. See the code for details. See L{DirOpen},
        L{DirRead} and L{DirClose} for details on the command packets used.

        @type path: string
        @param path: The path to list
        @type recurse: boolean
        @param recurse: If true do a recursive listing
        @return: A list of tuples. The first element of each tuple is a path.
        The second element is a list of L{Files<File>}.
        The path is the path we are listing, the C{Files} are the
        files/directories in that path. If it is a recursive list, then the first
        element will be (C{path}, children), the next will be
        (child, its children) and so on. If it is not recursive the length of the
        outermost list will be 1.
        """
        def _list(path):
            """ Do a non recursive listsing of path """
            if not path.endswith("/"):
                path += "/" # Initially assume path is a directory
            cp = self.card_prefix(False)
            path = path.replace('card:/', cp if cp else '')
            files = []
            candidate = self.path_properties(path, end_session=False)
            if not candidate.is_dir:
                path = path[:-1]
                data = self.path_properties(path, end_session=False)
                files = [ File((path, data)) ]
            else:
                # Get query ID used to ask for next element in list
                res = self.send_validated_command(DirOpen(path))
                if res.code != 0:
                    raise PathError("Unable to open directory " + path + \
                                " for reading. Response code: " + hex(res.code))
                _id = self._bulk_read(0x14, data_type=IdAnswer, \
                                            command_number=DirOpen.NUMBER)[0].id
                # Create command asking for next element in list
                next = DirRead(_id)
                items = []
                while True:
                    res = self.send_validated_command(next, response_type=ListResponse)
                    size = res.data_size + 16
                    data = self._bulk_read(size, data_type=ListAnswer, \
                                              command_number=DirRead.NUMBER)[0]
                    # path_not_found seems to happen if the usb server
                    # doesn't have the permissions to access the directory
                    if res.is_eol or res.path_not_found:
                        break
                    elif res.code != 0:
                        raise ProtocolError("Unknown error occured while "+\
                            "reading contents of directory " + path + \
                            ". Response code: " + hex(res.code))
                    items.append(data.name)
                self.send_validated_command(DirClose(_id))
                # Ignore res.code as we cant do anything if close fails
                for item in items:
                    ipath = path + item
                    data = self.path_properties(ipath, end_session=False)
                    files.append( File( (ipath, data) ) )
            files.sort()
            return files

        files = _list(path)
        dirs = [(path, files)]

        for _file in files:
            if recurse and _file.is_dir and not _file.path.startswith(("/dev","/proc")):
                dirs[len(dirs):] = self.list(_file.path, recurse=True, end_session=False)
        return dirs

    @safe
    def total_space(self, end_session=True):


Generated by  Doxygen 1.6.0   Back to index