From: Oleg Broytman Date: Tue, 24 May 2016 21:47:20 +0000 (+0300) Subject: Search books by author's names X-Git-Tag: 0.0.7~2 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=6408cf9621ddfc695902939bcdfe29fe73528e96;p=m_librarian.git Search books by author's names --- diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index 640607d..202494c 100644 --- a/docs-ru/command_line.rst +++ b/docs-ru/command_line.rst @@ -100,7 +100,7 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] [-l lang] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [--surname name] [--name name] [--misc-name name] [--fullname name] [-e ext] [-l lang] Искать и печатать список книг по заголовку, серии, архиву, имени файла. @@ -113,6 +113,10 @@ ml-search.py -d, --details Выводить больше информации о найденных книгах; повторите эту опцию несколько раз, чтобы получить ещё больше деталей + --surname surname Искать по фамилии автора + --name name Искать по имени автора + --misc-name misc. name Искать по доп. имени автора + --fullname name Искать по полному имени автора -e, --ext ext Искать по расширению имени файла -l, --lang lang Искать по языку diff --git a/docs/command_line.rst b/docs/command_line.rst index 837a415..1739afc 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -99,7 +99,7 @@ Book search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] [-l lang] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [--surname name] [--name name] [--misc-name name] [--fullname name] [-e ext] [-l lang] Search and print a list of books by title, series, archive or file name. @@ -111,6 +111,10 @@ Options:: -f, --file file Search by file name (without extension) -d, --details Output more details about books; repeat for even more details + --surname surname Search by author's surname + --name name Search by author's name + --misc-name misc. name Search by author's misc. name + --fullname name Search by author's full name -e, --ext ext Search by file extension -l, --lang lang Search by language diff --git a/scripts/ml-search.py b/scripts/ml-search.py index eff58fb..db57f2b 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -62,8 +62,28 @@ def _search_books(case_sensitive, search_type, args): values = _get_values(args, 'title', 'series', 'archive', 'file') if case_sensitive is None: test_values = values.copy() - test_values.update(_get_values(args, 'ext', 'lang')) + test_values.update(_get_values(args, 'surname', 'name', 'misc_name', + 'fullname', 'ext', 'lang')) case_sensitive = _guess_case_sensitivity(test_values) + avalues = _get_values(args, 'surname', 'name', 'misc_name', 'fullname') + if avalues: + if (args.surname or args.name or args.misc_name) and args.fullname: + sys.stderr.write( + "Cannot search by names and full name at the same time\n") + main_parser.print_help() + sys.exit(1) + expressions = [] + join_expressions.append(Book.j.authors) + value = args.fullname + if value: + expressions.append(( + CONCAT(Author.q.surname, ' ', Author.q.name, ' ', + Author.q.misc_name), + unicode(value, default_encoding) + )) + conditions = mk_search_conditions( + Author, search_type, case_sensitive, avalues, expressions) + join_expressions.extend(conditions) if args.ext: join_expressions.append(Book.j.extension) conditions = mk_search_conditions( @@ -178,6 +198,10 @@ if __name__ == '__main__': parser.add_argument('-d', '--details', action='count', help='output more details about books; ' 'repeat for even more details') + parser.add_argument('--surname', help='search by author\'s surname') + parser.add_argument('--name', help='search by author\'s name') + parser.add_argument('--misc-name', help='search by author\'s misc. name') + parser.add_argument('--fullname', help='search by author\'s full name') parser.add_argument('-e', '--ext', help='search by file extension') parser.add_argument('-l', '--lang', help='search by language') parser.set_defaults(func=_search_books)