mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1757 (Metadata fields not editable)
This commit is contained in:
parent
92c17d2d58
commit
73b87c713d
@ -456,10 +456,7 @@ def convert(htmlfile, opts, notification=None, create_epub=True,
|
|||||||
if os.path.exists(cpath):
|
if os.path.exists(cpath):
|
||||||
opf.add_path_to_manifest(cpath, 'image/jpeg')
|
opf.add_path_to_manifest(cpath, 'image/jpeg')
|
||||||
with open(opf_path, 'wb') as f:
|
with open(opf_path, 'wb') as f:
|
||||||
raw = opf.render()
|
f.write(opf.render())
|
||||||
if not raw.startswith('<?xml '):
|
|
||||||
raw = '<?xml version="1.0" encoding="UTF-8"?>\n'+raw
|
|
||||||
f.write(raw)
|
|
||||||
ncx_path = os.path.join(os.path.dirname(opf_path), 'toc.ncx')
|
ncx_path = os.path.join(os.path.dirname(opf_path), 'toc.ncx')
|
||||||
if os.path.exists(ncx_path) and os.stat(ncx_path).st_size > opts.profile.flow_size:
|
if os.path.exists(ncx_path) and os.stat(ncx_path).st_size > opts.profile.flow_size:
|
||||||
logger.info('Condensing NCX from %d bytes...'%os.stat(ncx_path).st_size)
|
logger.info('Condensing NCX from %d bytes...'%os.stat(ncx_path).st_size)
|
||||||
@ -475,7 +472,7 @@ def convert(htmlfile, opts, notification=None, create_epub=True,
|
|||||||
logger.info(_('Output written to ')+opts.output)
|
logger.info(_('Output written to ')+opts.output)
|
||||||
|
|
||||||
if opts.show_opf:
|
if opts.show_opf:
|
||||||
print open(os.path.join(tdir, 'metadata.opf')).read()
|
print open(opf_path, 'rb').read()
|
||||||
|
|
||||||
if opts.extract_to is not None:
|
if opts.extract_to is not None:
|
||||||
if os.path.exists(opts.extract_to):
|
if os.path.exists(opts.extract_to):
|
||||||
|
@ -1007,7 +1007,6 @@ def merge_metadata(htmlfile, opf, opts):
|
|||||||
mi = get_metadata(open(htmlfile, 'rb'), 'html')
|
mi = get_metadata(open(htmlfile, 'rb'), 'html')
|
||||||
except:
|
except:
|
||||||
mi = MetaInformation(None, None)
|
mi = MetaInformation(None, None)
|
||||||
|
|
||||||
if opts.from_opf is not None and os.access(opts.from_opf, os.R_OK):
|
if opts.from_opf is not None and os.access(opts.from_opf, os.R_OK):
|
||||||
mi.smart_update(OPF(open(opts.from_opf, 'rb'), os.path.abspath(os.path.dirname(opts.from_opf))))
|
mi.smart_update(OPF(open(opts.from_opf, 'rb'), os.path.abspath(os.path.dirname(opts.from_opf))))
|
||||||
for attr in ('title', 'authors', 'publisher', 'tags', 'comments'):
|
for attr in ('title', 'authors', 'publisher', 'tags', 'comments'):
|
||||||
|
@ -247,6 +247,12 @@ class MetaInformation(object):
|
|||||||
if getattr(mi, 'cover_data', None) and mi.cover_data[0] is not None:
|
if getattr(mi, 'cover_data', None) and mi.cover_data[0] is not None:
|
||||||
self.cover_data = mi.cover_data
|
self.cover_data = mi.cover_data
|
||||||
|
|
||||||
|
def format_series_index(self):
|
||||||
|
try:
|
||||||
|
x = float(self.series_index)
|
||||||
|
except ValueError:
|
||||||
|
x = 1.0
|
||||||
|
return '%d'%x if int(x) == x else '%.2f'%x
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
ans = u''
|
ans = u''
|
||||||
@ -267,7 +273,7 @@ class MetaInformation(object):
|
|||||||
if self.tags:
|
if self.tags:
|
||||||
ans += u'Tags : ' + u', '.join([unicode(t) for t in self.tags]) + '\n'
|
ans += u'Tags : ' + u', '.join([unicode(t) for t in self.tags]) + '\n'
|
||||||
if self.series:
|
if self.series:
|
||||||
ans += u'Series : '+unicode(self.series) + ' #%d\n'%self.series_index
|
ans += u'Series : '+unicode(self.series) + ' #%s\n'%self.format_series_index()
|
||||||
if self.language:
|
if self.language:
|
||||||
ans += u'Language : ' + unicode(self.language) + u'\n'
|
ans += u'Language : ' + unicode(self.language) + u'\n'
|
||||||
return ans.strip()
|
return ans.strip()
|
||||||
@ -277,11 +283,11 @@ class MetaInformation(object):
|
|||||||
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
|
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
|
||||||
ans += [(_('Publisher'), unicode(self.publisher))]
|
ans += [(_('Publisher'), unicode(self.publisher))]
|
||||||
ans += [(_('Producer'), unicode(self.book_producer))]
|
ans += [(_('Producer'), unicode(self.book_producer))]
|
||||||
ans += [(_('Category'), unicode(self.category))]
|
|
||||||
ans += [(_('Comments'), unicode(self.comments))]
|
ans += [(_('Comments'), unicode(self.comments))]
|
||||||
ans += [('ISBN', unicode(self.isbn))]
|
ans += [('ISBN', unicode(self.isbn))]
|
||||||
ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))]
|
ans += [(_('Tags'), u', '.join([unicode(t) for t in self.tags]))]
|
||||||
ans += [(_('Series'), unicode(self.series))]
|
if self.series:
|
||||||
|
ans += [(_('Series'), unicode(self.series))+ ' #%s'%self.format_series_index()]
|
||||||
ans += [(_('Language'), unicode(self.language))]
|
ans += [(_('Language'), unicode(self.language))]
|
||||||
for i, x in enumerate(ans):
|
for i, x in enumerate(ans):
|
||||||
ans[i] = u'<tr><td><b>%s</b></td><td>%s</td></tr>'%x
|
ans[i] = u'<tr><td><b>%s</b></td><td>%s</td></tr>'%x
|
||||||
|
@ -789,7 +789,10 @@ class OPF(object):
|
|||||||
return elem
|
return elem
|
||||||
|
|
||||||
def render(self, encoding='utf-8'):
|
def render(self, encoding='utf-8'):
|
||||||
return etree.tostring(self.root, encoding='utf-8', pretty_print=True)
|
raw = etree.tostring(self.root, encoding=encoding, pretty_print=True)
|
||||||
|
if not raw.lstrip().startswith('<?xml '):
|
||||||
|
raw = '<?xml version="1.0" encoding="%s"?>\n'%encoding.upper()+raw
|
||||||
|
return raw
|
||||||
|
|
||||||
def smart_update(self, mi):
|
def smart_update(self, mi):
|
||||||
for attr in ('author_sort', 'title_sort', 'comments', 'category',
|
for attr in ('author_sort', 'title_sort', 'comments', 'category',
|
||||||
@ -877,7 +880,8 @@ class OPFCreator(MetaInformation):
|
|||||||
self.guide = Guide.from_opf_guide(guide_element, self.base_path)
|
self.guide = Guide.from_opf_guide(guide_element, self.base_path)
|
||||||
self.guide.set_basedir(self.base_path)
|
self.guide.set_basedir(self.base_path)
|
||||||
|
|
||||||
def render(self, opf_stream, ncx_stream=None, ncx_manifest_entry=None):
|
def render(self, opf_stream=sys.stdout, ncx_stream=None,
|
||||||
|
ncx_manifest_entry=None):
|
||||||
from calibre.resources import opf_template
|
from calibre.resources import opf_template
|
||||||
from calibre.utils.genshi.template import MarkupTemplate
|
from calibre.utils.genshi.template import MarkupTemplate
|
||||||
template = MarkupTemplate(opf_template)
|
template = MarkupTemplate(opf_template)
|
||||||
|
@ -18,7 +18,7 @@ from calibre.gui2 import error_dialog, choose_images, pixmap_to_data, ResizableD
|
|||||||
from calibre.ebooks.epub.from_any import SOURCE_FORMATS, config as epubconfig
|
from calibre.ebooks.epub.from_any import SOURCE_FORMATS, config as epubconfig
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ptempfile import PersistentTemporaryFile
|
from calibre.ptempfile import PersistentTemporaryFile
|
||||||
from calibre.ebooks.metadata.opf import OPFCreator
|
from calibre.ebooks.metadata.opf2 import OPFCreator
|
||||||
from calibre.ebooks.metadata import authors_to_string, string_to_authors
|
from calibre.ebooks.metadata import authors_to_string, string_to_authors
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user