mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #54 and add support for sort keys to lrf-meta
This commit is contained in:
parent
21c84c914f
commit
599ee22515
@ -33,7 +33,7 @@ You may have to adjust the GROUP and the location of the rules file to
|
|||||||
suit your distribution.
|
suit your distribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.3.24"
|
__version__ = "0.3.25"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
|
|
||||||
|
@ -155,10 +155,10 @@ class Span(_Span):
|
|||||||
if ans:
|
if ans:
|
||||||
t['fontsize'] = ans
|
t['fontsize'] = ans
|
||||||
elif key == 'font-weight':
|
elif key == 'font-weight':
|
||||||
ans = font_weight(val)
|
ans = font_weight(val)
|
||||||
if ans:
|
if ans:
|
||||||
t['fontweight'] = ans
|
t['fontweight'] = ans
|
||||||
if ans > 140:
|
if int(ans) > 1400:
|
||||||
t['wordspace'] = '50'
|
t['wordspace'] = '50'
|
||||||
elif key.startswith("margin"):
|
elif key.startswith("margin"):
|
||||||
if key == "margin":
|
if key == "margin":
|
||||||
@ -816,11 +816,11 @@ class HTMLConverter(object):
|
|||||||
self.css[key].update(ncss[key])
|
self.css[key].update(ncss[key])
|
||||||
else:
|
else:
|
||||||
self.css[key] = ncss[key]
|
self.css[key] = ncss[key]
|
||||||
ncss = None
|
ncss = {}
|
||||||
if tagname == 'style':
|
if tagname == 'style':
|
||||||
for c in tag.contents:
|
for c in tag.contents:
|
||||||
if isinstance(c, NavigableString):
|
if isinstance(c, NavigableString):
|
||||||
ncss = self.parse_css(str(c))
|
ncss.update(self.parse_css(str(c)))
|
||||||
elif tag.has_key('type') and tag['type'] == "text/css" \
|
elif tag.has_key('type') and tag['type'] == "text/css" \
|
||||||
and tag.has_key('href'):
|
and tag.has_key('href'):
|
||||||
url = tag['href']
|
url = tag['href']
|
||||||
@ -834,7 +834,7 @@ class HTMLConverter(object):
|
|||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
if ncss:
|
if ncss:
|
||||||
update_css(ncss)
|
update_css(ncss)
|
||||||
elif tagname == 'pre':
|
elif tagname == 'pre':
|
||||||
self.end_current_para()
|
self.end_current_para()
|
||||||
self.current_block.append_to(self.current_page)
|
self.current_block.append_to(self.current_page)
|
||||||
|
@ -87,6 +87,46 @@ class fixed_stringfield(object):
|
|||||||
return "A string of length " + str(self._length) + \
|
return "A string of length " + str(self._length) + \
|
||||||
" starting at byte " + str(self._start)
|
" starting at byte " + str(self._start)
|
||||||
|
|
||||||
|
class xml_attr_field(object):
|
||||||
|
def __init__(self, tag_name, attr, parent='BookInfo'):
|
||||||
|
self.tag_name = tag_name
|
||||||
|
self.parent = parent
|
||||||
|
self.attr= attr
|
||||||
|
|
||||||
|
def __get__(self, obj, typ=None):
|
||||||
|
""" Return the data in this field or '' if the field is empty """
|
||||||
|
document = dom.parseString(obj.info)
|
||||||
|
elems = document.getElementsByTagName(self.tag_name)
|
||||||
|
if len(elems):
|
||||||
|
elem = None
|
||||||
|
for candidate in elems:
|
||||||
|
if candidate.parentNode.nodeName == self.parent:
|
||||||
|
elem = candidate
|
||||||
|
if elem and elem.hasAttribute(self.attr):
|
||||||
|
return elem.getAttribute(self.attr)
|
||||||
|
|
||||||
|
def __set__(self, obj, val):
|
||||||
|
if val == None:
|
||||||
|
val = ""
|
||||||
|
document = dom.parseString(obj.info)
|
||||||
|
elems = document.getElementsByTagName(self.tag_name)
|
||||||
|
if len(elems):
|
||||||
|
elem = None
|
||||||
|
for candidate in elems:
|
||||||
|
if candidate.parentNode.nodeName == self.parent:
|
||||||
|
elem = candidate
|
||||||
|
if elem:
|
||||||
|
elem.setAttribute(self.attr, val)
|
||||||
|
info = document.toxml(encoding='utf-16')
|
||||||
|
obj.info = info
|
||||||
|
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "XML Attr Field: " + self.tag_name + " in " + self.parent
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.tag_name+'.'+self.attr
|
||||||
|
|
||||||
class xml_field(object):
|
class xml_field(object):
|
||||||
"""
|
"""
|
||||||
Descriptor that gets and sets XML based meta information from an LRF file.
|
Descriptor that gets and sets XML based meta information from an LRF file.
|
||||||
@ -236,7 +276,9 @@ class LRFMetaFile(object):
|
|||||||
fmt=DWORD, start=0x54)
|
fmt=DWORD, start=0x54)
|
||||||
|
|
||||||
title = xml_field("Title", parent="BookInfo")
|
title = xml_field("Title", parent="BookInfo")
|
||||||
|
title_reading = xml_attr_field("Title", 'reading', parent="BookInfo")
|
||||||
author = xml_field("Author", parent="BookInfo")
|
author = xml_field("Author", parent="BookInfo")
|
||||||
|
author_reading = xml_attr_field("Author", 'reading', parent="BookInfo")
|
||||||
# 16 characters. First two chars should be FB for personal use ebooks.
|
# 16 characters. First two chars should be FB for personal use ebooks.
|
||||||
book_id = xml_field("BookID", parent="BookInfo")
|
book_id = xml_field("BookID", parent="BookInfo")
|
||||||
publisher = xml_field("Publisher", parent="BookInfo")
|
publisher = xml_field("Publisher", parent="BookInfo")
|
||||||
@ -510,8 +552,12 @@ def main():
|
|||||||
""", version=VERSION)
|
""", version=VERSION)
|
||||||
parser.add_option("-t", "--title", action="store", type="string", \
|
parser.add_option("-t", "--title", action="store", type="string", \
|
||||||
dest="title", help="Set the book title")
|
dest="title", help="Set the book title")
|
||||||
|
parser.add_option('--title-sort', action='store', type='string', default=None,
|
||||||
|
dest='title_reading', help='Set sort key for the title')
|
||||||
parser.add_option("-a", "--author", action="store", type="string", \
|
parser.add_option("-a", "--author", action="store", type="string", \
|
||||||
dest="author", help="Set the author")
|
dest="author", help="Set the author")
|
||||||
|
parser.add_option('--author-sort', action='store', type='string', default=None,
|
||||||
|
dest='author_reading', help='Set sort key for the author')
|
||||||
parser.add_option("-c", "--category", action="store", type="string", \
|
parser.add_option("-c", "--category", action="store", type="string", \
|
||||||
dest="category", help="The category this book belongs"+\
|
dest="category", help="The category this book belongs"+\
|
||||||
" to. E.g.: History")
|
" to. E.g.: History")
|
||||||
@ -533,6 +579,10 @@ def main():
|
|||||||
lrf = LRFMetaFile(open(args[0], "r+b"))
|
lrf = LRFMetaFile(open(args[0], "r+b"))
|
||||||
if options.title:
|
if options.title:
|
||||||
lrf.title = options.title
|
lrf.title = options.title
|
||||||
|
if options.title_reading != None:
|
||||||
|
lrf.title_reading = options.title_reading
|
||||||
|
if options.author_reading != None:
|
||||||
|
lrf.author_reading = options.author_reading
|
||||||
if options.author:
|
if options.author:
|
||||||
lrf.author = options.author
|
lrf.author = options.author
|
||||||
if options.category:
|
if options.category:
|
||||||
@ -557,6 +607,7 @@ def main():
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
fields = LRFMetaFile.__dict__.items()
|
fields = LRFMetaFile.__dict__.items()
|
||||||
|
fields.sort()
|
||||||
for f in fields:
|
for f in fields:
|
||||||
if "XML" in str(f):
|
if "XML" in str(f):
|
||||||
print str(f[1]) + ":", lrf.__getattribute__(f[0]).encode('utf-8')
|
print str(f[1]) + ":", lrf.__getattribute__(f[0]).encode('utf-8')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user