Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 09-20-2011, 10:18 AM   #1
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
Functions not found when used in Export script

Hello, I made a function to make the correct folder name on disk or book.
I have the result in a column, which shows the correct content.
However, when I try to use that column in the export script I get an error in the file names.
The function call for the column is this: {title:folderOnDevice({#genre},{series},{series_in dex},{#max_number_in_series},10)}
The other needed columns (genre and max_number_in_series) are correct too.
The column is called: folder_on_device_10
When I use this script for output, it does show the correct output: {#genre}
When I use this script for output: {#folder_on_device_10} I get this file:
folderOnDevice_ onbekende functie

(onbekende functie means: unknown function)

Please help me to put the files in the correct place on my devices!!

Is this a bug which will be resolved soon?
Arco Witter is offline   Reply With Quote
Old 09-20-2011, 01:10 PM   #2
chaley
"chaley", not "charley"
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: 5,030
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
I am not sure what you mean by "export script". Also, I am confused by the term "function call".

From what I can tell, you have a composite custom column called "folder_on_device_10". The template for that column is
Code:
{title:folderOnDevice({#genre},{series},{series_index},{#max_number_in_series},10)}
I assume that 'folderOnDevice' is a custom template function.

First comment: you should not use template references inside function arguments. There are many ways that this breaks. I consider it a bug that it works at all, but people have asked me not to fix it.

Instead of template references, you should be using one of the program modes. Given that your function does not use title, you should probably use general program mode. Your function would look something like:
Code:
program:folderOnDevice(field('#genre'), field('series'), field('series_index'), field('#max_number_in_series'),10)
Second comment (really a question): what do you mean by "export"? Do you mean save to disk or send to device?
chaley is offline   Reply With Quote
 
Enthusiast
Old 09-23-2011, 09:30 AM   #3
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
Thanks for helping!!
However, when I use what you wrote, I get an error:
SJABLOONFOUT Formatter: incorrect number of arguments for function folderOnDevice dichtbij )

With "Export" I meant save to disk (Having the Dutch language I have to translate every item, sorry for that...)
But I think this will not work when sending to device.

Could you please give me the definition for this function? (correct parameters are enough, I think)
Currently I have this:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, genretext, serietext, number_in_series, max_number_in_series, aantal_menu_items):
	titletext=val
	try:
		aant_mi = int(aantal_menu_items)
	except:
		return 'aantal_menu_items is geen aantal!'

	if number_in_series is None:
		num_in_serie = 0
	else:
		try:
			num_in_serie = int(number_in_series)
		except:
			num_in_serie = 0
			#return 'number_in_series is geen aantal!'

	MaxAantInSerie = 0
	if num_in_serie > 0:
		if max_number_in_series is None:
			MaxAantInSerie = num_in_serie
		else:
			try:
				MaxAantInSerie = int(max_number_in_series)
			except:
				MaxAantInSerie = num_in_serie
				# return 'max_number_in_series is niet ingevuld!'

	s = ''

	DoeBerekening = 1
	if MaxAantInSerie == 0:
		DoeBerekening = 0
	if num_in_serie == 0:
		DoeBerekening = 0

	#return 'MaxAantInSerie={0}, num_in_serie={1}, DoeBerekening={2}'.format(MaxAantInSerie, num_in_serie, DoeBerekening)

	if DoeBerekening == 1:
		#try:
	    # Menu structuur aanbrengen
			f  = num_in_serie - 1
			f1 =  f / aant_mi
			f2 = f1 / aant_mi
			f3 = f2 / aant_mi
			f4 = f3 / aant_mi
			f5 = f4 / aant_mi

			# Aantal items dat per menudiepte kan worden geplaatst
			items_in_menu_diepte1 = aant_mi
			items_in_menu_diepte2 = items_in_menu_diepte1 * aant_mi
			items_in_menu_diepte3 = items_in_menu_diepte2 * aant_mi
			items_in_menu_diepte4 = items_in_menu_diepte3 * aant_mi
			items_in_menu_diepte5 = items_in_menu_diepte4 * aant_mi

			# Bereken diepst benodigde niveau
			max_mi_diepte=5
			if MaxAantInSerie <= items_in_menu_diepte5:
				max_mi_diepte=4
			if MaxAantInSerie <= items_in_menu_diepte4:
				max_mi_diepte=3
			if MaxAantInSerie <= items_in_menu_diepte3:
				max_mi_diepte=2
			if MaxAantInSerie <= items_in_menu_diepte2:
				max_mi_diepte=1
			if MaxAantInSerie <= items_in_menu_diepte1:
				max_mi_diepte=0

			# Bereken de van.. tot per menudiepte voor betreffende boek
			fl1 =  f1      * items_in_menu_diepte1 + 1
			fh1 = (f1 + 1) * items_in_menu_diepte1
			fl2 =  f2      * items_in_menu_diepte2 + 1
			fh2 = (f2 + 1) * items_in_menu_diepte2
			fl3 =  f3      * items_in_menu_diepte3 + 1
			fh3 = (f3 + 1) * items_in_menu_diepte3
			fl4 =  f4      * items_in_menu_diepte4 + 1
			fh4 = (f4 + 1) * items_in_menu_diepte4
			fl5 =  f5      * items_in_menu_diepte5 + 1
			fh5 = (f5 + 1) * items_in_menu_diepte5

      # Zorg ervoor dat de hoogste niet meer wordt dan het maximum in de serie
			if fh1 > MaxAantInSerie:
			  fh1 = MaxAantInSerie
			if fh2 > MaxAantInSerie:
			  fh2 = MaxAantInSerie
			if fh3 > MaxAantInSerie:
			  fh3 = MaxAantInSerie
			if fh4 > MaxAantInSerie:
			  fh4 = MaxAantInSerie
			if fh5 > MaxAantInSerie:
			  fh5 = MaxAantInSerie

			# Bepaal aantal cijfers benodigd om maximum vast te houden
			ac=1
			if MaxAantInSerie>9:
				ac=2
			if MaxAantInSerie>99:
				ac=3
			if MaxAantInSerie>999:
				ac=4
			if MaxAantInSerie>9999:
				ac=5

			# Bepaal hier de feitelijke string voor de menustructuur
			acs='{0:02}'.format(ac)  #Levert een string op zoals: 01 of 02
			if max_mi_diepte == 0:  #1-10
				s = ''
			if max_mi_diepte > 1:  #1-100, dus gelijk al 2 diep: 001-100/001-010, 001-100/011-020, ... 101-200/101-110
				s = serietext + ' {2:' + acs + '}-{3:' + acs + '}' + '/{0:' + acs + '}-{1:' + acs + '}'
			if max_mi_diepte > 2:
				s = serietext + ' {4:' + acs + '}-{5:' + acs + '}' + '/' + s
			if max_mi_diepte > 3:
				s = serietext + ' {6:' + acs + '}-{7:' + acs + '}' + '/' + s
			if max_mi_diepte > 4:
				s = serietext + ' {8:' + acs + '}-{9:' + acs + '}' + '/' + s
			#if max_mi_diepte > 5:
			#	s = serietext + ' {10:' + acs + '}-{11:' + acs + '}' + '/' + s

			#return 'ac={0}, MaxAantInSerie={1}, max_mi_diepte={2}, s={3}'.format(ac,MaxAantInSerie,max_mi_diepte,s)


			s = s.format(fl1,fh1,fl2,fh2,fl3,fh3,fl4,fh4,fl5,fh5)

			#return 'items_in_menu_diepte: 1={0}, 2={1}, 3={2}, 4={3}; aant_menu_nodig_voor_max_serie={4}; max_mi_diepte={5}; s={6}'.format(items_in_menu_diepte1,items_in_menu_diepte2,items_in_menu_diepte3,items_in_menu_diepte4,aant_menu_nodig_voor_max_serie,max_mi_diepte,s);
		#except:
		#	pass
		#	return 'OEPS!'

	if genretext != '':
		genretext = genretext + '/'

	if serietext != '':
		serietext = serietext + '/'

	if (genretext + serietext != '') and (s != ''):
		s = s + '/'

	return genretext + serietext + s
btw: I got this information from here: http://manual.calibre-ebook.com/temp...late-functions
so this is the manual for Calibre itself, right?
If you can point me to any place where the construction 'program:' is used, please do so!

Last edited by Arco Witter; 09-23-2011 at 09:46 AM.
Arco Witter is offline   Reply With Quote
Old 09-23-2011, 11:07 AM   #4
chaley
"chaley", not "charley"
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: 5,030
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by Arco Witter View Post
Could you please give me the definition for this function? (correct parameters are enough, I think)
Currently I have this:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, genretext, serietext, number_in_series, max_number_in_series, aantal_menu_items):
I am not sure what you mean by definition. I suspect you mean the prototype for how you call it.

That function requires six arguments: val, genretext, serietext, number_in_series, max_number_in_series, aantal_menu_items. The example in your first post implies that 'val' is really title. Using this assumption, and further assuming template program mode, you would call it something like
Code:
{title:folderOnDevice($, field('#genre'), field('series'), field('series_index'), field('#max_number_in_series'),10)'}
You would call it in general program mode using
Code:
program: folderOnDevice(field('title'), field('#genre'), field('series'), field('series_index'), field('#max_number_in_series'),10)
Quote:
btw: I got this information from here: http://manual.calibre-ebook.com/temp...late-functions
so this is the manual for Calibre itself, right?
yes
Quote:
If you can point me to any place where the construction 'program:' is used, please do so!
It is documented in the same manual section. See http://manual.calibre-ebook.com/temp...l-program-mode
chaley is offline   Reply With Quote
Old 09-23-2011, 02:31 PM   #5
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
I do have the column correctly now.
However, save to disk still does not work.
I tried this:
Code:
program:folderOnDevice(field('#genre'), field('series'), field('series_index'), field('#max_number_in_series'),10)
as well as this:
Code:
{#folder_on_device_10}
but I still get an error that the field does not exist.

When I do the save to disk itself, I get these filenames:
Code:
#folder_on_device_10.jpg
#folder_on_device_10.mobi
#folder_on_device_10.opf
#folder_on_device_10.pdf
It just seems that the program has several divisions which do know nothing about each others functions or fields (columns).
I can't think of anything to make this work... Hopefully you do!
Arco Witter is offline   Reply With Quote
Old 09-23-2011, 03:42 PM   #6
chaley
"chaley", not "charley"
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: 5,030
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
There is indeed a problem with using user-defined functions in save-to-disk and send-to-device templates. Unfortunately, it isn't easy to fix. The problem is that the template functions are stored in the library, which is not available within the save/send jobs. I need to find a way to pass these functions without breaking anything. This needs some thought.
chaley is offline   Reply With Quote
Old 09-23-2011, 05:35 PM   #7
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
Good to see that we're up on something!
Now the solution :P
(Since I am a programmer myself (though Delphi) I might be of some service?)
Arco Witter is offline   Reply With Quote
Old 09-24-2011, 11:57 AM   #8
chaley
"chaley", not "charley"
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: 5,030
Karma: 802238
Join Date: Jan 2010
Location: France
Device: Many android devices
Fix is in the 'trunk' source and will be in the next release.

And thanks for offering to help.
chaley is offline   Reply With Quote
Old 09-24-2011, 04:41 PM   #9
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
Nice to see how quick this problem is solved!
Let's hope this is the working solution.
(Can't wait to see the upcoming version)
Thanks!
Arco Witter is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Most often used calibre functions thearr Calibre 17 08-07-2011 02:44 PM
New functions poco06 Calibre 4 05-01-2010 01:39 PM
Can I use all Kindle functions outside USA? khanhtm Amazon Kindle 11 01-04-2010 08:15 AM
Changing Button functions vadindot iRex 3 03-26-2009 10:49 AM
Cybook not found in linux, found in win XP fjf Bookeen 15 01-18-2008 06:57 PM


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


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