I looked at the code for the driver and the utilities and I think that setting the device name will be a giant pain in the *^&. The problem is the sequencing of the operations. The calibre device driver gets and caches the device_info before the utilities can get involved.
I also looked at the code for generating collection values (get_collections). Changing that to use a template will also be a pain because so much of it is built around lookup/collection names.
Fortunately for me, neither of the above is needed. The following solves my problem albeit with a bit of brute force:
- In the utilities plugin, add the ability to copy the device serial number so the user can get it to use in the template.
- Add another box to the driver where I can put a template to format values for collection attributes.
- Change kobo.books.get_collections() to invoke the template if it is defined. If it is defined then you would:
- Initialize a 'globals' dict with the device serial number, the lookup name being processed, the value generated, and the column heading. You can get the serial number at device-open time without involving the utilities plugin.
- Initialize a new_vals dict.
- For each value in the vals dict, call the template. If the answer is non-empty add it to the new_vals dict.
- Replace vals with new_vals
Attached is a patch file showing an example of the kobotouch driver changes to do the above. It works for me. NB: I didn't make the utilities change.