Программа является свободной, распространяется под лицензией типа BSD. Точные
условия лицензии см. в файле License.txt. Домашняя страница программы:
http://home-lib.net/
+
+Структура inp: http://forum.home-lib.net/index.php?showtopic=16
+Список колонок либо в файле structure.info, либо
+
+Стандартная структура (librusec.inpx и librusec_usr.inpx):
+
+AUTHOR;GENRE;TITLE;SERIES;SERNO;FILE;SIZE;LIBID;DEL;EXT;DATE;
+
+Структура для пользовательских коллекций:
+
+AUTHOR;GENRE;TITLE;SERIES;SERNO;FILE;SIZE;LIBID;DEL;EXT;DATE;INSNO;FOLDER;
+
+Новый librusec.inpx:
+
+AUTHOR;GENRE;TITLE;SERIES;SERNO;FILE;SIZE;LIBID;DEL;EXT;DATE;LANG;LIBRATE;KEYWORDS;
+
+Скачать:
+
+http://home-lib.net/download/inpx/librusec_local_fb2.inpx
+http://home-lib.net/download/inpx/librusec_local_usr.inpx
+http://home-lib.net/download/inpx/librusec_local_all.inpx
return table(name=name, count=0, **kw)
+def update_counters():
+ for author in Author.select():
+ author.count = len(author.books)
+
+ for ext in Extension.select():
+ ext.count = Book.select(Book.q.extension == ext.name).count()
+
+ for genre in Genre.select():
+ genre.count = len(genre.books)
+
+ for language in Language.select():
+ language.count = Book.select(Book.q.language == language.name).count()
+
+
def test():
print "DB dirs:", db_dirs
if db_uri:
--- /dev/null
+
+__all__ = ['import_inpx']
+
+import os
+from zipfile import ZipFile
+from sqlobject import sqlhub, SQLObjectNotFound
+from .db import Author, Book, Extension, Genre, Language, insert_name
+
+
+EOT = chr(4) # INP field separator
+
+
+def split_line(line):
+ parts = line.strip().split(EOT)
+ l = len(parts)
+ if l < 11:
+ raise ValueError('Unknown INP structure: "%s"' % line)
+ if l == 11: # Standard structure
+ parts.append(None) # Emulate lang
+ else: # New structure
+ parts = parts[:12]
+ return parts
+
+
+def import_inp_line(archive, parts):
+ authors, genres, title, series, ser_no, file, size, lib_id, deleted, \
+ extension, date, language = parts
+ try:
+ Book.archive_file_idx.get(archive, file)
+ except SQLObjectNotFound:
+ pass
+ else:
+ return
+ try:
+ ser_no = int(ser_no)
+ except ValueError:
+ ser_no = None
+ size = int(size)
+ deleted = deleted == '1'
+ extension_row = insert_name(Extension, extension)
+ language_row = insert_name(Language, language)
+ book = Book(title=title, series=series, ser_no=ser_no,
+ archive=archive, file=file, size=size,
+ lib_id=lib_id, deleted=deleted,
+ extension=extension_row, date=date,
+ language=language_row)
+ for author in authors.split(':'):
+ if author:
+ author_row = insert_name(Author, author)
+ book.addAuthor(author_row)
+ for genre in genres.split(':'):
+ if genre:
+ genre_row = insert_name(Genre, genre, title=genre)
+ book.addGenre(genre_row)
+
+
+def import_inp(archive, inp):
+ for line in inp:
+ import_inp_line(archive, split_line(line))
+
+
+def import_inpx(path):
+ inpx = ZipFile(path)
+ for name in inpx.namelist():
+ archive, ext = os.path.splitext(name)
+ if ext != 'inp':
+ continue
+ inp = inpx.open(name)
+ sqlhub.doInTransaction(import_inp, archive + '.zip', inp)
+ inp.close()