Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 11-15-2016, 02:57 AM   #1
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
Problems using sigil_bs4 and gumbo_bs4.parse

(Moved from the Sigil user forum, with apologies)

I'm currently trying to write an html conversion plugin for Sigil which runs on python 3.4 (external) or Sigil's bundled python 3.5+(internal). As part of the html sanitizing process I currently use bs4 with python 3.4 and this works fine.

But when I use sigil_bs4 or gumbo_bs4.parse from the bundled python I do not get the same results as using bs4 -- because it simply doesn't work. Here is the code:

When I use this code with bs4 on my python 3.4 it works fine:

Code:
from bs4 import BeautifulSoup as bs

    html = open(file, 'rt', encoding='utf-8').read()
    soup = bs(html, 'html.parser')
    
    for tag in soup():
        for attribute in ["lang", "id", "dir", "name" "link"]:
            del tag[attribute]
But when I write this code using sigil_bs4 or gumbo_bs4.parse with the bundled python(3.5+) swtiched on it doesn't do the job and also doesn't give any specific errors.

Code:
from sigil_bs4 import BeautifulSoup as bs
(or import sigil_gumbo_bs4_adapter as gumbo_bs4)

    html = open(file, 'rt', encoding='utf-8').read()
    soup = bs(html, 'html.parser')
    (or soup = gumbo_bs4.parse(html))

    for tag in soup():
        for attribute in ["lang", "id", "dir", "name" "link"]:
            del tag[attribute]
I'm using Sigil 0.9.7 on Windows 8.

It seems that neither sigil_bs4 nor gumbo_bs4.parse produce a callable BS object(taking no arguments and returning a list of all html tags) which is what I need for the above code to work. I've also used sigil_bs4 quite successfully throughout my plugin as a line by line parser for other formatting(but not as a callable object as above).

Any further suggestions to make this code work for sigil_bs4 or gumbo_bs4.parse would be greatly appreciated.

This is my first python plugin(or major python app of any note).

Last edited by slowsmile; 11-15-2016 at 03:11 AM.
slowsmile is offline   Reply With Quote
Old 11-15-2016, 04:15 AM   #2
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
I wasn't able to reproduce your problem with on my 64bit Windows 10 machine.

I used the following edit plugin code:

Spoiler:
Code:
#!/usr/bin/env python
import sys

try:
    from sigil_bs4 import BeautifulSoup
    print('Sigil bs4 imported')
except:
    from bs4 import BeautifulSoup
    print('regular bs4 imported')

def run(bk):
    print('Launcher version: ', bk.launcher_version())
    print('Python version: ', sys.version, '\n')
    html = bk.readfile('Section0001.xhtml')
    soup = BeautifulSoup(html, 'html.parser')
    
    for tag in soup():
        for attribute in ["lang", "id", "dir", "name" "link"]:
            del tag[attribute]
        
    print(str(soup))
    
    return 0

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

if __name__ == "__main__":
    sys.exit(main())


with this Section0001.xhtml file:

Spoiler:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
</head>

<body lang="en">
  <p id="test">Lorem ipsum</p>
</body>
</html>


The output was:

Spoiler:
Code:
Status: success

Sigil bs4 imported
Launcher version:  20160909
Python version:  3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p>Lorem ipsum</p>
</body>
</html>


BTW, you should be able to import sigil_bs4 even if you use an external interpreter. If you disable Use Bundled Python, you should still get the following message:

Code:
Sigil bs4 imported
Doitsu is offline   Reply With Quote
Advert
Old 11-15-2016, 04:44 AM   #3
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
@Doitsu...A hearty thanks for your suggestions. I'll try them out and get back to you as soon as I can.

Just to also mention that I've used the bs4 code in a windowing app that I've written for converting html to epub. That worked without problems. I just ported the main html to epub converter function to the plugin and couldn't get it to work with sigil_bs4. Very frustrating.
slowsmile is offline   Reply With Quote
Old 11-15-2016, 05:47 AM   #4
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by slowsmile View Post
Just to also mention that I've used the bs4 code in a windowing app that I've written for converting html to epub. That worked without problems. I just ported the main html to epub converter function to the plugin and couldn't get it to work with sigil_bs4. Very frustrating.
There might be any number of reasons why your code doesn't work. However, it's really hard to tell what the problem is without seeing the code. Please post or attach it.

