![]() |
#586 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Additional question: The GPM template returns backslashes. Do I need to use a re(_,/) when this is used in a save template as with a non-composite column?
|
![]() |
![]() |
![]() |
#587 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I think best would be to use slashes exclusively, which might argue for the re() you mention. However, I am not sure that save templates can use functions because they use a limited formatter, which if so means you can't use re(). Try it and see... |
|
![]() |
![]() |
Advert | |
|
![]() |
#588 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,614
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Suggestion: an has_data function, analogue of has_cover.
|
![]() |
![]() |
![]() |
#589 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
This is something I would use.
|
![]() |
![]() |
![]() |
#590 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Such a function must query the file system, so it won't be fast. My suspicion is that you want to use this for column icons, which may make the performance unacceptable.
Implementation choices:
This python template does check #2. Make it a stored template and try it to see if it is sufficiently performant. Code:
python: def evaluate(book, context): db = context.db.new_api files = db.list_extra_files_matching(book.id) return '1' if files else '' |
![]() |
![]() |
Advert | |
|
![]() |
#591 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I want to run it in a saved search, so speed wouldn't have been much an issue. Will try the python though.
|
![]() |
![]() |
![]() |
#592 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I should point out another problem with using some API to have column icons for books with extra data: the answer might be wrong. The answer from column icon templates is cached in the GUI until something changes. Unfortunately for this: extra data can be added/removed outside of calibre, so calibre doesn't know that something changed. The "answer" will be wrong until something does change or the GUI is refreshed.
Last edited by chaley; 04-21-2023 at 05:45 AM. |
![]() |
![]() |
![]() |
#593 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,614
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
No worries, I'll continue doing what I've been doing with my !Attachment folders, putting a file:/// link to the ...author/book/data path in the #links/Links long text columns.
I guess I assumed there'd be a has_data BOOL in the books table. Should have looked. BTW the inter-library peek (book-details) is exactly what I wanted, thanks for that. |
![]() |
![]() |
![]() |
#594 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
does has_cover stored in the database, or just a check for cover.jpg?
|
![]() |
![]() |
![]() |
#595 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#596 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
That makes sense. I don't think there's an in-program way to delete extra files (at least that I found). So setting a database entry on adding an extra file isn't very reliable.
|
![]() |
![]() |
![]() |
#597 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
@chaley - I saved the template to has_data(). I did change '1' to 'Yes' so it would match has_cover().
It worked pretty quickly in a saved search so as an extra test I added it to this: Code:
program: formats = approximate_formats(); strcat ( if "epub" inlist formats then 'formats_epub.png:' fi, if "pdf" inlist formats then 'formats_pdf.png:' fi, if "azw3" inlist formats then 'formats_azw3.png:' fi, if "mobi" inlist formats then 'formats_mobi.png:' fi, if "cbz" inlist formats then 'formats_cbz.png:' fi, if "txt" inlist formats then 'formats_txt.png:' fi, if "paperbook" inlist formats then 'formats_paperbook.png:' fi, if "overdrive" inlist formats then 'formats_overdrive.png:' fi, if has_data() == 'Yes' then 'save.png:' fi, if list_difference(formats, 'epub, pdf, azw3, mobi, cbz, paperbook, overdrive, txt', ',') then 'formats_unknown.png' fi ) Last edited by ownedbycats; 04-21-2023 at 07:43 PM. |
![]() |
![]() |
![]() |
#598 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
@chaley - After updating Calibre to source, has_data() broke with this error:
EXCEPTION: Error in function evaluate on line 4 : AttributeError - 'Cache' object has no attribute 'list_extra_files_matching' What changed? EDIT: Maybe this change https://github.com/kovidgoyal/calibr...095525b6e24e92 Last edited by ownedbycats; 04-24-2023 at 01:32 AM. |
![]() |
![]() |
![]() |
#599 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The template should be: Code:
python: def evaluate(book, context): db = context.db.new_api files = db.list_extra_files(book.id, pattern='data/**/*', use_cache=True) return 'Yes' if files else '' |
|
![]() |
![]() |
![]() |
#600 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thanks
![]() Somewhat related: What happens if a new template function shares the name as an already existing saved template? |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Library Management: various questions not worth their own thread | ownedbycats | Library Management | 198 | 04-26-2025 07:02 PM |
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates | Boilerplate4U | Development | 13 | 07-07-2020 02:35 AM |
Questions on Kobo [Interfered with another thread topic] | spdavies | Kobo Reader | 8 | 10-12-2014 11:37 AM |
[OLD Thread] Some questions before buying the fire. | darthreader13 | Kindle Fire | 7 | 05-10-2013 09:19 PM |
Thread management questions | meme | Feedback | 6 | 01-31-2011 05:07 PM |