My thanks to KevinH and DiapDealer for your suggestions.
In reply to KevinH's points:
1. The only way for a plugin to get access to a file inside of Sigil is via the plugin interface calls. Please make sure you are using those as demonstrated in the sample plugins
I have read the Sigil Plugin guide thoroughly and I think know how to use the Plugin Manager interface. I'm pretty sure that I've been using it correctly. After all, I must be use using it correctly if I say that the bs4 version is working in the plugin but the sigil_bs4 version isn't working.
2. Make sure your plugin run() method is properly returning success upon completion (0) otherwise any changes made by your code will be aborted inside of Sigil (it will look like nothing happened).
My plugin always returns success and does a complete conversion whether I use bs4(which works) or sigil_bs4(which always fails to remove the attributes in the html). This is the weird part. And this is why it has been so hard for me to track down and solve this problem.
3. Make sure if any exceptions happen they are caught properly and run() returns properly (see point 2 above).
In the plugin the run() function always runs to completion with success whether I use bs4 or sigil_bs4(this is very strange for sure). At DiapDealers and your suggestion, I will also put try/except around everything and see what happens.
I will also send you the plugin files soon as the plugin zip file, which was a very generous suggestion on your part because I know that you are a busy guy.
In reply to DiapDealer's points:
The Plugin Framework's bk.readfile(), bk.writefile(), bk.addfile() helper functions should be used to read/modify/add-to an epub's content whenever possible.
In my plugin.py I don't use any of the above bk methods except for bk.getPrefs, bk.savePrefs, and bk.addotherfile(). My plugin is an input plugin that converts OpenDoc html directly to epub(a full conversion - preserves all layout and formatting on conversion to epub). The plugin is based around my own convert2Epub() function which I originally wrote and lifted from a much larger python windowing app of mine which works without problems(using bs4). Consequently, the convert2Epub() function does all file read/writes etc using the normal python interface functions ie the python code was working and already there in the function when I ported it so I left it as it was. The convert2Epub() function also works fine in the plugin.
Offhand (without seeing all the code in question), I'm guessing the difference between a successful run using external Python and an unsuccessful one using the bundled Python is an attempt to write a file to a "current working directory" that's privileged under the latter, but not the former.
But that's the weird part -- whether I run bs4(which is always successful) or sigil_bs4(which always fails to remove the attributes0 in the plugin -- the plugin always runs successfully with no errors. But I think your suggestion to put try/except around everything is well worth a try. Will get back to you on that one after I've tried it.
I also use mkdtemp() to create my plugin temp work directory -- not in plugin.py but in my convert2Epub() function because it was already there in the function when I ported it to the plugin.
Just to also say that the plugin appears to be working fine except for the sigil_bs4 problem. Hence all my frustration.
Kevinh...I think the easiest way is just for me to send you the plugin, as a zip file via email if that's OK. It should work when you install it in Sigil and run it. I've only tested it on Windows 7, 8 and 10. There is also a helpful a readme file inside the plugin as well.
|