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
@ -454,12 +454,9 @@ def convert(htmlfile, opts, notification=None, create_epub=True,
|
||||
|
||||
cpath = os.path.join(tdir, 'content', 'resources', '_cover_.jpg')
|
||||
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:
|
||||
raw = opf.render()
|
||||
if not raw.startswith('<?xml '):
|
||||
raw = '<?xml version="1.0" encoding="UTF-8"?>\n'+raw
|
||||
f.write(raw)
|
||||
f.write(opf.render())
|
||||
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:
|
||||
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)
|
||||
|
||||
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 os.path.exists(opts.extract_to):
|
||||
|
@ -1007,7 +1007,6 @@ def merge_metadata(htmlfile, opf, opts):
|
||||
mi = get_metadata(open(htmlfile, 'rb'), 'html')
|
||||
except:
|
||||
mi = MetaInformation(None, None)
|
||||
|
||||
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))))
|
||||
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:
|
||||
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):
|
||||
ans = u''
|
||||
@ -267,7 +273,7 @@ class MetaInformation(object):
|
||||
if self.tags:
|
||||
ans += u'Tags : ' + u', '.join([unicode(t) for t in self.tags]) + '\n'
|
||||
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:
|
||||
ans += u'Language : ' + unicode(self.language) + u'\n'
|
||||
return ans.strip()
|
||||
@ -277,11 +283,11 @@ class MetaInformation(object):
|
||||
ans += [(_('Author(s)'), (authors_to_string(self.authors) if self.authors else _('Unknown')))]
|
||||
ans += [(_('Publisher'), unicode(self.publisher))]
|
||||
ans += [(_('Producer'), unicode(self.book_producer))]
|
||||
ans += [(_('Category'), unicode(self.category))]
|
||||
ans += [(_('Comments'), unicode(self.comments))]
|
||||
ans += [('ISBN', unicode(self.isbn))]
|
||||
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))]
|
||||
for i, x in enumerate(ans):
|
||||
ans[i] = u'<tr><td><b>%s</b></td><td>%s</td></tr>'%x
|
||||
|
@ -789,7 +789,10 @@ class OPF(object):
|
||||
return elem
|
||||
|
||||
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):
|
||||
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.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.utils.genshi.template import MarkupTemplate
|
||||
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.metadata import MetaInformation
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user