@Becky...
Quote:
Again me: Validate OPF and offset.
I found the issue that bothered me.
bk.get_opf() -- is not perfect.
Why?
Result of bk.get_opf() is not current state of file .opf. This is state "what will the .opf file look like after saving" + missing two spaces before <metadata and </metadata> + missing four spaces before each <dc:… and <meta ….
|
I'm not sure whether I've got your problem right but, as far as I'm concerned, what really matters when you use the bk.get_opf() method is
when you actually run it in your program. So if you've already changed epub files in the epub itself and then you run the get_opf() function then you will get errors because it also changes and updates epub files on the fly as someone has already said.
The way round this problem is just to create a separate work directory for all the files that your are going to change or update in the epub with your plugin code. Use the python
mkdtemp() method to create the work directly. In your plugin just save all your changed files to the work dir. The very last task for your plugin should be to write all new or changed files from your work dir to your epub.
If you use a work dir and, as your last plugin task, save all changed or new files back to the epub, then it won't matter how many times you run get_opf() in your plugin because all the epub files will still be in their original state because nothing has been saved or changed yet. So doing it this way should give you correct line numbers.
I remember, somewhere in the distant past, Kevin patiently explaining all this to me in an email and enlightening me in the way the container updates all files that you've changed with your plugin after end-of-run. The container processing runs in this this order: delete files, add files(adds new files), write files(write existing files back to the epub). Appreciating the container processing order and always using a temp work dir in my plugins has stood me in good stead because that's what really helped me to understand how I could safely use the get_opf() function in my IDErrorCheck plugin without any problems.