mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Cybook: upload file objects (news) to device
This commit is contained in:
parent
a30c638e53
commit
2afb87843a
@ -57,7 +57,15 @@ class USBMS(Device):
|
|||||||
else:
|
else:
|
||||||
path = os.path.join(self._card_prefix, self.EBOOK_DIR_CARD)
|
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)
|
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:
|
||||||
@ -72,6 +80,15 @@ class USBMS(Device):
|
|||||||
filepath = os.path.join(path, names.next())
|
filepath = os.path.join(path, names.next())
|
||||||
paths.append(filepath)
|
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)
|
shutil.copy2(infile, filepath)
|
||||||
|
|
||||||
return zip(paths, cycle([on_card]))
|
return zip(paths, cycle([on_card]))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user