mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Implement dc:publisher
This commit is contained in:
parent
d6412787ab
commit
dca6c268ed
@ -547,6 +547,26 @@ def set_comments(root, prefixes, refines, val):
|
|||||||
m.append(c)
|
m.append(c)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# Publisher {{{
|
||||||
|
|
||||||
|
@simple_text
|
||||||
|
def read_publisher(root, prefixes, refines):
|
||||||
|
for dc in XPath('./opf:metadata/dc:publisher')(root):
|
||||||
|
if dc.text:
|
||||||
|
return dc.text
|
||||||
|
|
||||||
|
def set_publisher(root, prefixes, refines, val):
|
||||||
|
for dc in XPath('./opf:metadata/dc:publisher')(root):
|
||||||
|
remove_element(dc, refines)
|
||||||
|
m = XPath('./opf:metadata')(root)[0]
|
||||||
|
if val:
|
||||||
|
val = val.strip()
|
||||||
|
if val:
|
||||||
|
c = m.makeelement(DC('publisher'))
|
||||||
|
c.text = normalize_whitespace(val)
|
||||||
|
m.append(c)
|
||||||
|
# }}}
|
||||||
|
|
||||||
def read_metadata(root):
|
def read_metadata(root):
|
||||||
ans = Metadata(_('Unknown'), [_('Unknown')])
|
ans = Metadata(_('Unknown'), [_('Unknown')])
|
||||||
prefixes, refines = read_prefixes(root), read_refines(root)
|
prefixes, refines = read_prefixes(root), read_refines(root)
|
||||||
@ -579,6 +599,7 @@ def read_metadata(root):
|
|||||||
if not is_date_undefined(lm):
|
if not is_date_undefined(lm):
|
||||||
ans.last_modified = lm
|
ans.last_modified = lm
|
||||||
ans.comments = read_comments(root, prefixes, refines) or ans.comments
|
ans.comments = read_comments(root, prefixes, refines) or ans.comments
|
||||||
|
ans.publisher = read_publisher(root, prefixes, refines) or ans.publisher
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def get_metadata(stream):
|
def get_metadata(stream):
|
||||||
@ -598,6 +619,7 @@ def apply_metadata(root, mi, cover_prefix='', cover_data=None, apply_null=False,
|
|||||||
set_pubdate(root, prefixes, refines, mi.pubdate)
|
set_pubdate(root, prefixes, refines, mi.pubdate)
|
||||||
set_timestamp(root, prefixes, refines, mi.timestamp)
|
set_timestamp(root, prefixes, refines, mi.timestamp)
|
||||||
set_comments(root, prefixes, refines, mi.comments)
|
set_comments(root, prefixes, refines, mi.comments)
|
||||||
|
set_publisher(root, prefixes, refines, mi.publisher)
|
||||||
|
|
||||||
pretty_print_opf(root)
|
pretty_print_opf(root)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from calibre.ebooks.metadata.opf3 import (
|
|||||||
read_authors, Author, set_authors, ensure_prefix, read_prefixes,
|
read_authors, Author, set_authors, ensure_prefix, read_prefixes,
|
||||||
read_book_producers, set_book_producers, read_timestamp, set_timestamp,
|
read_book_producers, set_book_producers, read_timestamp, set_timestamp,
|
||||||
read_pubdate, set_pubdate, CALIBRE_PREFIX, read_last_modified, read_comments,
|
read_pubdate, set_pubdate, CALIBRE_PREFIX, read_last_modified, read_comments,
|
||||||
set_comments
|
set_comments, read_publisher, set_publisher
|
||||||
)
|
)
|
||||||
|
|
||||||
TEMPLATE = '''<package xmlns="http://www.idpf.org/2007/opf" version="3.0" prefix="calibre: %s" unique-identifier="uid"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">{metadata}</metadata></package>''' % CALIBRE_PREFIX # noqa
|
TEMPLATE = '''<package xmlns="http://www.idpf.org/2007/opf" version="3.0" prefix="calibre: %s" unique-identifier="uid"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">{metadata}</metadata></package>''' % CALIBRE_PREFIX # noqa
|
||||||
@ -181,6 +181,18 @@ class TestOPF3(unittest.TestCase):
|
|||||||
return rt(root)
|
return rt(root)
|
||||||
root = self.get_opf('''<dc:description><span>one</span></dc:description><dc:description> xxx</dc:description>''')
|
root = self.get_opf('''<dc:description><span>one</span></dc:description><dc:description> xxx</dc:description>''')
|
||||||
self.ae('<span>one</span>\nxxx', rt(root))
|
self.ae('<span>one</span>\nxxx', rt(root))
|
||||||
|
self.ae('<a>p</a>', st(root, '<a>p</a> '))
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
def test_publisher(self): # {{{
|
||||||
|
def rt(root):
|
||||||
|
return read_publisher(root, read_prefixes(root), read_refines(root))
|
||||||
|
def st(root, val):
|
||||||
|
set_publisher(root, read_prefixes(root), read_refines(root), val)
|
||||||
|
return rt(root)
|
||||||
|
root = self.get_opf('''<dc:publisher> one </dc:publisher><dc:publisher> xxx</dc:publisher>''')
|
||||||
|
self.ae('one', rt(root))
|
||||||
|
self.ae('<a>p</a>', st(root, '<a>p</a> '))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Run tests {{{
|
# Run tests {{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user