~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/devices/prs500/driver.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090730124941-kviipg9ypwgppulc
Tags: upstream-0.6.3+dfsg
ImportĀ upstreamĀ versionĀ 0.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from functools import wraps
41
41
from StringIO import StringIO
42
42
 
43
 
from calibre.devices.interface import Device
 
43
from calibre.devices.interface import DevicePlugin
44
44
from calibre.devices.libusb import Error as USBError
45
45
from calibre.devices.libusb import get_device_by_id
46
46
from calibre.devices.prs500.prstypes import *
47
47
from calibre.devices.errors import *
48
48
from calibre.devices.prs500.books import BookList, fix_ids
49
49
from calibre import __author__, __appname__
 
50
from calibre.devices.usbms.deviceconfig import DeviceConfig
50
51
 
51
52
# Protocol versions this driver has been tested with
52
53
KNOWN_USB_PROTOCOL_VERSIONS = [0x3030303030303130L]
76
77
        return self.name
77
78
 
78
79
 
79
 
class PRS500(Device):
 
80
class PRS500(DeviceConfig, DevicePlugin):
80
81
 
81
82
    """
82
83
    Implements the backend for communication with the SONY Reader.
83
84
    Each method decorated by C{safe} performs a task.
84
85
    """
 
86
    name           = 'PRS-500 Device Interface'
 
87
    description    = _('Communicate with the Sony PRS-500 eBook reader.')
 
88
    author         = _('Kovid Goyal')
 
89
    supported_platforms = ['windows', 'osx', 'linux']
85
90
 
86
91
    VENDOR_ID    = 0x054c #: SONY Vendor Id
87
92
    PRODUCT_ID   = 0x029b #: Product Id for the PRS-500
103
108
    CARD_PATH_PREFIX = __appname__
104
109
    _packet_number = 0     #: Keep track of the packet number for packet tracing
105
110
 
 
111
    SUPPORTS_SUB_DIRS = False
 
112
    MUST_READ_METADATA = True
 
113
 
106
114
    def log_packet(self, packet, header, stream=sys.stderr):
107
115
        """
108
116
        Log C{packet} to stream C{stream}.
181
189
 
182
190
        return run_session
183
191
 
184
 
    def __init__(self, key='-1', log_packets=False, report_progress=None) :
 
192
    def reset(self, key='-1', log_packets=False, report_progress=None) :
185
193
        """
186
194
        @param key: The key to unlock the device
187
195
        @param log_packets: If true the packet stream to/from the device is logged
274
282
        if res.code != 0:
275
283
            raise ProtocolError("Could not set time on device")
276
284
 
 
285
    def eject(self):
 
286
        pass
 
287
 
277
288
    def close(self):
278
289
        """ Release device interface """
279
290
        try:
620
631
                data_type=FreeSpaceAnswer, \
621
632
                command_number=FreeSpaceQuery.NUMBER)[0]
622
633
            data.append( pkt.free )
 
634
        data = [x for x in data if x != 0]
 
635
        data.append(0)
623
636
        return data
624
637
 
625
638
    def _exists(self, path):
855
868
        size = sum(sizes)
856
869
        space = self.free_space(end_session=False)
857
870
        mspace = space[0]
858
 
        cspace = space[1] if space[1] >= space[2] else space[2]
 
871
        cspace = space[2] if len(space) > 2 and space[2] >= space[1] else  space[1]
859
872
        if on_card and size > cspace - 1024*1024:
860
873
            raise FreeSpaceError("There is insufficient free space "+\
861
874
                                          "on the storage card")