Also download the Plugin Framework Guide, install the test plugin and have a look at the plugin code written by KevinH and DiapDealer.
Doitsu is offline   Reply With Quote
Old 11-15-2016, 07:29 AM   #5
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
I've implemented your suggested changes and it didn't work. The problem is the same.

I have this code in a module that contains a worker function:

Code:
try:
    from sigil_bs4 import BeautifulSoup
    print('Sigil bs4 imported')
except:
    from bs4 import BeautifulSoup
    print('regular bs4 imported')


def fixHTML(wdir, file):    
    
    output = wdir + os.sep + 'new_html.htm'
    outfp = open(output, 'wt', encoding=('utf-8'))
    html = open(file, 'rt', encoding='utf-8').read()
    soup = BeautifulSoup(html)
    
    for tag in soup():
        for attribute in ["lang", "id", "dir", "name" "link"]:
            del tag[attribute]    
    |
    More code
    |
    outfp.writelines(str(soup))
    outfp.close()

    os.remove(file)
    os.rename(output, file)
    return(file)
If I set to bundled python in Plugin manager and then hit the OK key and run the plugin, it prints 'Sigil bs4 imported' and it fails. When I deselect the bundled python and set my on system python 3.4 then it prints 'regular bs4 imported' and the plugin successfully removes the attributes from the html file as it should.

My calling is like this:

run()
|
calls
|
convert2Epub --> calls --> fixHTML(contains the sigil_bs4 code above)

I've also already read The Sigil Plugin Framework Guide a while ago. It doesn't really tell you how to use the sigil_bs4 module, it just mentions it. I found out more useful info, including all the code, on FOSSIE and GitHub.

I think I'll try reinstalling Sigil 0.9.7 and see if I can get any joy there.
slowsmile is offline   Reply With Quote
Advert
Old 11-15-2016, 07:34 AM   #6
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by slowsmile View Post
If I set to bundled python in Plugin manager and then hit the OK key and run the plugin, it prints 'Sigil bs4 imported' and it fails.
Two questions:

1. Did my sample plugin work on your machine?
2. What's the exact error message that you got?
Doitsu is offline   Reply With Quote
Old 11-15-2016, 07:53 AM   #7
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
That's the weird thing. I implemented your import code into the plugin as shown above. And when I used sigil_bs4 it did not remove the attributes and gave no error message at all. But when I checked the html afterwards -- all the attributes that should have been removed were still there.

I'm afraid that your sample code and suggestions didn't work.

Also, I've reinstalled Sigil and re-tested the plugin and the problem still remains the same. I'm somewhat stumped by this one. I'm now pretty convinced that sigil_bs4 does not have the same capabilities or behaviour as the bs4 version. Perhaps KevinH or DiapDealer might be able to confirm this.

Don't forget that I'm using the BeautifulSoup call like this:

for tag in soup():
for attribute in ["lang", "id", "dir", "name" "link"]:
del tag[attribute]

I'm not using any methods at all from the soup object in this initial call -- I'm calling the object directly like a function in my code. So here's my question:

Does the sigil_bs4 version allow direct object calls, without any arguments, or not ?

I know that you can use the original bs4 version with a no-argument object call because my code works with bs4. But it doesn't work with sigil_bs4. That's really why I need an answer to the above question.

Last edited by slowsmile; 11-15-2016 at 08:15 AM.
slowsmile is offline   Reply With Quote
Old 11-15-2016, 08:15 AM   #8
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by slowsmile View Post
That's the weird thing. I implemented your import code into the plugin as shown above.
Don't just test the import lines, create a new edit plugin in a bs4test folder with the following plugin.xml code.

Spoiler:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<name>bs4test</name>
<type>edit</type>
<author>Doitsu</author>
<autostart>true</autostart>
<description>bs4test</description>
<engine>python3.4</engine>
<version>0.1</version>
<oslist>unx,win,osx</oslist>
</plugin>


and the plugin.py code that I already posted. Then create a epub2 book, add some attributes to tags in Section0001.xhtml and run the test plugin with Used Bundled Python enabled and disabled.
You should get the same results, except for the different Python version numbers.

