Quote:
Originally Posted by Doitsu
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()