From: Oleg Broytman Date: Thu, 9 Jun 2016 17:52:02 +0000 (+0300) Subject: Download many books at once X-Git-Tag: 0.0.12~2 X-Git-Url: https://git.phdru.name/?p=m_librarian.git;a=commitdiff_plain;h=f500438f9ec07d6242b6f5c06125a6df7d696919 Download many books at once --- diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index 872ef5c..a86687e 100644 --- a/docs-ru/command_line.rst +++ b/docs-ru/command_line.rst @@ -121,7 +121,7 @@ ml-search.py Использование:: - ml-search.py books [-t title] [-s series] [-a archive] [-f file] [-p path] [--get] [--id id] [--surname name] [--name name] [--misc-name name] [--fullname name] [--aid aid] [-e ext] [--eid eid] [--gname name] [--gtitle title] [--gid gid] [-l lang] [--lid lid] + ml-search.py books [-t title] [-s series] [-a archive] [-f file] [-p path] [--get] [--get-many N] [--id id] [--surname name] [--name name] [--misc-name name] [--fullname name] [--aid aid] [-e ext] [--eid eid] [--gname name] [--gtitle title] [--gid gid] [-l lang] [--lid lid] Искать и печатать список книг по заголовку, серии, архиву, имени файла. @@ -133,6 +133,7 @@ ml-search.py -f, --file файл Искать по имени файла (без расширения) -p, --path path Путь к директории с архивами библиотеки --get Загрузить ровно один файл + --get-many N Загрузить не больше указанного числа файлов --id id Искать по id книги --surname surname Искать по фамилии автора --name name Искать по имени автора @@ -194,6 +195,10 @@ ml-search.py в конец с точкой в качестве разделителя. Т.о. формат `%f` эквивалентен формату `%f.%e`. +Опция `--get-many N` позволяет загрузить указанное число книг (не больше +чем N, где N — целое число.) Опции `--get-many N` и `--get` взаимно +исключают друг друга и не должны использоваться одновременно. + Поиск расширений ^^^^^^^^^^^^^^^^ diff --git a/docs/command_line.rst b/docs/command_line.rst index ef27723..5125d0e 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -118,7 +118,7 @@ Book searching and downloading Usage:: - ml-search.py books [-t title] [-s series] [-a archive] [-f file] [-p path] [--get] [--id id] [--surname name] [--name name] [--misc-name name] [--fullname name] [--aid aid] [-e ext] [--eid eid] [--gname name] [--gtitle title] [--gid gid] [-l lang] [--lid lid] + ml-search.py books [-t title] [-s series] [-a archive] [-f file] [-p path] [--get] [--get-many N] [--id id] [--surname name] [--name name] [--misc-name name] [--fullname name] [--aid aid] [-e ext] [--eid eid] [--gname name] [--gtitle title] [--gid gid] [-l lang] [--lid lid] Search and print a list of books by title, series, archive or file name. @@ -131,6 +131,7 @@ Options:: -p, --path path Path to the directory with the library archives --get Download exactly one book + --get-many N Download at most this many books --id id Search by database id --surname surname Search by author’s surname --name name Search by author’s name @@ -190,6 +191,10 @@ Format must not end in directory separator (`/` or `\\`). If specifier unconditionally with a dot. That is, format `%f` is equivalent to `%f.%e`. +Option `--get-many N` allows to download many books (at most N, where N +is an integer). Options `--get-many N` and `--get` are, of course, +mutually incompatible. + Extension search ^^^^^^^^^^^^^^^^ diff --git a/scripts/ml-search.py b/scripts/ml-search.py index 48fce48..9f06657 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -73,6 +73,11 @@ def _search_authors(case_sensitive, search_type, args): def _search_books(case_sensitive, search_type, args): + if args.get and args.get_many: + sys.stderr.write( + "Cannot get one book and many books at the same time\n") + main_parser.print_help() + sys.exit(1) join_expressions = [] values = _get_values(args, 'title', 'series', 'archive', 'file', 'id') if case_sensitive is None: @@ -139,15 +144,16 @@ def _search_books(case_sensitive, search_type, args): if args.count: print_count(books.count()) return - if args.get: + if args.get_many: + books = books[:args.get_many] + elif args.get: count = books.count() if count != 1: sys.stderr.write("There must be exactly 1 book for --get; " "(found %d).\n" % count) + sys.stderr.write("Use --get-many N to download more than one " + "book.\n") sys.exit(1) - book = books[0] - download(book, args.path) - return count = 0 for book in books: print book.title.encode(default_encoding), @@ -182,6 +188,8 @@ def _search_books(case_sensitive, search_type, args): book.size, _("bytes").encode(default_encoding) print " ", _("Deleted").encode(default_encoding), ":", \ _(str(book.deleted)).encode(default_encoding) + if args.get or args.get_many: + download(book, args.path) count += 1 print_count(count) @@ -289,6 +297,8 @@ if __name__ == '__main__': 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('--get-many', type=int, + help='download at most this many books') parser.add_argument('--id', type=int, 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')