|
|
Thread Tools | Search this Thread |
01-04-2016, 03:59 AM | #1 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Losin in python: Passing info between different instances of a class
Hi,
I'm trying to finish a plugin to store the filename into a library column when a book is added to calibre. I've been able to define a costum colum (by hand, not getting info from calibre library but...), and getting the filename and the metadata. Problem is, I've got to pass this info between instances, as the name must be caught before adding it to the library and the column must be updated after the book has been added (onimport and postimport). In theory, if I used a class variable (dictionary) this should be easy but it doesn't work for me and I don't know enough python to find the problem. The dictionary is fulfilled on import, but it is empty at post import. Any idea would be welcome, thank you. |
01-04-2016, 07:28 AM | #2 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There is no easy way to do that. onimport is run in a separate process. A short lived worker process is used to read metadata from ebook files. postimport uns in the main process, which actually adds the files to the database.
The only way to pass information between onimport and postimport would be to persist the data in the filesystem. You could simply write the information keyed by file path to a temp file in onimport and read it from the temp file in onpostimport. There are two problems witht hat you would have to overcome: 1) Identifying the file. You would need to robustly identify the same file in the two contexts. Using the file path may or may not work, since other onimport plugins can change the file path. 2) On windows you will run into file locking issues when using a temp file. So remember to use the share_open() function from calibre.utils.shared_file |
Advert | |
|
01-04-2016, 08:30 AM | #3 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Here I have added some API to FieTypePlugins that should make it very easy to do what you need in a postimport plugin.
https://github.com/kovidgoyal/calibr...95264fc36f87f5 Just implement the postadd() method in your plugin and read teh filename from the fmt_map parameter. |
01-04-2016, 02:14 PM | #4 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Thank you, but I'm not sure about the fmt_map parameter, as this will not be the same than on_import in some cases (Alf tools), and I don't know how to relate both of them. I'll have to see if I find a pattern I can use in Alf tools.
|
01-04-2016, 02:18 PM | #5 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The filename (except for extension) is always preserved when running import plugins. Only the full file path may be different.
|
Advert | |
|
01-04-2016, 02:22 PM | #6 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
That was something I didn't know, so it's quite easy now, thank you very much.
|
01-04-2016, 02:24 PM | #7 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It has to be that way, otherwise reading metadata from filenames would not work, since metadata has to be read after the import plugins are run.
|
01-04-2016, 02:46 PM | #8 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
You're right but, as I don't use that method, I never think about it, sorry.
|
01-17-2016, 04:58 AM | #9 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Hi,
I'm testing the method and the problem I've found is that postadd isn't called when I add books from a single directory and I select a book? I have defined postimport postadd methods and postimport is called but postadd no. I don't know what I'm doing wrong. Thanks in advance |
01-17-2016, 06:31 AM | #10 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
What exactly are you doing? Clicking add books and selecting a file? Or selecting add books from sub-directories, one book per directory?
|
01-17-2016, 07:01 AM | #11 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Clicking add books and selecting a file.
|
01-17-2016, 10:19 AM | #12 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I have no way to help without access to your plugin.
|
01-17-2016, 01:18 PM | #13 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Here you have it, it's very simple and rough. And thank you very much.
|
01-17-2016, 02:07 PM | #14 |
Grand Sorcerer
Posts: 6,233
Karma: 11768331
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Hi kovid,
my plugin has a mistake but I think the problem is that _on_postadd is not declared as global so the functions are not called (I've setup a development environment, declared it and it is called now). |
01-18-2016, 12:05 AM | #15 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You are correct, sorry about that
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Aura H2O MicroSDHC card class 4 or class 10? | chipro12 | Kobo Reader | 5 | 07-04-2015 02:24 AM |
Compare two instances of calibre | snoopyeab | Library Management | 9 | 03-10-2015 05:03 AM |
PRS-650 SD Card Importance? SDHC, SDHC Class 4, Class 10 etc is it important | Renji | Sony Reader | 11 | 12-03-2011 12:30 PM |
Two instances of Calibre | Ortep | Calibre | 4 | 03-25-2011 06:10 PM |
Peculiar instances of georestrictions | AprilHare | General Discussions | 9 | 10-12-2010 12:06 AM |