This commit is contained in:
Kovid Goyal 2010-02-22 09:36:55 -07:00
commit 8030cff498
4 changed files with 39 additions and 47 deletions

View File

@ -311,9 +311,10 @@ class MetadataUpdater(object):
return StreamSlicer(self.stream, start, stop) return StreamSlicer(self.stream, start, stop)
def update(self, mi): def update(self, mi):
def pop_exth_record(exth_id): def update_exth_record(rec):
if exth_id in self.original_exth_records: recs.append(rec)
self.original_exth_records.pop(exth_id) if rec[0] in self.original_exth_records:
self.original_exth_records.pop(rec[0])
if self.type != "BOOKMOBI": if self.type != "BOOKMOBI":
raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n" raise MobiError("Setting metadata only supported for MOBI files of type 'BOOK'.\n"
@ -328,50 +329,36 @@ class MetadataUpdater(object):
pas = False pas = False
if mi.author_sort and pas: if mi.author_sort and pas:
authors = mi.author_sort authors = mi.author_sort
recs.append((100, authors.encode(self.codec, 'replace'))) update_exth_record((100, authors.encode(self.codec, 'replace')))
pop_exth_record(100)
elif mi.authors: elif mi.authors:
authors = '; '.join(mi.authors) authors = '; '.join(mi.authors)
recs.append((100, authors.encode(self.codec, 'replace'))) update_exth_record((100, authors.encode(self.codec, 'replace')))
pop_exth_record(100)
if mi.publisher: if mi.publisher:
recs.append((101, mi.publisher.encode(self.codec, 'replace'))) update_exth_record((101, mi.publisher.encode(self.codec, 'replace')))
pop_exth_record(101)
if mi.comments: if mi.comments:
recs.append((103, mi.comments.encode(self.codec, 'replace'))) update_exth_record((103, mi.comments.encode(self.codec, 'replace')))
pop_exth_record(103)
if mi.isbn: if mi.isbn:
recs.append((104, mi.isbn.encode(self.codec, 'replace'))) update_exth_record((104, mi.isbn.encode(self.codec, 'replace')))
pop_exth_record(104)
if mi.tags: if mi.tags:
subjects = '; '.join(mi.tags) subjects = '; '.join(mi.tags)
recs.append((105, subjects.encode(self.codec, 'replace'))) update_exth_record((105, subjects.encode(self.codec, 'replace')))
pop_exth_record(105)
if mi.pubdate: if mi.pubdate:
recs.append((106, str(mi.pubdate).encode(self.codec, 'replace'))) update_exth_record((106, str(mi.pubdate).encode(self.codec, 'replace')))
pop_exth_record(106)
elif mi.timestamp: elif mi.timestamp:
recs.append((106, str(mi.timestamp).encode(self.codec, 'replace'))) update_exth_record((106, str(mi.timestamp).encode(self.codec, 'replace')))
pop_exth_record(106)
elif self.timestamp: elif self.timestamp:
recs.append((106, self.timestamp)) update_exth_record((106, self.timestamp))
pop_exth_record(106)
else: else:
recs.append((106, nowf().isoformat().encode(self.codec, 'replace'))) update_exth_record((106, nowf().isoformat().encode(self.codec, 'replace')))
pop_exth_record(106)
if self.cover_record is not None: if self.cover_record is not None:
recs.append((201, pack('>I', self.cover_rindex))) update_exth_record((201, pack('>I', self.cover_rindex)))
recs.append((203, pack('>I', 0))) update_exth_record((203, pack('>I', 0)))
pop_exth_record(201)
pop_exth_record(203)
if self.thumbnail_record is not None: if self.thumbnail_record is not None:
recs.append((202, pack('>I', self.thumbnail_rindex))) update_exth_record((202, pack('>I', self.thumbnail_rindex)))
pop_exth_record(202) if 503 in self.original_exth_records:
if mi.title is not None: update_exth_record((503, mi.title.encode(self.codec, 'replace')))
recs.append((503, mi.title.encode(self.codec, 'replace')))
pop_exth_record(503)
# Restore any original EXTH fields that weren't updated # Include remaining original EXTH fields
for id in sorted(self.original_exth_records): for id in sorted(self.original_exth_records):
recs.append((id, self.original_exth_records[id])) recs.append((id, self.original_exth_records[id]))
recs = sorted(recs, key=lambda x:(x[0],x[0])) recs = sorted(recs, key=lambda x:(x[0],x[0]))

View File

