Использование::
- ml-search.py [-i] [-I] [-t {exact,start,substring}] ...
+ ml-search.py [-i] [-I] [-t] [-s] [-f] ...
Программа выполняет поиск по базе данных и показывает список
результатов. В настоящее время может искать только в списке авторов.
-i, --ignore-case независимо от регистра (по умолчанию: угадать)
-I, --case-sensitive с учётом регистра
- -t, --search-type {exact,start,substring}
- тип поиска: точный, подстрока в начале (это тип по умолчанию),
- подстрока в любом месте.
+ -t, --start тип поиска: подстрока в начале строки
+ (это тип поиска по умолчанию)
+ -s, --substring тип поиска: подстрока в любом месте
+ -f, --full тип поиска: полное совпадение всей строки
Опции ``-i/-I`` не могут использованы одновременно, поскольку означают
противоположные команды. В случае, если ни одна из них не использована,
параметров есть параметры в ВЕРХНЕМ или Смешанном регистре - поиск будет
с учётом регистра.
-Опция ``-t/--search-type`` определяет тип поиска. Возможные значения:
+Опции ``-t/-s/-f`` определяют тип поиска. Возможные значения:
-* exact - поиск на точное совпадение; поиск "друг" найдёт только "друг",
- но не "другой";
* start - поиск подстроки в начале поля; поиск "друг" найдёт "друг" и
"другой", но не "подруга"; это тип по умолчанию;
* substring - поиск подстроки в любом месте; поиск "друг" найдёт "друг",
"другой" и "подруга".
+* full - поиск на точное совпадение всей строки; поиск "друг" найдёт
+ только "друг", но не "другой";
Поиск авторов
Использование::
- ml-search.py [-i] [-I] [-t ...] 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] [fullname]
Искать и печатать список авторов по фамилии, имени, доп. имени (обычно
отчеству) или полному имени.
Использование::
- ml-search.py [-i] [-I] [-t ...] books [-t title] [-s series] [-a archive] [-f file] [-d]
+ ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d]
Искать и печатать список книг по заголовку, серии, архиву, имени файла.
Использование::
- ml-search.py [-i] [-I] [-t ...] ext [name]
+ ml-search.py [-i/-I] [-t/-s/-f] ext [name]
Искать и печатать список расширений имён файлов по имени.
Использование::
- ml-search.py [-i] [-I] [-t ...] genres [-n name] [-t title]
+ ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title]
Искать и печатать список жанров по имени и заголовку.
Использование::
- ml-search.py [-i] [-I] [-t ...] lang [name]
+ ml-search.py [-i/-I] [-t/-s/-f] lang [name]
Искать и печатать список языков по имени.
Usage::
- ml-search.py [-i] [-I] [-t {exact,start,substring}] ...
+ ml-search.py [-i] [-I] [-t] [-s] [-f] ...
Search through the database and display results. Currently can only
search authors by name.
-i, --ignore-case ignore case (default is to guess)
-I, --case-sensitive don't ignore case
- -t, --search-type {exact,start,substring}
- search type: exact match, substring at the start (this is the default),
- substring anywhere.
+ -t, --start search type: substring at the start
+ (this is the default)
+ -s, --substring search type: substring anywhere
+ -f, --full search type: match the full string
Options ``-i/-I`` cannot be used together as they are the opposite. In
case none of them are used the program guesses case-sensitivity by
performs case-insensitive search. If there are UPPERCASE or MixedCase
arguments the program performs case-sensitive search.
-Option ``-t/--search-type`` defines the search type. Search types are:
+Options ``-t/-s/-f`` define the search type. Search types are:
-* exact - search for exact match; i.e. searching for "duck" returns
- results for "duck" but not for "duckling";
* start - search for substring at the start of the search field; for
example searching for "duck" returns results for "duck" and "duckling"
but not for "McDuck"; this is the default search type.
* substring - search for any substring; "duck" => "duck", "duckling",
"McDuck" (except for case-sensitive search, of course).
+* full - search for exact match, compare the entire strings;
+ i.e. searching for "duck" returns results for "duck" but not for
+ "duckling";
Author search
Usage::
- ml-search.py [-i] [-I] [-t ...] 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] [fullname]
Search and print a list of authors by surname/name/misc name/full name.
Usage::
- ml-search.py [-i] [-I] [-t ...] books [-t title] [-s series] [-a archive] [-f file] [-d]
+ ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d]
Search and print a list of books by title, series, archive or file name.
Usage::
- ml-search.py [-i] [-I] [-t ...] ext [name]
+ ml-search.py [-i/-I] [-t/-s/-f] ext [name]
Search and print a list of extensions by name.
Usage::
- ml-search.py [-i] [-I] [-t ...] genres [-n name] [-t title]
+ ml-search.py [-i/-I] [-t/-s/-f] genres [-n name] [-t title]
Search and print a list of genres by name and title.
Usage::
- ml-search.py [-i] [-I] [-t ...] lang [name]
+ ml-search.py [-i/-I] [-t/-s/-f] lang [name]
Search and print a list of languages by name.
return False
-def _search_authors(case_sensitive, args):
+def _search_authors(case_sensitive, search_type, args):
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")
))
if case_sensitive is None:
case_sensitive = _guess_case_sensitivity(values)
- for author in search_authors(args.search_type, case_sensitive, values,
+ for author in search_authors(search_type, case_sensitive, values,
expressions,
orderBy=('surname', 'name', 'misc_name')):
names = filter(None, (author.surname, author.name, author.misc_name))
(u"(%s: %d)" % (_('books'), author.count)).encode(default_encoding)
-def _search_books(case_sensitive, args):
+def _search_books(case_sensitive, search_type, args):
values = {}
for column in 'title', 'series', 'archive', 'file':
value = getattr(args, column)
values[column] = unicode(value, default_encoding)
if case_sensitive is None:
case_sensitive = _guess_case_sensitivity(values)
- for book in search_books(args.search_type, case_sensitive, values,
+ for book in search_books(search_type, case_sensitive, values,
orderBy='title'):
print book.title.encode(default_encoding)
if args.details > 0:
print
-def _search_extensions(case_sensitive, 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)
else:
values = {}
- for ext in search_extensions(args.search_type, case_sensitive, values,
+ for ext in search_extensions(search_type, case_sensitive, values,
orderBy='name'):
print ext.name.encode(default_encoding), \
(u"(%s: %d)" % (_('books'), ext.count)).encode(default_encoding)
-def _search_genres(case_sensitive, args):
+def _search_genres(case_sensitive, search_type, args):
values = {}
for column in 'name', 'title':
value = getattr(args, column)
values[column] = unicode(value, default_encoding)
if case_sensitive is None:
case_sensitive = _guess_case_sensitivity(values)
- for genre in search_genres(args.search_type, case_sensitive, values,
+ for genre in search_genres(search_type, case_sensitive, values,
orderBy='name'):
names = filter(None, (genre.name, genre.title))
fullname = u' '.join(names)
(u"(%s: %d)" % (_('books'), genre.count)).encode(default_encoding)
-def _search_languages(case_sensitive, 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)
else:
values = {}
- for lang in search_languages(args.search_type, case_sensitive, values,
+ for lang in search_languages(search_type, case_sensitive, values,
orderBy='name'):
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',
- action='store_true',
+ main_parser.add_argument('-i', '--ignore-case', action='store_true',
help='ignore case '
'(default is to guess)')
- main_parser.add_argument('-I', '--case-sensitive',
- action='store_true',
- help='don\'t ignore case ')
- main_parser.add_argument('-t', '--search-type',
- choices=['exact', 'start', 'substring'],
- default='start',
- help='search type: '
- 'exact match, substring at the start '
- '(this is the default), substring anywhere')
+ main_parser.add_argument('-I', '--case-sensitive', action='store_true',
+ help='don\'t ignore case')
+ main_parser.add_argument('-t', '--start', action='store_true',
+ help='search substring at the start '
+ '(this is the default)')
+ main_parser.add_argument('-s', '--substring', action='store_true',
+ help='search substring anywhere')
+ main_parser.add_argument('-f', '--full', action='store_true',
+ help='match the entire string')
subparsers = main_parser.add_subparsers(help='Commands')
parser = subparsers.add_parser('authors', help='Search authors')
parser.set_defaults(func=_search_languages)
args = main_parser.parse_args()
+
if args.case_sensitive:
if args.ignore_case:
sys.stderr.write(
case_sensitive = False
else:
case_sensitive = None # guess case sensitivity
+
+ if int(args.start) + int(args.substring) + int(args.full) > 1:
+ sys.stderr.write(
+ "Cannot search case sensitive and case insensitive "
+ "at the same time\n")
+ main_parser.print_help()
+ sys.exit(1)
+ if args.start:
+ search_type = 'start'
+ elif args.substring:
+ search_type = 'substring'
+ elif args.full:
+ search_type = 'full'
+ else:
+ search_type = 'start'
+
open_db()
- args.func(case_sensitive, args)
+ args.func(case_sensitive, search_type, args)