Cybook: upload file objects (news) to device

This commit is contained in:
John Schember 2009-01-14 08:26:46 -05:00
parent a30c638e53
commit 2afb87843a

View File

@ -57,7 +57,15 @@ class USBMS(Device):
else:
path = os.path.join(self._card_prefix, self.EBOOK_DIR_CARD)
sizes = map(os.path.getsize, files)
def get_size(obj):
if hasattr(obj, 'seek'):
obj.seek(0, os.SEEK_END)
size = obj.tell()
obj.seek(0)
return size
return os.path.getsize(obj)
sizes = map(get_size, files)
size = sum(sizes)
if on_card and size > self.free_space()[2] - 1024*1024:
@ -72,6 +80,15 @@ class USBMS(Device):
filepath = os.path.join(path, names.next())
paths.append(filepath)
if hasattr(infile, 'read'):
infile.seek(0)
dest = open(filepath, 'wb')
shutil.copyfileobj(infile, dest, 10*1024*1024)
dest.flush()
dest.close()
else:
shutil.copy2(infile, filepath)
return zip(paths, cycle([on_card]))