@ -250,7 +250,8 @@ def generate_catalog(parent, dbspec, ids, device):
# Profile the connected device # Profile the connected device
# Parallel initialization in calibre.library.cli:command_catalog() # Parallel initialization in calibre.library.cli:command_catalog()
connected_device = { 'storage':None,'serial':None,'name':None} connected_device = { 'storage':None,'serial':None,'save_template':None,'name':None}
if device: if device:
try: try:
storage = [] storage = []
@ -260,9 +261,10 @@ def generate_catalog(parent, dbspec, ids, device):
storage.append(os.path.join(device._card_a_prefix, device.EBOOK_DIR_CARD_A)) storage.append(os.path.join(device._card_a_prefix, device.EBOOK_DIR_CARD_A))
if device._card_b_prefix: if device._card_b_prefix:
storage.append(os.path.join(device._card_b_prefix, device.EBOOK_DIR_CARD_B)) storage.append(os.path.join(device._card_b_prefix, device.EBOOK_DIR_CARD_B))
connected_device = {'storage': storage, connected_device = { 'storage': storage,
'serial': device.detected_device.serial if \ 'serial': device.detected_device.serial if \
hasattr(device.detected_device,'serial') else None, hasattr(device.detected_device,'serial') else None,
'save_template': device.save_template(),
'name': device.gui_name} 'name': device.gui_name}
except: except:
pass pass

View File

@ -3448,6 +3448,10 @@ class EPUB_MOBI(CatalogPlugin):
build_log = [] build_log = []
build_log.append(u"%s(): Generating %s %sin %s environment" %
(self.name,self.fmt,'for %s ' % opts.output_profile if opts.output_profile else '',
'CLI' if opts.cli_environment else 'GUI'))
# If exclude_genre is blank, assume user wants all genre tags included # If exclude_genre is blank, assume user wants all genre tags included
if opts.exclude_genre.strip() == '': if opts.exclude_genre.strip() == '':
opts.exclude_genre = '\[^.\]' opts.exclude_genre = '\[^.\]'
@ -3459,18 +3463,17 @@ class EPUB_MOBI(CatalogPlugin):
(opts.connected_device['name'], (opts.connected_device['name'],
opts.connected_device['serial'][0:4], opts.connected_device['serial'][0:4],
'x' * (len(opts.connected_device['serial']) - 4))) 'x' * (len(opts.connected_device['serial']) - 4)))
build_log.append(" save_template: '%s'" % opts.connected_device['save_template'])
else: else:
build_log.append(" connected_device: '%s'" % opts.connected_device['name']) build_log.append(" connected_device: '%s'" % opts.connected_device['name'])
for storage in opts.connected_device['storage']: for storage in opts.connected_device['storage']:
if storage: if storage:
build_log.append(" mount point: %s" % storage) build_log.append(" mount point: %s" % storage)
build_log.append(" save_template: '%s'" % opts.connected_device['save_template'])
opts_dict = vars(opts) opts_dict = vars(opts)
build_log.append(u"%s(): Generating %s %sin %s environment" %
(self.name,self.fmt,'for %s ' % opts.output_profile if opts.output_profile else '',
'CLI' if opts.cli_environment else 'GUI'))
if opts_dict['ids']: if opts_dict['ids']:
build_log.append(" Book count: %d" % len(opts_dict['ids'])) build_log.append(" book count: %d" % len(opts_dict['ids']))
sections_list = ['Descriptions','Authors'] sections_list = ['Descriptions','Authors']
if opts.generate_titles: if opts.generate_titles:
@ -3479,7 +3482,7 @@ class EPUB_MOBI(CatalogPlugin):
sections_list.append('Recently Added') sections_list.append('Recently Added')
if not opts.exclude_genre.strip() == '.': if not opts.exclude_genre.strip() == '.':
sections_list.append('Genres') sections_list.append('Genres')
build_log.append(u"Creating Sections for %s" % ', '.join(sections_list)) build_log.append(u" Sections: %s" % ', '.join(sections_list))
# Display opts # Display opts
keys = opts_dict.keys() keys = opts_dict.keys()
@ -3499,16 +3502,16 @@ class EPUB_MOBI(CatalogPlugin):
# Launch the Catalog builder # Launch the Catalog builder
catalog = self.CatalogBuilder(db, opts, self, report_progress=notification) catalog = self.CatalogBuilder(db, opts, self, report_progress=notification)
if opts.verbose: if opts.verbose:
log.info("Begin catalog source generation") log.info(" Begin catalog source generation")
catalog.createDirectoryStructure() catalog.createDirectoryStructure()
catalog.copyResources() catalog.copyResources()
catalog.calculateThumbnailSize() catalog.calculateThumbnailSize()
catalog_source_built = catalog.buildSources() catalog_source_built = catalog.buildSources()
if opts.verbose: if opts.verbose:
if catalog_source_built: if catalog_source_built:
log.info("Finished catalog source generation\n") log.info(" Finished catalog source generation\n")
else: else:
log.warn("No database hits with supplied criteria") log.warn(" No database hits with supplied criteria")
if catalog_source_built: if catalog_source_built:
recommendations = [] recommendations = []

View File

@ -683,7 +683,7 @@ def command_catalog(args, dbpath):
# No support for connected device in CLI environment # No support for connected device in CLI environment
# Parallel initialization in calibre.gui2.tools:generate_catalog() # Parallel initialization in calibre.gui2.tools:generate_catalog()
opts.connected_device = {'storage':None,'serial':None,'name':None} opts.connected_device = { 'storage':None,'serial':None,'save_template':None,'name':None}
with plugin: with plugin:
plugin.run(args[1], opts, get_db(dbpath, opts)) plugin.run(args[1], opts, get_db(dbpath, opts))