Thread: Library names
View Single Post
Old 02-27-2011, 01:24 PM   #16
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,471
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Call for comments

I propose that for usb-based devices, calibre creates and maintains a file devinfo.calibre containing the following dict:

Code:
devstatus_calibre = {
    'uuid'                : None,
    'calibre_version'     : None,
    'date_last_changed'   : None,
}
Should there be anything else in the dict?

Details:

The device driver (usbms) will read the dict from the file when the device connects (in usbms.device.open), initializing the dict if it does not exist. It will update the file at the end of sync_booklists. A new interface function get_devstatus will be provided to fetch the dict. The interface function will not start a job. An API will be added to the device manager to call it.

The file will be JSON-encoded. Sample code is under the spoiler:
Spoiler:
Code:
import json, uuid

from calibre.constants import numeric_version
from calibre.utils.config import to_json
from calibre.utils.date import now

devstatus_calibre = {
    'uuid'                : None,
    'calibre_version'     : None,
    'date_last_changed'   : None,
}

devstatus_calibre['uuid'] = unicode(uuid.uuid4())
devstatus_calibre['calibre_version'] = list(numeric_version)
devstatus_calibre['date_last_changed'] = unicode(now())

print json.dumps(devstatus_calibre, default=to_json)

Design constraints:
1) there can be no data in the dict requiring interaction with the user.
2) the data must be JSON-serializable
3) the dict must be small (less than 512 bytes) and complexity must be low to avoid out-of-space errors or corruption-on-write problems.
4) calibre must be able to survive the file disappearing or being corrupted.
chaley is offline   Reply With Quote