From 02e4e537e46e3f93e6a1044c7f4bfb647993dfc6 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Jan 2009 20:54:36 -0500 Subject: [PATCH 1/2] pylint clean ups --- src/calibre/devices/cybookg3/driver.py | 4 ++-- src/calibre/devices/usbms/device.py | 5 ++--- src/calibre/devices/usbms/driver.py | 7 ++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index 66e6097371..2415950d85 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -51,10 +51,10 @@ class CYBOOKG3(USBMS): return size return os.path.getsize(obj) - sizes = map(get_size, files) + sizes = [get_size(f) for f in files] size = sum(sizes) - if on_card and size > self.free_space()[2] - 1024*1024: + if on_card and size > self.free_space()[2] - 1024*1024: raise FreeSpaceError(_("There is insufficient free space on the storage card")) if not on_card and size > self.free_space()[0] - 2*1024*1024: raise FreeSpaceError(_("There is insufficient free space in main memory")) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index c9a9c2a942..3c6c660e2b 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -191,7 +191,6 @@ class Device(_Device): self._main_prefix = drives['main'] if 'main' in drives.keys() else None self._card_prefix = drives['card'] if 'card' in drives.keys() else None - @classmethod def get_osx_mountpoints(self, raw=None): if raw is None: ioreg = '/usr/sbin/ioreg' @@ -226,11 +225,11 @@ class Device(_Device): dev_pat = r'/dev/%s(\w*)\s+on\s+([^\(]+)\s+' if 'main' not in names.keys(): raise DeviceError(_('Unable to detect the %s disk drive. Try rebooting.')%self.__class__.__name__) - main_pat = dev_pat%names['main'] + main_pat = dev_pat % names['main'] self._main_prefix = re.search(main_pat, mount).group(2) + os.sep card_pat = names['card'] if 'card' in names.keys() else None if card_pat is not None: - card_pat = dev_pat%card_pat + card_pat = dev_pat % card_pat self._card_prefix = re.search(card_pat, mount).group(2) + os.sep def open_linux(self): diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 1edf406d0b..db527c04ea 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -34,7 +34,7 @@ class USBMS(Device): SUPPORTS_SUB_DIRS = False def __init__(self, key='-1', log_packets=False, report_progress=None): - pass + Device.__init__(self, key, log_packets, report_progress) def get_device_information(self, end_session=True): """ @@ -54,7 +54,8 @@ class USBMS(Device): # Get all books in all directories under the root ebook_dir directory for path, dirs, files in os.walk(os.path.join(prefix, ebook_dir)): - # Filter out anything that isn't in the list of supported ebook types + # Filter out anything that isn't in the list of supported ebook + # types for book_type in self.FORMATS: for filename in fnmatch.filter(files, '*.%s' % (book_type)): title, author, mime = self.__class__.extract_book_metadata_by_filename(filename) @@ -80,7 +81,7 @@ class USBMS(Device): return size return os.path.getsize(obj) - sizes = map(get_size, files) + sizes = [get_size(f) for f in files] size = sum(sizes) if on_card and size > self.free_space()[2] - 1024*1024: From d0986bbe8ad24d82feab3b2415294a1a88fb4bb6 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 20 Jan 2009 21:13:00 -0500 Subject: [PATCH 2/2] Do not add books to the list of books on device if they are already in the list. Fixes book showing up multiple times if it it sent to the device multiple times. Only one istance of the book will be on the device in this case. --- src/calibre/devices/usbms/books.py | 3 +++ src/calibre/devices/usbms/driver.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 3943ef94f4..fffed41549 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -18,6 +18,9 @@ class Book(object): self.thumbnail = None self.tags = [] + def __eq__(self, other): + return self.path == other.path + @apply def title_sorter(): doc = '''String to sort the title. If absent, title is returned''' diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index db527c04ea..7529890470 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -109,7 +109,7 @@ class USBMS(Device): if not os.path.exists(newpath): os.makedirs(newpath) - filepath = os.path.join(newpath, names.next()) + filepath = os.path.join(newpath, names.next()) paths.append(filepath) if hasattr(infile, 'read'): @@ -132,7 +132,10 @@ class USBMS(Device): on_card = 1 if location[1] else 0 title, author, mime = cls.extract_book_metadata_by_filename(os.path.basename(path)) - booklists[on_card].append(Book(path, title, author, mime)) + book = Book(path, title, author, mime) + + if not book in booklists[on_card]: + booklists[on_card].append(book) def delete_books(self, paths, end_session=True): for path in paths: