View Single Post
Old 05-14-2015, 09:31 AM   #21
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,708
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Doitsu View Post
If I understand you correctly, there's no way to directly manipulate manifest entries or rewrite the manifest section only. The following code seems to work, but, IMHO, it'd be much easier if the Plugin Runner code allowed for direct manifest entry value changes.

Code:
#!/usr/bin/env python
 # -*- coding: utf-8 -*-
import os
 
def run(bk):

    # read manifest items
    for id in sorted(bk._w.id_to_mime):
        mime = bk._w.id_to_mime[id]
        href = bk._w.id_to_href[id]
            
        # check for invalid MIME types
        if href.endswith('tf') and mime not in ('application/x-font-ttf', 'application/vnd.ms-opentype') :
            data = bk.readfile(id)
            bk.deletefile(id)
            if href.endswith('ttf'):
                bk.addfile(id, os.path.basename(href), data, 'application/x-font-ttf')
            else:
                bk.addfile(id, os.path.basename(href), data, 'application/vnd.ms-opentype')
            print 'MIME type updated: ' + os.path.basename(href)

def main():
    print 'I reached main when I should not have\n'
    return -1

if __name__ == "__main__":
    sys.exit(main())
Not that it matters a lot in this instance/example, but you may just want to use the manifest_iter method of the bookcontainer (bk) class instead of calling the underlying wrapper methods and properties directly.

Code:
for id, href, mime in bk.manifest_iter()

Last edited by DiapDealer; 05-14-2015 at 09:58 AM.
DiapDealer is offline   Reply With Quote