View Single Post
Old 06-22-2012, 05:33 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: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
Also if you have the formats visible as a custom column like I do, then you can quickly see which books only have ePub versions and know that they need converting to mobi.
If the question is whether or not one must re-convert, then you can use a variant of the formats column that shows the time the format file (.epub, .mobi, etc) was last changed. One possible template for the custom column is
Code:
program: formats_modtimes('yyyy-MM-dd hh:mm:ss')
Do note that a column displaying this information can slow down calibre because it must query the file system for every format to get the times. A slowdown will be especially pronounced if you sort on the column or if your library is on a NAS. My guess is that the slowdown won't be too noticable until one has more than 5,000 books in the library, and maybe not even then.

Now to run amok a little bit ...

Just for fun, I decided to create a yes/no display telling me if a book has formats that are older than my "master" format (EPUB). I wrote a custom formatter function that compares the dates of the formats using one as a "golden" copy. The function is intended to be used in a "column built from other columns" with "show checkmarks" checked and a sort type of "yes/no".

The function returns '' if there are zero or one formats or if there is no "golden" format, resulting is displaying nothing in the column. Otherwise it returns 'no' if any of the non-golden formats are older than the golden one resulting in displaying a red X, and it returns 'yes' if the golden format is the oldest resulting in a green check.

The function definition is:
Code:
Function: myFunc (or whatever you want to call it)
Arg count: 1
Documentation: (whatever you want to write)
Program code:
def evaluate(self, formatter, kwargs, mi, locals, golden):
	fmi = mi.format_metadata
	golden = golden.upper()
	if len(fmi) <= 1 or fmi.get(golden, None) is None:
		return ''
	g = sorted(fmi.items(), key=lambda x:x[1]['mtime'])
	if g[0][0] == golden:
		return 'yes'
	return 'no'
Assuming that the function name is myFunc (as above) and that the golden format is EPUB, the template for the composite column is
Code:
program: myFunc('EPUB')
If you want to have the golden format differ for each book you must create another custom text column and enter the golden format name in that. You would then change the template to pass that field into myFunc instead of the constant string ("field('#lookupkey')" instead of 'EPUB').
chaley is offline   Reply With Quote