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 04-16-2023, 06:04 PM   #586
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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?
ownedbycats is offline   Reply With Quote
Old 04-16-2023, 06:13 PM   #587
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: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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?
Perhaps. Using backslashes works for paths in Windoes unless they appear in a context where they might be considered to be escapes. I also don't know that you can mix slashes and backslashes in the same path.

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...
chaley is offline   Reply With Quote
Advert
Old 04-21-2023, 01:04 AM   #588
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,614
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Suggestion: an has_data function, analogue of has_cover.
BetterRed is online now   Reply With Quote
Old 04-21-2023, 01:19 AM   #589
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,650
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
This is something I would use.
ownedbycats is offline   Reply With Quote
Old 04-21-2023, 05:10 AM   #590
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: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BetterRed View Post
Suggestion: an has_data function, analogue of has_cover.
Quote:
Originally Posted by ownedbycats View Post
This is something I would use.
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:
  1. Fastest would be to check if "data/" exists, regardless of whether or not there is anything in it. I suspect the false positive rate would be unacceptable.
  2. Next would be to check if "data/" contains anything.
  3. Equally performant as 2, or perhaps I should say non-performant, would be to permit checking if particular files exist by matching the list of files against a regular expression.

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 ''
chaley is offline   Reply With Quote
Advert
Old 04-21-2023, 05:36 AM   #591
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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.
ownedbycats is offline   Reply With Quote
Old 04-21-2023, 05:36 AM   #592
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: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BetterRed View Post
Suggestion: an has_data function, analogue of has_cover.
Quote:
Originally Posted by ownedbycats View Post
This is something I would use.
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.
chaley is offline   Reply With Quote
Old 04-21-2023, 06:10 AM   #593
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
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.
BetterRed is online now   Reply With Quote
Old 04-21-2023, 06:44 AM   #594
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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?
ownedbycats is offline   Reply With Quote
Old 04-21-2023, 06:45 AM   #595
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: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
does has_cover stored in the database, or just a check for cover.jpg?
It checks the database. If you delete the cover by hand then the database can be wrong. This is why "Check library" has a cover check.
chaley is offline   Reply With Quote
Old 04-21-2023, 06:51 AM   #596
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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.
ownedbycats is offline   Reply With Quote
Old 04-21-2023, 06:15 PM   #597
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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	
   )
It doesn't seem to be any slower than usual so think I will keep.

Last edited by ownedbycats; 04-21-2023 at 07:43 PM.
ownedbycats is offline   Reply With Quote
Old 04-24-2023, 01:30 AM   #598
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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.
ownedbycats is offline   Reply With Quote
Old 04-24-2023, 04:06 AM   #599
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: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
@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
Yes, because of that commit. The API was improved for this use case, making it faster.

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 ''
Note: I will be adding template functions for queries about extra files.
chaley is offline   Reply With Quote
Old 04-24-2023, 04:36 AM   #600
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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?
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 05:54 PM.


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