Ejemplo n.º 1
0
 def test_series_fn(self):
     """ Тестирование функций addseries, addbseries """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.series.count(), 1)
     ser = book.series.all()[0]
     self.assertEqual(ser.ser, "mywork")
     self.assertEqual(bseries.objects.get(ser=ser).ser_no, 1)
Ejemplo n.º 2
0
    def inpx_callback(self, inpx, inp, meta_data):

        name = "%s.%s" % (meta_data[inpx_parser.sFile],
                          meta_data[inpx_parser.sExt])

        lang = meta_data[inpx_parser.sLang].strip(strip_symbols)
        title = meta_data[inpx_parser.sTitle].strip(strip_symbols)
        annotation = ''
        docdate = meta_data[inpx_parser.sDate].strip(strip_symbols)

        rel_path_current = os.path.join(self.rel_path,
                                        meta_data[inpx_parser.sFolder])

        if opdsdb.findbook(name, rel_path_current, 1) == None:
            cat = opdsdb.addcattree(rel_path_current, opdsdb.CAT_INP)
            book = opdsdb.addbook(name, rel_path_current, cat,
                                  meta_data[inpx_parser.sExt], title,
                                  annotation, docdate, lang,
                                  meta_data[inpx_parser.sSize], opdsdb.CAT_INP)
            self.books_added += 1
            self.books_in_archives += 1
            self.logger.debug("Book " + rel_path_current + "/" + name +
                              " Added ok.")

            for a in meta_data[inpx_parser.sAuthor]:
                author = opdsdb.addauthor(a.replace(',', ' '))
                opdsdb.addbauthor(book, author)

            for g in meta_data[inpx_parser.sGenre]:
                opdsdb.addbgenre(
                    book, opdsdb.addgenre(g.lower().strip(strip_symbols)))

            for s in meta_data[inpx_parser.sSeries]:
                ser = opdsdb.addseries(s.strip())
                opdsdb.addbseries(book, ser, 0)
Ejemplo n.º 3
0
 def test_author_fn(self):
     """ Тестирование функций addauthor, addbauthor """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.authors.count(), 1)
     self.assertEqual(
         book.authors.get(full_name="Test Author").search_full_name,
         "TEST AUTHOR")
Ejemplo n.º 4
0
    def inpx_callback(self, inpx, inp, meta_data):          
                 
        name = "%s.%s"%(meta_data[inpx_parser.sFile],meta_data[inpx_parser.sExt])
        
        lang=meta_data[inpx_parser.sLang].strip(strip_symbols)
        title=meta_data[inpx_parser.sTitle].strip(strip_symbols)
        annotation=''
        docdate=meta_data[inpx_parser.sDate].strip(strip_symbols)

        rel_path_current = os.path.join(self.rel_path,meta_data[inpx_parser.sFolder])

        if opdsdb.findbook(name, rel_path_current, 1) == None:
            cat = opdsdb.addcattree(rel_path_current, opdsdb.CAT_INP)
            book=opdsdb.addbook(name,rel_path_current,cat,meta_data[inpx_parser.sExt],title,annotation,docdate,lang,meta_data[inpx_parser.sSize],opdsdb.CAT_INP)
            self.books_added+=1
            self.books_in_archives+=1
            self.logger.debug("Book "+rel_path_current+"/"+name+" Added ok.")

            for a in meta_data[inpx_parser.sAuthor]:
                author=opdsdb.addauthor(a.replace(',',' '))
                opdsdb.addbauthor(book,author)

            for g in meta_data[inpx_parser.sGenre]:
                opdsdb.addbgenre(book,opdsdb.addgenre(g.lower().strip(strip_symbols)))

            for s in meta_data[inpx_parser.sSeries]:
                ser=opdsdb.addseries(s.strip())
                opdsdb.addbseries(book,ser,0)
Ejemplo n.º 5
0
 def test_series_fn(self):
     """ Тестирование функций addseries, addbseries """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.series.count(), 1)
     ser = book.series.all()[0]
     self.assertEqual(ser.ser, "mywork")
     self.assertEqual(bseries.objects.get(ser=ser).ser_no, 1)
