From a8f1548e9c27d01b0d64ef0efa20d7220318e4b1 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 30 May 2016 20:45:48 +0300 Subject: [PATCH] Search authors/extensions/genres/languages by database id --- docs-ru/command_line.rst | 18 ++++++++++++++---- docs/command_line.rst | 18 ++++++++++++++---- scripts/ml-search.py | 22 ++++++++++++---------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index eb83521..5bb3699 100644 --- a/docs-ru/command_line.rst +++ b/docs-ru/command_line.rst @@ -73,7 +73,7 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] author [-s surname] [-n name] [-m misc-name] [fullname] + ml-search.py [-i/-I] [-t/-s/-f] author [-s surname] [-n name] [-m misc-name] [--id id] [fullname] Искать и печатать список авторов по фамилии, имени, доп. имени (обычно отчеству) или полному имени. @@ -83,6 +83,7 @@ ml-search.py -s, --surname фамилия Искать по фамилии -n, --name имя Искать по имени -m, --misc-name доп. имени Искать по доп. имени + --id id Искать по id автора Пример:: @@ -145,7 +146,11 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] ext [name] + ml-search.py [-i/-I] [-t/-s/-f] ext [name] [--id id] + +Опции:: + + --id id Искать по id расширения Искать и печатать список расширений имён файлов по имени. @@ -157,7 +162,7 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title] + ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title] [--id id] Искать и печатать список жанров по имени и заголовку. @@ -165,6 +170,7 @@ ml-search.py -n, --name имя Искать по названию -t, --title заголовок Искать по заголовку + --id id Искать по id жанра При использовании опции `-d` также выводится id из БД. @@ -174,7 +180,11 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] lang [name] + ml-search.py [-i/-I] [-t/-s/-f] lang [name] [--id id] + +Опции:: + + --id id Искать по id языка Искать и печатать список языков по имени. diff --git a/docs/command_line.rst b/docs/command_line.rst index 6aec9f8..2905b26 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -71,7 +71,7 @@ Author search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] author [-s surname] [-n name] [-m misc-name] [fullname] + ml-search.py [-i/-I] [-t/-s/-f] author [-s surname] [-n name] [-m misc-name] [--id id] [fullname] Search and print a list of authors by surname/name/misc name/full name. @@ -80,6 +80,7 @@ Options:: -s, --surname surname Search by surname -n, --name name Search by name -m, --misc-name misc. name Search by misc. name + --id id Search by database id Example:: @@ -142,7 +143,11 @@ Extension search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] ext [name] + ml-search.py [-i/-I] [-t/-s/-f] ext [name] [--id id] + +Options:: + + --id id Search by database id Search and print a list of extensions by name. @@ -154,7 +159,7 @@ Genres search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title] + ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title] [--id id] Search and print a list of genres by name and title. @@ -162,6 +167,7 @@ Options:: -n, --name name Search by name -t, --title title Search by title + --id id Search by database id With one option `-d` it also prints database id. @@ -171,10 +177,14 @@ Language search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] lang [name] + ml-search.py [-i/-I] [-t/-s/-f] lang [name] [--id id] Search and print a list of languages by name. +Options:: + + --id id Search by database id + With one option `-d` it also prints database id. .. vim: set tw=72 : diff --git a/scripts/ml-search.py b/scripts/ml-search.py index 5e26ab5..d6ea828 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -37,7 +37,7 @@ def _search_authors(case_sensitive, search_type, args): main_parser.print_help() sys.exit(1) expressions = [] - values = _get_values(args, 'surname', 'name', 'misc_name') + values = _get_values(args, 'surname', 'name', 'misc_name', 'id') if not values: value = args.fullname if value: @@ -170,10 +170,9 @@ def _search_books(case_sensitive, search_type, args): def _search_extensions(case_sensitive, search_type, args): - if args.name: - values = {'name': args.name} - if case_sensitive is None: - case_sensitive = _guess_case_sensitivity(values) + values = _get_values(args, 'name', 'id') + if case_sensitive is None: + case_sensitive = _guess_case_sensitivity(values) else: values = {} extensions = search_extensions(search_type, case_sensitive, values, @@ -190,7 +189,7 @@ def _search_extensions(case_sensitive, search_type, args): def _search_genres(case_sensitive, search_type, args): - values = _get_values(args, 'name', 'title') + values = _get_values(args, 'name', 'title', 'id') if case_sensitive is None: case_sensitive = _guess_case_sensitivity(values) genres = search_genres(search_type, case_sensitive, values, orderBy='name') @@ -208,10 +207,9 @@ def _search_genres(case_sensitive, search_type, args): def _search_languages(case_sensitive, search_type, args): - if args.name: - values = {'name': args.name} - if case_sensitive is None: - case_sensitive = _guess_case_sensitivity(values) + values = _get_values(args, 'name', 'id') + if case_sensitive is None: + case_sensitive = _guess_case_sensitivity(values) else: values = {} for lang in search_languages(search_type, case_sensitive, values, @@ -248,6 +246,7 @@ if __name__ == '__main__': parser.add_argument('-s', '--surname', help='search by surname') parser.add_argument('-n', '--name', help='search by name') parser.add_argument('-m', '--misc-name', help='search by misc. name') + parser.add_argument('--id', help='search by database id') parser.add_argument('fullname', nargs='?', help='search by full name') parser.set_defaults(func=_search_authors) @@ -273,15 +272,18 @@ if __name__ == '__main__': parser = subparsers.add_parser('ext', help='Search extensions') parser.add_argument('name', nargs='?', help='search by name') + parser.add_argument('--id', help='search by database id') parser.set_defaults(func=_search_extensions) parser = subparsers.add_parser('genres', help='Search genres') parser.add_argument('-n', '--name', help='search by name') parser.add_argument('-t', '--title', help='search by title') + parser.add_argument('--id', help='search by database id') parser.set_defaults(func=_search_genres) parser = subparsers.add_parser('lang', help='Search languages') parser.add_argument('name', nargs='?', help='search by name') + parser.add_argument('--id', help='search by database id') parser.set_defaults(func=_search_languages) args = main_parser.parse_args() -- 2.39.5