MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   [Plugin] RemoveInLineStyles Plugin (https://www.mobileread.com/forums/showthread.php?t=274274)

KevinH 05-13-2021 12:06 PM

Okay, Please give RemoveInLineStyles_v030.zip a try. It is attached to the first post in this thread.

It requires at least Sigil-1.0 to work but should properly handle any epub layout.

Sarmat89 05-28-2021 06:45 PM

The new version doesn't seem to work:

Code:

Traceback (most recent call last):
  File "C:\Programs\Sigil\plugin_launchers\python\launcher.py", line 142, in launch
    self.exitcode = target_script.run(container)
  File "C:\Users\xxx\AppData\Local\sigil-ebook\sigil\plugins\RemoveInLineStyles\plugin.py", line 164, in run
    bk.addbookpath(css_new_filename, css_new_bookpath, cssdata, mime='text/css')
  File "C:\Programs\Sigil\plugin_launchers\python\bookcontainer.py", line 457, in addbookpath
    return self._w.addbookpath(uniqueid, bookpath, data, mime)
  File "C:\Programs\Sigil\plugin_launchers\python\wrapper.py", line 721, in addbookpath
    with open(filepath, 'wb') as fp:
PermissionError: [Errno 13] Permission denied: 'C:\\sgc_styles.css'


KevinH 05-28-2021 07:18 PM

It should fail given the path is outside the epub: 'C:\\sgc_styles.css'

Are you trying to create the css file outside the epub? Or is this some strange Windows path issue. It worked just fine on macOS when I tried it.

Hmmm...

Something is very strange.

KevinH 05-28-2021 07:34 PM

Please try adding an existing css file to your epub just temporarily.

What is its resulting book path (mouse over the added css file in BookBrowser to see its full book path).

Try then running the plugin. The plugin should put the file right beside the existing css file you added temporarily? Did it or does the plugin still generate an error?

If so move the temporarily added css file into a "Styles" folder and try the plugin once again.

What errors does it generate?

If you have an epub that you can generate the error with, would you please post it someplace private (unless it is public domain) and pm me (KevinH) here onMobileread with a private link so that I can try to reproduce what settings are causing the plugin to write something to your root directory instead of to your epub plugin output folder.

KevinH 05-28-2021 07:49 PM

By any chance is your epub an epub2 with no OEBPS folder and no existing stylesheets?

Sarmat89 05-28-2021 11:15 PM

It is added to the root folder. It is a flat EPUB3 file with existing stylesheets.

The generated stylesheet was successfully added after the existing stylesheets were moved into Styles subfolder.

KevinH 05-28-2021 11:23 PM

If it has existing stylesheets, are they all stored in the root of the epub? Or are some css stored in a different place?

The addbookpath routine literally prepends the path to the plugin working directory to the file path built from its book path. This simply can not be at the root level of the C drive. As the plugin's work directory is created in temp with a unique path.

I will create an epub3 that is flat with no organizing or grouping folders but with a existing css file at the root level of the epub to see if I can recreate what you are seeing.

Is there anything else unique about your test epub?

KevinH 05-28-2021 11:33 PM

Okay, I think I can see how no folder at all could cause an issue for my plugin code but not the exact one you are seeing. But perhaps it is related. So give me a day or two and I will post a revised v031 version for you to try. Hopefully it will prevent the issue you are seeing as well.

Sarmat89 05-30-2021 07:29 PM

That can happen if you append an absolute path starting with \ or /.

KevinH 05-30-2021 08:19 PM

But I prepend a outdir to it. Would you feel comfortable hand editing the plugin.py in a text editor and trying to see if this fixes the issue. If so, here is what I would like you to try if possible:

Near line 70 in plugin.py you will see the following:

Code:

    css_new_filename = unique_filename('sgc_styles.css', namelist)
    style_folders = bk.group_to_folders("Styles","")
    css_new_bookpath = style_folders[0] + "/" + css_new_filename

Code:

    css_new_filename = unique_filename('sgc_styles.css', namelist)
    style_folders = bk.group_to_folders("Styles",[""])
    css_new_bookpath = css_new_filename
    if style_folders[0] != "":
        css_new_bookpath = style_folders[0] + "/" + css_new_filename

Notice the added "[" "]" brackets in the line that gets the folder list (it should always return a list).

And notice the test for non-empty default style_folder to prevent starting with "/" in the book path.

The spacing for the indent is 4 spaces in case it gets messed up by the post.

If you could try that and let me know if it works. If it does I will make an official new release with that change in place.

If you do not feel comfortable editing python code, just let me know and I will try to build something for you to test. I have just been so tied up with the new Sigil release. I apologize for the delay.

KevinH 05-30-2021 08:30 PM

I made the change just in case. Please give this one a try before I make an official new release.

I have my fingers crossed!

[Attachment removed - see the first post in this thread for the plugin zip archive]

Sarmat89 05-31-2021 11:48 AM

It seems to work correctly.

KevinH 05-31-2021 12:30 PM

Quote:

Originally Posted by Sarmat89 (Post 4126242)
It seems to work correctly.

Thanks for testing it.

I will make v031 the official release once I get back to my desktop machine.

KevinH

ps. It is now uploaded to the first post in this thread.


All times are GMT -4. The time now is 08:24 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.