View Single Post
Old 10-11-2013, 06:57 PM   #11
kcz
Member
kcz began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Oct 2013
Device: Kindle
Thanks again for the detailed information. Your explanations help a lot.

Quote:
Originally Posted by chaley View Post
If I understand correctly, you want to choose the format of the series for a particular book based on the union of information from all books. You cannot do this in a template function. These functions can see only the book you are working on. They cannot see data for any other book.
Yes, pretty much. I want to choose the format of the series index based on information of the series indexes within that series.
The format should depend on the:
- max number of digits of the integer part
- max number of digits of the fractional part

e.g. one book in the series has the index 13.203 (13 and 203 are the biggest numbers for the respective floating number parts), in which case the function should return the index for every book in this series as xx.yyy
(it's just an example. it is rather unlikely that book 13 has 203 sub books )
If another series has only numbers with fractional parts of .00 and the biggest index number is 13.00, then it should be formatted as xx

Quote:
You would do something similar in python, but using calibre's data access layer. The problem is that a template function does not have access to the db, and in fact cannot have access to it. The reason: template functions can be evaluated in contexts where the db must not be opened, such as worker processes or file name generation during send-to operations.
Makes sense. Is there a description of the calibre data access layer? I found info on the plugin api and some other info, but nothing on the db layer.

Quote:
Doing what you want requires writing a plugin. These can see the database and can do completely arbitrary things such as writing values into custom columns. Alternatively you could change calibre itself to do what you want.
There is the next problem. I found information on the APIs for the different plugins, but the info does not tell me which plugin type I would have to use.
The manual also does not tell me how to use 'hooks' within calibre.

There are several ways how someone could accomplish this formatting function:

1) create a function to be used by the template language

This function would calculate the 2 info points (as described above) every time it is called. Rather ineffecient, since it would have to loop through all books in the series to find the data.
How do I even write a plugin that provides a function for the template language?

2) create a function plus a meta data table for the series

A new table with 3 columns (string series, int max_int, int max_fract). In this case calibre would have to update this table, every time a series index is changed/added/deleted. Are there any hooks in calibre or would I have to write this part as well?
In this case the function would just access this table and format the current index accordingly.

The latter is much more performant, but also more complex.

In any case, the documentation did not answer any of my questions and I am afraid I do not have the time to get familiar with the calibre code base and the plugin interfaces, which I would had to do to be actually able to implement my formatting function.

I hoped that calibre would already provide a functionality like this, since it seems logical to me that someone would like to have aligned indexes in a filename without having to hardcode the padding. e.g. who wants a filename like 'seriesname [007.000] bookname', if the biggest index is 7.00 and the series has only integers?

I just hope that I will find the time to implement something like this in the future.
kcz is offline   Reply With Quote