Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-12-2012, 07:26 PM   #1
Backi
Connoisseur
Backi has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead community
 
Backi's Avatar
 
Posts: 99
Karma: 15776
Join Date: Dec 2011
Device: PB912 Matt White
[Bug?] Field(s) in prefix/suffix

Could you confirm the malfunction I encountered using fields in prefix/suffix?

This template (just an example) works on books with and without series/series_index:
Code:
{series:|{isbn}|}{title}
These surprisingly don't work on books without series/series_index:
Code:
{series_index:|{isbn}|}{title}
{series_index:||{isbn}}{title}
In both cases I get this error message (here for the first one):
Quote:
calibre, version 0.8.42
WARNING: Could not save some books: Could not save some books, Click the show details button to see which ones.

Traceback (most recent call last):
File "site-packages\calibre\library\save_to_disk.py", line 437, in save_serialized_to_disk
File "site-packages\calibre\library\save_to_disk.py", line 305, in do_save_book_to_disk
ValueError: Failed to calculate path for save to disk. Template: {series_index:|{isbn}|}{title}
Error: Single '}' encountered in format string
The only difference could be that series is a string whereas series_index is a number?
I wonder, why the field series_index is considered at all for books where it's empty. The section "Advanced formatting" states:
Quote:
If field has no value, then the result will be the empty string (nothing); the prefix and suffix are ignored.
Backi is offline   Reply With Quote
Old 03-12-2012, 07:35 PM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,812
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
I don't think inserting a field was ever envisioned in this manner.
I believe those positions expect 'literals' (characters).
If you don't have a Series, you can't have a series index

I believe you will need to us Program mode (And, Please don't ask me for help with that)
theducks is offline   Reply With Quote
Advert
Old 03-12-2012, 08:05 PM   #3
Backi
Connoisseur
Backi has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead community
 
Backi's Avatar
 
Posts: 99
Karma: 15776
Join Date: Dec 2011
Device: PB912 Matt White
Quote:
Originally Posted by theducks View Post
I don't think inserting a field was ever envisioned in this manner.
I believe those positions expect 'literals' (characters).
I don't think so, because otherwise I would get something like "_isbn_" instead of the value for {isbn} in prefix/suffix.

Quote:
Originally Posted by theducks View Post
If you don't have a Series, you can't have a series index
But this one without fields in prefix and suffix works:
Code:
{series_index:|test1|test2}{title}

Last edited by Backi; 03-12-2012 at 08:08 PM.
Backi is offline   Reply With Quote
Old 03-13-2012, 01:37 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Backi View Post
Could you confirm the malfunction I encountered using fields in prefix/suffix?

This template (just an example) works on books with and without series/series_index:
Code:
{series:|{isbn}|}{title}
These surprisingly don't work on books without series/series_index:
Code:
{series_index:|{isbn}|}{title}
{series_index:||{isbn}}{title}
It says in the single-function section of the manual: "All arguments must be constants; there is no sub-evaluation." Your template is using sub-evaluation because "{isbn}" is inside the series_index template expression.

The use of template expressions within template expressions is highly unreliable. I consider it a bug that it works at all, and would take it out except that doing so would cause the people for whom it works to yell very loudly. You have hit one of the problems -- expecting { ... } to nest. There are cases where they do not, one of which is references to series_index in save_to_disk templates. In the failure case a { is paired with the nearest }, not with the matching nested }. In other words, the { in front of "series_index" is matched against the } following "isbn", not against the one following the '|' character. The other common failure case occurs when the value being inserted contains a template special character such as '|', '{', '}', or sometimes ','.

You can express the equivalent of {series_index:|{isbn}|}{title} without nesting by using the following "template program mode" template.
Code:
{series_index:'test($, strcat(field('isbn'), $), '')'}{title}
For completeness, an equivalent template in general program mode is
Code:
program: 
	s = field('series_index');
	strcat(test(s, strcat(field('isbn'), s), ''), field('title'))
chaley is offline   Reply With Quote
Old 03-13-2012, 05:48 AM   #5
Backi
Connoisseur
Backi has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead communityBacki has become a pillar of the MobileRead community
 
Backi's Avatar
 
Posts: 99
Karma: 15776
Join Date: Dec 2011
Device: PB912 Matt White
Quote:
Originally Posted by chaley View Post
It says in the single-function section of the manual: "All arguments must be constants; there is no sub-evaluation." Your template is using sub-evaluation because "{isbn}" is inside the series_index template expression.
Is it really sub-evaluation? I thought there is no sub-evaluation, because there is no function after ":". All I have is a prefix/suffix which is a field, not an argument of any function.

Quote:
Originally Posted by chaley View Post
The use of template expressions within template expressions is highly unreliable. I consider it a bug that it works at all, and would take it out except that doing so would cause the people for whom it works to yell very loudly. You have hit one of the problems -- expecting { ... } to nest. There are cases where they do not, one of which is references to series_index in save_to_disk templates. In the failure case a { is paired with the nearest }, not with the matching nested }. In other words, the { in front of "series_index" is matched against the } following "isbn", not against the one following the '|' character.
This is a weird behavior. I think it should be either taken completely out or implemented completely, or at least documented in the manual.

Quote:
Originally Posted by chaley View Post
You can express the equivalent of {series_index:|{isbn}|}{title} without nesting by using the following "template program mode" template.
Code:
{series_index:'test($, strcat(field('isbn'), $), '')'}{title}
For completeness, an equivalent template in general program mode is
Code:
program: 
	s = field('series_index');
	strcat(test(s, strcat(field('isbn'), s), ''), field('title'))
Thanks! I think, I will use the general program mode.
Backi is offline   Reply With Quote
Advert
Old 03-13-2012, 06:22 AM   #6
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Backi View Post
Is it really sub-evaluation? I thought there is no sub-evaluation, because there is no function after ":". All I have is a prefix/suffix which is a field, not an argument of any function.
Yes, it is sub-evaluation. There is a non-constant in the template -- a template expression in a template expression.
Quote:
This is a weird behavior. I think it should be either taken completely out or implemented completely, or at least documented in the manual.
I can't implement it completely/correctly without reimplementing python's text formatting language, which isn't something I am willing to do.

You are right that the documentation can be improved, which is a never-ending task. In this case I copied the bold "Do not use subtemplates" warning from the single-function-mode section to the section discussing prefixes and suffixes.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Default value for read field (Yes/No-field) opitzs Library Management 3 11-09-2011 07:17 AM
Embedded font bug or CSS bug in ADE JSWolf ePub 10 06-11-2011 02:34 PM
How does one change the prefix? AlexBell Upload Help 2 07-30-2010 07:31 AM
Bug? "Insert metadata as page at start of book" doesnt encode Comments field properly rollercoaster Calibre 2 04-24-2010 10:40 PM


All times are GMT -4. The time now is 02:36 AM.


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