Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-03-2016, 06:47 AM   #1
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Advice needed for plugin running background thread

As described in another thread I'm thinking of writing a plugin to reset permissions on files in the auto-add directory so they don't get stuck there for weeks until I manually reset them. (The rights and wrongs of it are discussed extensively in that thread, but I feel like trying it anyway, as an exercise if nothing else.)

The idea is to have a plugin which spins off a background thread when Calibre starts up, which shuts down when Calibre shuts down. I was thinking of something along the following lines:
Code:
class MyPlugin(Plugin):
    keepRunning = True
    def threadBody():
        while keepRunning:
            ...
    def __init__(self):
        thread = new Thread(target=threadBody)
        thread.start()
Can anyone advise me:
(a) am I going about this in the right way -- that is, will this do what I want?
(b) what are the lifecycle issues I need to deal with (i.e. setting my keepRunning flag to False to shut down the thread in an orderly way; handling plugin reloads or whatever) and how do I deal with them?
(c) is there anything else I should know before I dive in (apart from RTFM, of course)?

I've never written a plugin before, so feel free to tell me I'm a complete idiot!

Last edited by Phssthpok; 01-03-2016 at 07:15 AM.
Phssthpok is offline   Reply With Quote
Old 01-03-2016, 07:49 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Create a user interface plugin start your thread in the genesis() method and shut it down in the shutting_down() method. And dont forget to set your thread as a daemon.
kovidgoyal is offline   Reply With Quote
Advert
Old 01-03-2016, 08:00 AM   #3
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by kovidgoyal View Post
Create a user interface plugin start your thread in the genesis() method and shut it down in the shutting_down() method. And dont forget to set your thread as a daemon.
Thanks!
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 11:25 AM   #4
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Okay, this is what I came up with for anyone else who's interested. All it does is try to make any files in the auto-add directory readable and writable so that the auto-adder can process them, signal the auto-adder to process the files, and then sleep for 10 minutes. It can undoubtedly be improved but it's good enough for me for now.
Attached Files
File Type: zip autoadd_unblocker.zip (1.5 KB, 311 views)
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 12:43 PM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Well, you could at least tell it to only mangle permissions for filetypes that calibre knows about and tries to add...
eschwartz is offline   Reply With Quote
Advert
Old 01-06-2016, 01:40 PM   #6
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by eschwartz View Post
Well, you could at least tell it to only mangle permissions for filetypes that calibre knows about and tries to add...
Yeah, it's only a toy at the moment. Is there a list of filetypes that Calibre tries to add somewhere easily accessible? (I wouldn't want to hard-code it of course, as new formats will presumably come along sometime.) If so, it's easy enough to fix. And maybe the delay should be configurable, and so on.

Incidentally, does anyone ever put files they don't want Calibre to add in the auto-add directory? If so, why? And does this mean a manual clearing-out every so often, or what? (I only ever drop book files into my auto-add directory, and I assumed this was the norm for others too.)

Last edited by Phssthpok; 01-06-2016 at 01:47 PM.
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 01:45 PM   #7
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
The unsurprisingly-named and -located:

Code:
from calibre.ebooks import BOOK_EXTENSIONS
And some people use ~/Downloads as an auto-add folder.

...

How do I find these things out? I take a look at how calibre adds things, in calibre.gui2.add_to_library and calibre.gui2.auto_add

Last edited by eschwartz; 01-06-2016 at 01:55 PM.
eschwartz is offline   Reply With Quote
Old 01-06-2016, 01:56 PM   #8
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by eschwartz View Post
The unsurprisingly-named and -located:

Code:
from calibre.ebooks import BOOK_EXTENSIONS
And some people use ~/Downloads as an auto-add folder.

...

How do I find these things out? I take a look at how calibre adds things, in calibre.gui2.add_to_library and calibre.gui2.auto_add
Thanks!

...although I see the auto-adder ignores some of those file types, so probably I would be better off using "from calibre.gui2.auto-add import AUTO_ADDED" in this case?

Last edited by Phssthpok; 01-06-2016 at 02:05 PM.
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 02:28 PM   #9
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by eschwartz View Post
Well, you could at least tell it to only mangle permissions for filetypes that calibre knows about and tries to add...
Here you go:
Attached Files
File Type: zip autoadd_unblocker.zip (1.9 KB, 294 views)
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 02:45 PM   #10
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,166
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
You could also just mangle them for files that do NOT have the correct permissions.
PeterT is offline   Reply With Quote
Old 01-06-2016, 03:01 PM   #11
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by PeterT View Post
You could also just mangle them for files that do NOT have the correct permissions.
Ah, but that would be a no-op change...
eschwartz is offline   Reply With Quote
Old 01-06-2016, 03:15 PM   #12
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by PeterT View Post
You could also just mangle them for files that do NOT have the correct permissions.
Sigh; no rest for the wicked!
Attached Files
File Type: zip autoadd_unblocker.zip (2.0 KB, 272 views)
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 03:16 PM   #13
Phssthpok
Age improves with wine.
Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.Phssthpok knows how to set a laser printer to stun.
 
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
Quote:
Originally Posted by eschwartz View Post
Ah, but that would be a no-op change...
Hmm, good point! Getting late where I am... Pity I read this after I got suckered into making the change... so I've undone it now. Good night all.

Last edited by Phssthpok; 01-06-2016 at 03:19 PM.
Phssthpok is offline   Reply With Quote
Old 01-06-2016, 03:44 PM   #14
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Checking for the pre-existing permissions only of files that are already slated to be added and cleaned up?

We don't care about preserving the mtime if it is being deleted, do we...

On the separate topic of efficiency, I had/have no qualms.
Anyway, you'd lose time when you stat the current permissions, and gain time if you can skip writing new permissions to an already-rw file.
You'd save time by not writing+deleting the flag file if only already-rw files are there.
Neither matters unless the plugin wakes up right after you add a rw file and before the auto-add finishes processing it. Unlikely timing.

With the extra (wasted?) stat calls, you might actually lose time. I'm not sure if os.stat is faster than os.chmod, if not then you always lose.
eschwartz is offline   Reply With Quote
Old 01-06-2016, 10:50 PM   #15
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The list of file types calibre adds is based on a user preference, the logic for getting that list is

Code:
        if gprefs['auto_add_everything']:
            self.allowed = AllAllowed()
        else:
            self.allowed = AUTO_ADDED - frozenset(gprefs['blocked_auto_formats'])
kovidgoyal is offline   Reply With Quote
Reply

Tags
thread that never ends


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PRS-T1 Help needed from users running the latest 1.0.07 firmware muse Sony Reader Dev Corner 7 08-28-2018 01:59 AM
UnicodeWarning when running Sigil plugin turbulent Plugins 9 12-17-2014 07:11 AM
Advice needed leeway63 General Discussions 23 12-30-2010 02:49 PM
Apps running in the background devseev enTourage Archive 14 10-25-2010 04:24 AM
apps running in background? kejia Spring Design Alex 0 05-13-2010 03:55 PM


All times are GMT -4. The time now is 11:00 AM.


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