Ejemplo n.º 6
0
 def test_genre_fn(self):
     """ Тестирование функций addgenre, addbgenre """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.genres.count(), 1)
     self.assertEqual(
         book.genres.get(genre="fantastic").section, opdsdb.unknown_genre)
     self.assertEqual(
         book.genres.get(genre="fantastic").subsection, "fantastic")
Ejemplo n.º 7
0
    def processfile(self,name,full_path,file,cat,archive=0,file_size=0):
        (n, e) = os.path.splitext(name)
        if e.lower() in config.SOPDS_BOOK_EXTENSIONS.split():
            rel_path=os.path.relpath(full_path,config.SOPDS_ROOT_LIB)
            self.logger.debug("Attempt to add book "+rel_path+"/"+name)
            try:
                if opdsdb.findbook(name, rel_path, 1) == None:
                    if archive==0:
                        cat=opdsdb.addcattree(rel_path,archive)

                    try:
                        book_data = create_bookfile(file, name)
                    except Exception as err:
                        book_data = None
                        self.logger.warning(rel_path + ' - ' + name + ' Book parse error, skipping... (Error: %s)'%err)
                        self.bad_books += 1

                    if book_data:
                        lang = book_data.language_code.strip(strip_symbols) if book_data.language_code else ''
                        title = book_data.title.strip(strip_symbols) if book_data.title else n
                        annotation = book_data.description if book_data.description else ''
                        annotation = annotation.strip(strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(strip_symbols)
                        docdate = book_data.docdate if book_data.docdate else ''

                        book=opdsdb.addbook(name,rel_path,cat,e[1:],title,annotation,docdate,lang,file_size,archive)
                        self.books_added+=1

                        if archive!=0:
                            self.books_in_archives+=1
                        self.logger.debug("Book "+rel_path+"/"+name+" Added ok.")

                        for a in book_data.authors:
                            author_name = a.get('name',_('Unknown author')).strip(strip_symbols)
                            # Если в имени автора нет запятой, то фамилию переносим из конца в начало
                            if author_name and author_name.find(',')<0:
                                author_names = author_name.split()
                                author_name = ' '.join([author_names[-1],' '.join(author_names[:-1])])
                            author=opdsdb.addauthor(author_name)
                            opdsdb.addbauthor(book,author)

                        for genre in book_data.tags:
                            opdsdb.addbgenre(book,opdsdb.addgenre(genre.lower().strip(strip_symbols)))


                        if book_data.series_info:
                            ser = opdsdb.addseries(book_data.series_info['title'])
                            ser_no = book_data.series_info['index']  or '0'
                            ser_no = int(ser_no) if ser_no.isdigit() else 0
                            opdsdb.addbseries(book,ser,ser_no)
                else:
                    self.books_skipped+=1
                    self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.")
            except UnicodeEncodeError as err:
                self.logger.warning(rel_path + ' - ' + name + ' Book UnicodeEncodeError error, skipping... (Error: %s)' % err)
                self.bad_books += 1
Ejemplo n.º 8
0
    def processfile(self,name,full_path,file,cat,archive=0,file_size=0):
        (n, e) = os.path.splitext(name)
        if e.lower() in config.SOPDS_BOOK_EXTENSIONS.split():
            rel_path=os.path.relpath(full_path,config.SOPDS_ROOT_LIB)
            self.logger.debug("Attempt to add book "+rel_path+"/"+name)
            try:
                if opdsdb.findbook(name, rel_path, 1) == None:
                    if archive==0:
                        cat=opdsdb.addcattree(rel_path,archive)

                    try:
                        book_data = create_bookfile(file, name)
                    except Exception as err:
                        book_data = None
                        self.logger.warning(rel_path + ' - ' + name + ' Book parse error, skipping... (Error: %s)'%err)
                        self.bad_books += 1

                    if book_data:
                        lang = book_data.language_code.strip(strip_symbols) if book_data.language_code else ''
                        title = book_data.title.strip(strip_symbols) if book_data.title else n
                        annotation = book_data.description if book_data.description else ''
                        annotation = annotation.strip(strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(strip_symbols)
                        docdate = book_data.docdate if book_data.docdate else ''

                        book=opdsdb.addbook(name,rel_path,cat,e[1:],title,annotation,docdate,lang,file_size,archive)
                        self.books_added+=1

                        if archive!=0:
                            self.books_in_archives+=1
                        self.logger.debug("Book "+rel_path+"/"+name+" Added ok.")

                        for a in book_data.authors:
                            author_name = a.get('name',_('Unknown author')).strip(strip_symbols)
                            # Если в имени автора нет запятой, то фамилию переносим из конца в начало
                            if author_name and author_name.find(',')<0:
                                author_names = author_name.split()
                                author_name = ' '.join([author_names[-1],' '.join(author_names[:-1])])
                            author=opdsdb.addauthor(author_name)
                            opdsdb.addbauthor(book,author)

                        for genre in book_data.tags:
                            opdsdb.addbgenre(book,opdsdb.addgenre(genre.lower().strip(strip_symbols)))


                        if book_data.series_info:
                            ser = opdsdb.addseries(book_data.series_info['title'])
                            ser_no = book_data.series_info['index']  or '0'
                            ser_no = int(ser_no) if ser_no.isdigit() else 0
                            opdsdb.addbseries(book,ser,ser_no)
                else:
                    self.books_skipped+=1
                    self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.")
            except UnicodeEncodeError as err:
                self.logger.warning(rel_path + ' - ' + name + ' Book UnicodeEncodeError error, skipping... (Error: %s)' % err)
                self.bad_books += 1
Ejemplo n.º 9
0
 def test_book_fn(self):
     """ Тестирование функций addbook, findbook """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertIsNotNone(book)
     self.assertEqual(book.filename, "testbook.fb2")
     self.assertEqual(book.path, "root/child")
     self.assertEqual(book.catalog.cat_name, "child")
     self.assertEqual(book.catalog.cat_type, 0)
     self.assertEqual(book.format, ".fb2")
     self.assertEqual(book.title, "Test Book")
     self.assertEqual(book.annotation, "Annotation")
     self.assertEqual(book.docdate, "01.01.2016")
     self.assertEqual(book.lang, "ru")
     self.assertEqual(book.filesize, 500)
     self.assertEqual(book.cat_type, 0)
Ejemplo n.º 10
0
 def test_book_fn(self):
     """ Тестирование функций addbook, findbook """
     book = opdsdb.findbook("testbook.fb2","root/child")
     self.assertIsNotNone(book)
     self.assertEqual(book.filename,"testbook.fb2")
     self.assertEqual(book.path, "root/child")
     self.assertEqual(book.catalog.cat_name, "child")
     self.assertEqual(book.catalog.cat_type, 0)
     self.assertEqual(book.format, ".fb2")
     self.assertEqual(book.title, "Test Book")
     self.assertEqual(book.annotation, "Annotation")
     self.assertEqual(book.docdate, "01.01.2016")
     self.assertEqual(book.lang, "ru")
     self.assertEqual(book.filesize, 500)
     self.assertEqual(book.cat_type, 0)
Ejemplo n.º 11
0
 def test_genre_fn(self):
     """ Тестирование функций addgenre, addbgenre """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.genres.count(), 1)
     self.assertEqual(book.genres.get(genre="fantastic").section, opdsdb.unknown_genre)
     self.assertEqual(book.genres.get(genre="fantastic").subsection, "fantastic")
Ejemplo n.º 12
0
 def test_author_fn(self):
     """ Тестирование функций addauthor, addbauthor """
     book = opdsdb.findbook("testbook.fb2", "root/child")
     self.assertEqual(book.authors.count(), 1)
     self.assertEqual(book.authors.get(full_name="Test Author").search_full_name, "TEST AUTHOR")