Ejemplo n.º 1
0
    def proceed(self, product):

        # Fetch Book from database
        facade = BookFacade()
        book = facade.get(product.book.isbn13)

        if book is None:

            utils.logger.info("This book is not in database")

            if self.next:
                return self.next.proceed(product)

            product.status = Status.Done
            return product

        utils.logger.info("This book is already in databse")

        product.status = Status.Already
        return product
Ejemplo n.º 2
0
    def proceed(self, product):

        # Add book in database
        facade = BookFacade()
        book = facade.put(product.book)

        # Get path to the book
        book_path = utils.configuration.library_path + "/" + product.book.isbn13

        # Create book directory
        os.makedirs(book_path, mode=0777)

        # Copy PDF file to book directory
        shutil.copy2(product.pdf_path, book_path + "/" + product.book.isbn13  + ".pdf")
        shutil.move(product.metadata_path, book_path + "/" + product.book.isbn13  + ".json")
        shutil.move(product.thumbnail_path, book_path + "/" + product.book.isbn13  + "." + imghdr.what(product.thumbnail_path))

        utils.logger.info("Book stored")

        if self.next:
            return self.next.proceed(product)

        product.status = Status.Done
        return product