Использование::
- ml-search.py [-i/-I] [-t/-s/-f] 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] [-e ext]
Искать и печатать список книг по заголовку, серии, архиву, имени файла.
-d, --details Выводить больше информации о найденных книгах;
повторите эту опцию несколько раз, чтобы
получить ещё больше деталей
+ -e, --ext ext Искать по расширению имени файла
По умолчанию программы выводит список заголовков найденных книг. При
использовании опции `-d` также выводится список авторов и жанров, а
Usage::
- ml-search.py [-i/-I] [-t/-s/-f] 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] [-e ext]
Search and print a list of books by title, series, archive or file name.
-f, --file file Search by file name (without extension)
-d, --details Output more details about books;
repeat for even more details
+ -e, --ext ext Search by file extension
By default the program prints only titles of the found book. With one
option `-d` it also prints the list of authors and genres, and also
def mk_search_conditions(table, search_type, case_sensitive, values,
- expressions=None):
+ expressions=None, join_expressions=None):
+ if join_expressions is None:
+ join_expressions = []
return _mk_search_conditions_with_operator(
table, case_sensitive, _search_conditions_dict[search_type],
- values, expressions)
+ values, expressions) + join_expressions
def _search(table, search_type, case_sensitive, values,
- expressions=None, orderBy=None):
+ expressions=None, join_expressions=None, orderBy=None):
conditions = mk_search_conditions(
- table, search_type, case_sensitive, values, expressions=expressions)
+ table, search_type, case_sensitive, values, expressions=expressions,
+ join_expressions=join_expressions)
return table.select(AND(*conditions), orderBy=orderBy)
expressions=None, orderBy=orderBy)
-def search_books(search_type, case_sensitive, values, orderBy=None):
+def search_books(search_type, case_sensitive, values, join_expressions=None,
+ orderBy=None):
return _search(Book, search_type, case_sensitive, values,
- orderBy=orderBy)
+ join_expressions=join_expressions, orderBy=orderBy)
def search_extensions(search_type, case_sensitive, values, orderBy=None):
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_books, \
+from m_librarian.db import Author, Book, Extension, open_db
+from m_librarian.search import mk_search_conditions, \
+ search_authors, search_books, \
search_extensions, search_genres, search_languages
from m_librarian.translations import translations
def _search_books(case_sensitive, search_type, args):
values = {}
+ join_expressions = []
for column in 'title', 'series', 'archive', 'file':
value = getattr(args, column)
if value:
values[column] = unicode(value, default_encoding)
if case_sensitive is None:
- case_sensitive = _guess_case_sensitivity(values)
+ test_values = values.copy()
+ for column in 'ext', :
+ value = getattr(args, column)
+ if value:
+ test_values[column] = unicode(value, default_encoding)
+ case_sensitive = _guess_case_sensitivity(test_values)
+ if args.ext:
+ join_expressions.append(Book.j.extension)
+ conditions = mk_search_conditions(
+ Extension, search_type, case_sensitive,
+ {'name': args.ext})
+ join_expressions.extend(conditions)
for book in search_books(search_type, case_sensitive, values,
+ join_expressions,
orderBy=('series', 'ser_no', 'title')):
print book.title.encode(default_encoding)
if args.details >= 1:
parser.add_argument('-d', '--details', action='count',
help='output more details about books; '
'repeat for even more details')
+ parser.add_argument('-e', '--ext', help='search by file extension')
parser.set_defaults(func=_search_books)
parser = subparsers.add_parser('ext', help='Search extensions')