Do you use a portable version of Sigil by any chance? If so install the regular version.
Doitsu is offline   Reply With Quote
Old 11-15-2016, 08:24 AM   #9
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
I've already done what you have suggested. I must've run the plugin about 10 times already checking it. I've tested it with and without bundled python. It still isn't working when I run the plugin with the sigil_bs4 version but works fine with the bs4 version. It's all in my posts above.

My Sigil version is the full Win64 version.

Do you have an answer to my question?

Does the sigil_bs4 version allow direct object calls, without any arguments, or not ?
slowsmile is offline   Reply With Quote
Old 11-15-2016, 09:22 AM   #10
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: 27,550
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
The modifications to the stock bs4 are documented in the sigil_custom_changes_to_bs4-4.4.0.patch.txt file in the sigil_bs4 folder in the plugin_launchers/python directory. Should be able to ge found in Sigil's Program Files directory after installation (or the Resource_Files directory in Sigil's source).

To my knowledge, the changes are minimal and should not be causing your issue.

You're positive the testplugin gives your installation a clean bill of heath RE sigil_bs4 and gumbo (with the Use Bundled Python option checked)?
DiapDealer is offline   Reply With Quote
Old 11-15-2016, 09:59 AM   #11
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
A few things ...

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

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).

3. Make sure if any exceptions happen they are caught properly and run() returns properly
(see point 2 above).

4. Please understand, you are not working directly with files inside of Sigil or the epub. You are interfacing using a copy on change style model where the changed copies are not updated inside Sigil until the plugin has returned successfully with a return code of 0 and the new files are all parseable.

Hope this helps, if not you can privately post your plugin code someplace and pm me (KevinH) or DiapDealer with the link and I would be happy to track down and fix any issues in your code or ours when I get home from work tonight.

KevinH
KevinH is offline   Reply With Quote
Old 11-15-2016, 10:11 AM   #12
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
ps, to answer your question, the soup object should work as advertized in sigil_bs4. The changes we make actually fix a few namespace bugs, and add xhtml specific interface routines to the soup object to convert a bs4 tree back to xml and or xhtml.

So no, unless there is a name/namespace clash somehow, Doitsu's code should work.

But please note Doitsu's test plugin (at least the code shown in the second post) will not actually change the file inside Sigil since his demonstration plugin does not save the changes back it just prints them to the screen (there is no bk.writefile call). BTW, the readfile() call needs the manifest id which in this case just happens to be the same as the file name.

Hope something here helps,

KevinH
KevinH is offline   Reply With Quote
Old 11-15-2016, 11:56 AM   #13
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: 27,550
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Also ... unless you're writing an Input/Output plugin (or your Edit plugin needs to access external files), there's probably no need for the manual reading and writing of files using Python's native FileIO that your code seems to be using. 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.

Perhaps if you could share the general workflow of your proposed plugin, some tips could be given about how best to accomplish it via the existing Framework.

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. One thing's for sure: something is silently failing when run with the bundled Python. The best way to track it down is to use Try/Except clauses around literally everything, to print out debugging messages all along the way. Sooner or later, you'll find the code that's quietly dying when encountered in the plugin.

Last edited by DiapDealer; 11-15-2016 at 12:11 PM.
DiapDealer is offline   Reply With Quote
Old 11-15-2016, 06:34 PM   #14
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
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.
slowsmile is offline   Reply With Quote
Old 11-15-2016, 06:42 PM   #15
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
I will pm you my home e-mail address as I do not want to post it for email harvesters to grab.

Take care,

KevinH
KevinH is offline   Reply With Quote
Reply

Tags
sigil, sigil_bs4, sigil_gumbo_bs4_adapter


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with RegEx to parse title with colon racergirl76 Library Management 3 02-16-2016 02:13 AM
Use parse_index to parse XML? surf Recipes 0 02-10-2013 04:36 AM
Seriously, how to parse metadata from filenames charlweed Calibre 7 07-18-2011 01:58 PM
Initial parse failed: mburgoa Calibre 4 08-07-2010 08:50 AM


All times are GMT -4. The time now is 08:32 AM.


MobileRead.com is a privately owned, operated and funded community.