Quote:
Originally Posted by KevinH
No, book href is correct for deleteotherfile. It would be incorrect for deletefile.
|
You may want to double-check this one. If I use your improved code,
Code:
#!/usr/bin/env python
import os, inspect, uuid
def run(bk):
SCRIPT_DIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
binary_file = 'WallauRundgotisch-Heavy.ttf'
binary_path = os.path.join(SCRIPT_DIR, binary_file)
data = ''
with open(binary_path, 'rb') as f:
data = f.read()
uniqueid = 'id' + str(uuid.uuid4())[24:82]
bk.addfile(uniqueid, binary_file, data, 'application/x-font-ttf')
return 0
def main():
print('I reached main when I should not have\n')
return -1
if __name__ == "__main__":
sys.exit(main())
a font file with the href
Fonts/WallauRundgotisch-Heavy.ttf will be added.
However, if I subsequently, comment out the last line of the code, replace it with a bk.deleteotherfile() statement and use the above href as the parameter:
Code:
#bk.addfile(uniqueid, binary_file, data, 'application/x-font-ttf')
bk.deleteotherfile('Fonts/WallauRundgotisch-Heavy.ttf')
I'm getting the following error message:
Code:
Traceback (most recent call last):
File "/usr/local/share/sigil/plugin_launchers//python/launcher.py", line 137, in launch
self.exitcode = target_script.run(container)
File "/home/user/.local/share/sigil-ebook/sigil/plugins/test/plugin.py", line 13, in run
bk.deleteotherfile('Fonts/WallauRundgotisch-Heavy.ttf')
File "/usr/local/share/sigil/plugin_launchers/python/bookcontainer.py", line 143, in deleteotherfile
self._w.deleteotherfile(book_href)
File "/usr/local/share/sigil/plugin_launchers/python/wrapper.py", line 565, in deleteotherfile
del self.id_to_filepath[id]
KeyError: u'Fonts/WallauRundgotisch-Heavy.ttf'
Error: u'Fonts/WallauRundgotisch-Heavy.ttf'
However, if I use the id instead of the href, I get no error message and the file is deleted both from the fonts folder and the manifest (but not from the actual epub file.)
D.