IGN:Don't add duplicate books to Cybook

This commit is contained in:
Kovid Goyal 2009-01-20 18:47:23 -08:00
commit fb64ef80fc
4 changed files with 17 additions and 9 deletions

View File

@ -52,10 +52,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"))

View File

@ -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'''

View File

@ -191,7 +191,6 @@ class Device(_Device):
self._main_prefix = drives.get('main', None)
self._card_prefix = drives.get('card', None)
@classmethod
def get_osx_mountpoints(self, raw=None):
if raw is None:
ioreg = '/usr/sbin/ioreg'
@ -227,11 +226,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):

View File

@ -34,7 +34,8 @@ class USBMS(Device):
SUPPORTS_SUB_DIRS = False
def __init__(self, key='-1', log_packets=False, report_progress=None):
pass
Device.__init__(self, key=key, log_packets=log_packets,
report_progress=report_progress)
def get_device_information(self, end_session=True):
"""
@ -54,7 +55,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 +82,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:
@ -131,7 +133,11 @@ 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: