mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
IGN:...
This commit is contained in:
parent
c4f554dc0e
commit
ceb3378d8c
@ -207,9 +207,9 @@ class MetaInformation(object):
|
|||||||
title = mi.title
|
title = mi.title
|
||||||
authors = mi.authors
|
authors = mi.authors
|
||||||
self.title = title
|
self.title = title
|
||||||
self.author = list(authors) # Needed for backward compatibility
|
self.author = list(authors) if authors else []# Needed for backward compatibility
|
||||||
#: List of strings or []
|
#: List of strings or []
|
||||||
self.authors = list(authors)
|
self.authors = list(authors) if authors else []
|
||||||
self.tags = getattr(mi, 'tags', [])
|
self.tags = getattr(mi, 'tags', [])
|
||||||
#: mi.cover_data = (ext, data)
|
#: mi.cover_data = (ext, data)
|
||||||
self.cover_data = getattr(mi, 'cover_data', (None, None))
|
self.cover_data = getattr(mi, 'cover_data', (None, None))
|
||||||
|
@ -15,6 +15,7 @@ from calibre import terminal_controller, preferred_encoding
|
|||||||
from calibre.utils.config import OptionParser, prefs
|
from calibre.utils.config import OptionParser, prefs
|
||||||
try:
|
try:
|
||||||
from calibre.utils.single_qt_application import send_message
|
from calibre.utils.single_qt_application import send_message
|
||||||
|
send_message
|
||||||
except:
|
except:
|
||||||
send_message = None
|
send_message = None
|
||||||
from calibre.ebooks.metadata.meta import get_metadata
|
from calibre.ebooks.metadata.meta import get_metadata
|
||||||
@ -55,7 +56,7 @@ XML_TEMPLATE = '''\
|
|||||||
</py:for>
|
</py:for>
|
||||||
</formats>
|
</formats>
|
||||||
</record>
|
</record>
|
||||||
</py:for>
|
</py:for>
|
||||||
</calibredb>
|
</calibredb>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ def get_db(dbpath, options):
|
|||||||
dbpath = os.path.abspath(dbpath)
|
dbpath = os.path.abspath(dbpath)
|
||||||
return LibraryDatabase2(dbpath)
|
return LibraryDatabase2(dbpath)
|
||||||
|
|
||||||
def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
||||||
prefix, output_format, subtitle='Books in the calibre database'):
|
prefix, output_format, subtitle='Books in the calibre database'):
|
||||||
if sort_by:
|
if sort_by:
|
||||||
db.sort(sort_by, ascending)
|
db.sort(sort_by, ascending)
|
||||||
@ -134,13 +135,13 @@ def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
|||||||
for i in data:
|
for i in data:
|
||||||
for j, field in enumerate(fields):
|
for j, field in enumerate(fields):
|
||||||
widths[j] = max(widths[j], len(unicode(i[str(field)])))
|
widths[j] = max(widths[j], len(unicode(i[str(field)])))
|
||||||
|
|
||||||
screen_width = terminal_controller.COLS if line_width < 0 else line_width
|
screen_width = terminal_controller.COLS if line_width < 0 else line_width
|
||||||
if not screen_width:
|
if not screen_width:
|
||||||
screen_width = 80
|
screen_width = 80
|
||||||
field_width = screen_width//len(fields)
|
field_width = screen_width//len(fields)
|
||||||
base_widths = map(lambda x: min(x+1, field_width), widths)
|
base_widths = map(lambda x: min(x+1, field_width), widths)
|
||||||
|
|
||||||
while sum(base_widths) < screen_width:
|
while sum(base_widths) < screen_width:
|
||||||
adjusted = False
|
adjusted = False
|
||||||
for i in range(len(widths)):
|
for i in range(len(widths)):
|
||||||
@ -150,14 +151,14 @@ def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
|||||||
break
|
break
|
||||||
if not adjusted:
|
if not adjusted:
|
||||||
break
|
break
|
||||||
|
|
||||||
widths = list(base_widths)
|
widths = list(base_widths)
|
||||||
titles = map(lambda x, y: '%-*s'%(x, y), widths, fields)
|
titles = map(lambda x, y: '%-*s'%(x, y), widths, fields)
|
||||||
print terminal_controller.GREEN + ''.join(titles)+terminal_controller.NORMAL
|
print terminal_controller.GREEN + ''.join(titles)+terminal_controller.NORMAL
|
||||||
|
|
||||||
wrappers = map(lambda x: TextWrapper(x-1), widths)
|
wrappers = map(lambda x: TextWrapper(x-1), widths)
|
||||||
o = cStringIO.StringIO()
|
o = cStringIO.StringIO()
|
||||||
|
|
||||||
for record in data:
|
for record in data:
|
||||||
text = [wrappers[i].wrap(unicode(record[field]).encode('utf-8')) for i, field in enumerate(fields)]
|
text = [wrappers[i].wrap(unicode(record[field]).encode('utf-8')) for i, field in enumerate(fields)]
|
||||||
lines = max(map(len, text))
|
lines = max(map(len, text))
|
||||||
@ -178,9 +179,9 @@ def do_list(db, fields, sort_by, ascending, search_text, line_width, separator,
|
|||||||
if isinstance(x['fmt_epub'], unicode):
|
if isinstance(x['fmt_epub'], unicode):
|
||||||
x['fmt_epub'] = x['fmt_epub'].encode('utf-8')
|
x['fmt_epub'] = x['fmt_epub'].encode('utf-8')
|
||||||
template = MarkupTemplate(STANZA_TEMPLATE)
|
template = MarkupTemplate(STANZA_TEMPLATE)
|
||||||
return template.generate(id="urn:calibre:main", data=data, subtitle=subtitle,
|
return template.generate(id="urn:calibre:main", data=data, subtitle=subtitle,
|
||||||
sep=os.sep, quote=quote, updated=db.last_modified()).render('xml')
|
sep=os.sep, quote=quote, updated=db.last_modified()).render('xml')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def command_list(args, dbpath):
|
def command_list(args, dbpath):
|
||||||
@ -199,7 +200,7 @@ List the books available in the calibre database.
|
|||||||
help=_('Sort results in ascending order'))
|
help=_('Sort results in ascending order'))
|
||||||
parser.add_option('-s', '--search', default=None,
|
parser.add_option('-s', '--search', default=None,
|
||||||
help=_('Filter the results by the search query. For the format of the search query, please see the search related documentation in the User Manual. Default is to do no filtering.'))
|
help=_('Filter the results by the search query. For the format of the search query, please see the search related documentation in the User Manual. Default is to do no filtering.'))
|
||||||
parser.add_option('-w', '--line-width', default=-1, type=int,
|
parser.add_option('-w', '--line-width', default=-1, type=int,
|
||||||
help=_('The maximum width of a single line in the output. Defaults to detecting screen size.'))
|
help=_('The maximum width of a single line in the output. Defaults to detecting screen size.'))
|
||||||
parser.add_option('--separator', default=' ', help=_('The string used to separate fields. Default is a space.'))
|
parser.add_option('--separator', default=' ', help=_('The string used to separate fields. Default is a space.'))
|
||||||
parser.add_option('--prefix', default=None, help=_('The prefix for all file paths. Default is the absolute path to the library folder.'))
|
parser.add_option('--prefix', default=None, help=_('The prefix for all file paths. Default is the absolute path to the library folder.'))
|
||||||
@ -264,14 +265,14 @@ def do_add(db, paths, one_book_per_directory, recurse, add_duplicates):
|
|||||||
|
|
||||||
formats.append(format)
|
formats.append(format)
|
||||||
metadata.append(mi)
|
metadata.append(mi)
|
||||||
|
|
||||||
file_duplicates = []
|
file_duplicates = []
|
||||||
if files:
|
if files:
|
||||||
file_duplicates = db.add_books(files, formats, metadata,
|
file_duplicates = db.add_books(files, formats, metadata,
|
||||||
add_duplicates=add_duplicates)
|
add_duplicates=add_duplicates)
|
||||||
if file_duplicates:
|
if file_duplicates:
|
||||||
file_duplicates = file_duplicates[0]
|
file_duplicates = file_duplicates[0]
|
||||||
|
|
||||||
|
|
||||||
dir_dups = []
|
dir_dups = []
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
|
@ -622,11 +622,7 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
if title:
|
if title:
|
||||||
if not isinstance(title, unicode):
|
if not isinstance(title, unicode):
|
||||||
title = title.decode(preferred_encoding, 'replace')
|
title = title.decode(preferred_encoding, 'replace')
|
||||||
tf = FIELD_MAP['title']
|
return bool(self.conn.get('SELECT id FROM books where title=?', (title,), all=False))
|
||||||
q = title.lower()
|
|
||||||
for record in self.data._data:
|
|
||||||
if record is not None and record[tf].lower() == q:
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def has_cover(self, index, index_is_id=False):
|
def has_cover(self, index, index_is_id=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user