From: Oleg Broytman Date: Fri, 13 May 2016 19:14:22 +0000 (+0300) Subject: Search languages by name X-Git-Tag: 0.0.5~2 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=81e51d7fdb7ee03b540a4bb82477b4da90a0a2eb;p=m_librarian.git Search languages by name --- diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index 6fc5f87..b219022 100644 --- a/docs-ru/command_line.rst +++ b/docs-ru/command_line.rst @@ -116,4 +116,13 @@ ml-search.py -n, --name имя Искать по названию -t, --title заголовок Искать по заголовку +Поиск языков +^^^^^^^^^^^^ + +Использование:: + + ml-search.py [-i] [-I] [-t ...] lang name + +Искать и печатать список языков по имени. + .. vim: set tw=72 : diff --git a/docs/command_line.rst b/docs/command_line.rst index 2697d50..ca386bd 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -114,4 +114,13 @@ Options:: -n, --name name Search by name -t, --title title Search by title +Language search +^^^^^^^^^^^^^^^ + +Usage:: + + ml-search.py [-i] [-I] [-t ...] lang name + +Search and print a list of languages by name. + .. vim: set tw=72 : diff --git a/scripts/ml-search.py b/scripts/ml-search.py index ef396fd..e4ae011 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -7,7 +7,7 @@ from sqlobject.sqlbuilder import CONCAT from m_lib.defenc import default_encoding from m_librarian.db import Author, open_db from m_librarian.search import search_authors, search_extensions, \ - search_genres + search_genres, search_languages from m_librarian.translations import translations _ = translations.ugettext @@ -75,6 +75,15 @@ def _search_genres(case_sensitive, args): (u"(%s: %d)" % (_('books'), genre.count)).encode(default_encoding) +def _search_languages(case_sensitive, args): + values = {'name': args.name} + if case_sensitive is None: + case_sensitive = _guess_case_sensitivity(values) + for lang in search_languages(args.search_type, case_sensitive, values): + print lang.name.encode(default_encoding), \ + (u"(%s: %d)" % (_('books'), lang.count)).encode(default_encoding) + + if __name__ == '__main__': main_parser = argparse.ArgumentParser(description='Search') main_parser.add_argument('-i', '--ignore-case', @@ -108,6 +117,10 @@ if __name__ == '__main__': parser.add_argument('-t', '--title', help='search by title') parser.set_defaults(func=_search_genres) + parser = subparsers.add_parser('lang', help='Search languages') + parser.add_argument('name', help='search by name') + parser.set_defaults(func=_search_languages) + args = main_parser.parse_args() if args.case_sensitive: if args.ignore_case: