def remove_books(self, paths, booklists, end_session=True): """ Remove the books specified by paths from the device. The metadata cache on the device should also be updated. """ for path in paths: self.del_file(path, end_session=False) fix_ids(booklists[0], booklists[1]) self.sync_booklists(booklists, end_session=False)
def add_books_to_metadata(cls, locations, metadata, booklists): metadata = iter(metadata) for location in locations: info = metadata.next() path = location[0] on_card = 1 if path[1] == ":" else 0 name = path.rpartition("/")[2] name = (cls.CARD_PATH_PREFIX + "/" if on_card else "books/") + name booklists[on_card].add_book(info, name, *location[1:]) fix_ids(*booklists)
def sync_booklists(self, booklists, end_session=True): """ Upload bookslists to device. @param booklists: A tuple containing the result of calls to (L{books}(oncard=False), L{books}(oncard=True)). """ fix_ids(*booklists) self.upload_book_list(booklists[0], end_session=False) if booklists[1].root: self.upload_book_list(booklists[1], end_session=False)
def add_books_to_metadata(cls, locations, metadata, booklists): metadata = iter(metadata) for location in locations: info = metadata.next() path = location[0] on_card = 1 if path[1] == ':' else 0 name = path.rpartition('/')[2] name = (cls.CARD_PATH_PREFIX + '/' if on_card else 'books/') + name booklists[on_card].add_book(info, name, *location[1:]) fix_ids(*booklists)
def sync_booklists(self, booklists, end_session=True): ''' Upload bookslists to device. @param booklists: A tuple containing the result of calls to (L{books}(oncard=False), L{books}(oncard=True)). ''' fix_ids(*booklists) self.upload_book_list(booklists[0], end_session=False) if booklists[1].root: self.upload_book_list(booklists[1], end_session=False)
def add_book(self, infile, name, info, booklists, oncard=False, \ sync_booklists=False, end_session=True): """ Add a book to the device. If oncard is True then the book is copied to the card rather than main memory. @param infile: The source file, should be opened in "rb" mode @param name: The name of the book file when uploaded to the device. The extension of name must be one of the supported formats for this device. @param info: A dictionary that must have the keys "title", "authors", "cover". C{info["cover"]} should be a three element tuple (width, height, data) where data is the image data in JPEG format as a string @param booklists: A tuple containing the result of calls to (L{books}(oncard=False), L{books}(oncard=True)). """ infile.seek(0, 2) size = infile.tell() infile.seek(0) card = self.card(end_session=False) space = self.free_space(end_session=False) mspace = space[0] cspace = space[1] if space[1] >= space[2] else space[2] if oncard and size > cspace - 1024 * 1024: raise FreeSpaceError("There is insufficient free space "+\ "on the storage card") if not oncard and size > mspace - 1024 * 1024: raise FreeSpaceError("There is insufficient free space " +\ "in main memory") prefix = "/Data/media/" if oncard: prefix = card + "/" else: name = "books/" + name path = prefix + name self.put_file(infile, path, end_session=False) ctime = self.path_properties(path, end_session=False).ctime bkl = booklists[1] if oncard else booklists[0] bkl.add_book(info, name, size, ctime) fix_ids(booklists[0], booklists[1]) if sync_booklists: self.sync_booklists(booklists, end_session=False)
def add_book(self, infile, name, info, booklists, oncard=False, sync_booklists=False, end_session=True): """ Add a book to the device. If oncard is True then the book is copied to the card rather than main memory. @param infile: The source file, should be opened in "rb" mode @param name: The name of the book file when uploaded to the device. The extension of name must be one of the supported formats for this device. @param info: A dictionary that must have the keys "title", "authors", "cover". C{info["cover"]} should be a three element tuple (width, height, data) where data is the image data in JPEG format as a string @param booklists: A tuple containing the result of calls to (L{books}(oncard=False), L{books}(oncard=True)). """ infile.seek(0, 2) size = infile.tell() infile.seek(0) card = self.card(end_session=False) space = self.free_space(end_session=False) mspace = space[0] cspace = space[1] if space[1] >= space[2] else space[2] if oncard and size > cspace - 1024 * 1024: raise FreeSpaceError("There is insufficient free space " + "on the storage card") if not oncard and size > mspace - 1024 * 1024: raise FreeSpaceError("There is insufficient free space " + "in main memory") prefix = "/Data/media/" if oncard: prefix = card + "/" else: name = "books/" + name path = prefix + name self.put_file(infile, path, end_session=False) ctime = self.path_properties(path, end_session=False).ctime bkl = booklists[1] if oncard else booklists[0] bkl.add_book(info, name, size, ctime) fix_ids(booklists[0], booklists[1]) if sync_booklists: self.sync_booklists(booklists, end_session=False)
def remove_books_from_metadata(cls, paths, booklists): for path in paths: on_card = 1 if path[1] == ":" else 0 booklists[on_card].remove_book(path) fix_ids(*booklists)
def remove_books_from_metadata(cls, paths, booklists): for path in paths: on_card = 1 if path[1] == ':' else 0 booklists[on_card].remove_book(path) fix_ids(*booklists)