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

« back to all changes in this revision

Viewing changes to src/calibre/devices/kindle/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:
6
6
 
7
7
import os, re, sys
8
8
 
9
 
from calibre.devices.usbms.driver import USBMS, metadata_from_formats
 
9
from calibre.devices.usbms.driver import USBMS
10
10
 
11
11
class KINDLE(USBMS):
 
12
    name           = 'Kindle Device Interface'
 
13
    description    = _('Communicate with the Kindle eBook reader.')
 
14
    author         = _('John Schember')
 
15
    supported_platforms = ['windows', 'osx', 'linux']
 
16
 
12
17
    # Ordered list of supported formats
13
18
    FORMATS     = ['azw', 'mobi', 'prc', 'azw1', 'tpz', 'txt']
14
19
 
18
23
 
19
24
    VENDOR_NAME = 'KINDLE'
20
25
    WINDOWS_MAIN_MEM = 'INTERNAL_STORAGE'
21
 
    WINDOWS_CARD_MEM = 'CARD_STORAGE'
 
26
    WINDOWS_CARD_A_MEM = 'CARD_STORAGE'
22
27
 
23
28
    OSX_MAIN_MEM = 'Kindle Internal Storage Media'
24
 
    OSX_CARD_MEM = 'Kindle Card Storage Media'
 
29
    OSX_CARD_A_MEM = 'Kindle Card Storage Media'
25
30
 
26
31
    MAIN_MEMORY_VOLUME_LABEL  = 'Kindle Main Memory'
27
32
    STORAGE_CARD_VOLUME_LABEL = 'Kindle Storage Card'
28
33
 
29
34
    EBOOK_DIR_MAIN = "documents"
30
 
    EBOOK_DIR_CARD = "documents"
 
35
    EBOOK_DIR_CARD_A = "documents"
31
36
    SUPPORTS_SUB_DIRS = True
32
37
 
33
38
    WIRELESS_FILE_NAME_PATTERN = re.compile(
34
39
    r'(?P<title>[^-]+)-asin_(?P<asin>[a-zA-Z\d]{10,})-type_(?P<type>\w{4})-v_(?P<index>\d+).*')
35
40
 
36
41
    def delete_books(self, paths, end_session=True):
37
 
        for path in paths:
 
42
        for i, path in enumerate(paths):
 
43
            self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
38
44
            if os.path.exists(path):
39
45
                os.unlink(path)
40
46
 
43
49
                # Delete the ebook auxiliary file
44
50
                if os.path.exists(filepath + '.mbp'):
45
51
                    os.unlink(filepath + '.mbp')
 
52
        self.report_progress(1.0, _('Removing books from device...'))
46
53
 
47
54
    @classmethod
48
55
    def metadata_from_path(cls, path):
49
 
        mi = metadata_from_formats([path])
 
56
        mi = cls.metadata_from_formats([path])
50
57
        if mi.title == _('Unknown') or ('-asin' in mi.title and '-type' in mi.title):
51
58
            match = cls.WIRELESS_FILE_NAME_PATTERN.match(os.path.basename(path))
52
59
            if match is not None:
58
65
 
59
66
 
60
67
class KINDLE2(KINDLE):
 
68
    name           = 'Kindle 2 Device Interface'
 
69
    description    = _('Communicate with the Kindle 2 eBook reader.')
 
70
    author         = _('John Schember')
 
71
    supported_platforms = ['windows', 'osx', 'linux']
61
72
 
62
73
    PRODUCT_ID = [0x0002]
63
74
    BCD        = [0x0100]
 
75
 
 
76
class KINDLE_DX(KINDLE):
 
77
    name           = 'Kindle DX Device Interface'
 
78
    description    = _('Communicate with the Kindle 2 eBook reader.')
 
79
    author         = _('John Schember')
 
80
    supported_platforms = ['windows', 'osx', 'linux']
 
81
 
 
82
    FORMATS     = ['azw', 'mobi', 'prc', 'azw1', 'tpz', 'pdf', 'txt']
 
83
 
 
84
    PRODUCT_ID = [0x0003]
 
85
    BCD        = [0x0100]
 
86
 
 
87