]> git.phdru.name Git - m_librarian.git/blobdiff - scripts/ml-search.py
Allow to set download format
[m_librarian.git] / scripts / ml-search.py
index b35d7eba546c375b85eaf8ad72d24db172c1ff9e..d19c5b4f6408b8ce4d629fe7913e2fd816cf63a2 100755 (executable)
@@ -6,6 +6,7 @@ from sqlobject.sqlbuilder import CONCAT
 
 from m_lib.defenc import default_encoding
 from m_librarian.db import Author, Book, Extension, Genre, Language, open_db
+from m_librarian.download import download
 from m_librarian.search import mk_search_conditions, \
     search_authors, search_books, \
     search_extensions, search_genres, search_languages
@@ -59,9 +60,7 @@ def _search_authors(case_sensitive, search_type, args):
         return
     count = 0
     for author in authors:
-        names = filter(None, (author.surname, author.name, author.misc_name))
-        fullname = u' '.join(names)
-        print fullname.encode(default_encoding), \
+        print author.fullname.encode(default_encoding), \
             (u"(%s: %d)" % (_('books'), author.count))\
             .encode(default_encoding),
         if args.verbose >= 1:
@@ -138,6 +137,15 @@ def _search_books(case_sensitive, search_type, args):
     if args.count:
         print_count(books.count())
         return
+    if args.get:
+        count = books.count()
+        if count != 1:
+            sys.stderr.write("There must be exactly 1 book for --get; "
+                             "(found %d).\n" % count)
+            sys.exit(1)
+        book = books[0]
+        download(book, args.path)
+        return
     count = 0
     for book in books:
         print book.title.encode(default_encoding),
@@ -147,10 +155,7 @@ def _search_books(case_sensitive, search_type, args):
         if args.verbose >= 1:
             print " ", _("Author(s)").encode(default_encoding), ":",
             for author in book.authors:
-                names = filter(None,
-                               (author.surname, author.name, author.misc_name))
-                fullname = u' '.join(names)
-                print fullname.encode(default_encoding),
+                print author.fullname.encode(default_encoding),
             print
             print " ", _("Genre(s)").encode(default_encoding), ":",
             for genre in book.genres:
@@ -279,6 +284,9 @@ if __name__ == '__main__':
     parser.add_argument('-s', '--series', help='search by series')
     parser.add_argument('-a', '--archive', help='search by archive (zip file)')
     parser.add_argument('-f', '--file', help='search by file name')
+    parser.add_argument('-p', '--path', help='path to the library archives')
+    parser.add_argument('--get', action='store_true',
+                        help='download exactly one book')
     parser.add_argument('--id', help='search by database id')
     parser.add_argument('--surname', help='search by author\'s surname')
     parser.add_argument('--name', help='search by author\'s name')