mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a convenience method to iterate over filenames of specific types
This commit is contained in:
parent
0a3c321d31
commit
3052ebd8a5
@ -618,6 +618,19 @@ class Container(ContainerBase): # {{{
|
||||
if q in props:
|
||||
yield self.href_to_name(item.get('href'), self.opf_name)
|
||||
|
||||
def manifest_items_of_type(self, predicate):
|
||||
''' The names of all manifest items whose media-type matches predicate.
|
||||
`predicate` can be a set, a list, a string or a function taking a single
|
||||
argument, which will be called with the media-type. '''
|
||||
if isinstance(predicate, type('')):
|
||||
predicate = predicate.__eq__
|
||||
elif hasattr(predicate, '__contains__'):
|
||||
predicate = predicate.__contains__
|
||||
for mt, names in self.manifest_type_map.iteritems():
|
||||
if predicate(mt):
|
||||
for name in names:
|
||||
yield name
|
||||
|
||||
@property
|
||||
def guide_type_map(self):
|
||||
' Mapping of guide type to canonical name '
|
||||
|
Loading…
x
Reference in New Issue
Block a user