X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Finp.py;h=6d3bd7d120ce0d15e4157dbf7a41cc42bfddc3c0;hb=HEAD;hp=d0b567af4c5f97f218b4c393e575b6d69a18ab17;hpb=1f66e2a621c7aab33b425640bd8ba76579c2fbaf;p=m_librarian.git diff --git a/m_librarian/inp.py b/m_librarian/inp.py index d0b567a..6d3bd7d 100644 --- a/m_librarian/inp.py +++ b/m_librarian/inp.py @@ -1,9 +1,10 @@ import os -import sys from zipfile import ZipFile -from sqlobject import sqlhub + +from sqlobject import dberrors, sqlhub from sqlobject.sqlbuilder import Select + from .db import Author, Book, Extension, Genre, Language, \ insert_name, insert_author @@ -70,14 +71,16 @@ def import_inp_line(archive, parts): for genre in genres.split(':'): if genre: genre_row = insert_name(Genre, genre, title=genre) - book.addGenre(genre_row) + try: + book.addGenre(genre_row) + except dberrors.DuplicateEntryError: + pass # The genre has already been added -if sys.version[0] == 2: - def tounicode(s): +def tounicode(s): + if isinstance(s, bytes): return s.decode('utf-8') -else: - def tounicode(s): + else: return s