]> git.phdru.name Git - m_librarian.git/blobdiff - m_librarian/inp.py
Process author names
[m_librarian.git] / m_librarian / inp.py
index db0a3d834baf41c5bb7a195a12047d2ceb07c3df..56f85e4d1dcdfb4561fe0ac08cc4d364c291f25a 100644 (file)
@@ -4,7 +4,8 @@ __all__ = ['import_inpx']
 import os
 from zipfile import ZipFile
 from sqlobject import sqlhub, SQLObjectNotFound
-from .db import Author, Book, Extension, Genre, Language, insert_name
+from .db import Author, Book, Extension, Genre, Language, \
+    insert_name, insert_author
 
 
 EOT = chr(4)  # INP field separator
@@ -46,7 +47,17 @@ def import_inp_line(archive, parts):
                 language=language_row)
     for author in authors.split(':'):
         if author:
-            author_row = insert_name(Author, author)
+            alist = author.split(',', 2)
+            surname = alist[0]
+            if len(alist) > 1:
+                name = alist[1]
+                if len(alist) == 3:
+                    misc_name = alist[2]
+                else:
+                    misc_name = ''
+            else:
+                name = misc_name = ''
+            author_row = insert_author(surname, name, misc_name)
             book.addAuthor(author_row)
     for genre in genres.split(':'):
         if genre:
@@ -63,8 +74,12 @@ def import_inpx(path):
     inpx = ZipFile(path)
     for name in inpx.namelist():
         archive, ext = os.path.splitext(name)
-        if ext != 'inp':
+        if ext != '.inp':
             continue
         inp = inpx.open(name)
         sqlhub.doInTransaction(import_inp, archive + '.zip', inp)
         inp.close()
+    connection = sqlhub.processConnection
+    if connection.dbName in ('postgres', 'sqlite'):
+        for table in Author, Book, Extension, Genre, Language:
+            connection.query("VACUUM %s" % table.sqlmeta.table)