diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index eef32594eb..75a67b146c 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -59,7 +59,7 @@ class CYBOOKG3(USBMS): 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: + if not on_card and size > self.free_space()[0] - 2*1024*1024: raise FreeSpaceError(_("There is insufficient free space in main memory")) paths = [] @@ -69,19 +69,28 @@ class CYBOOKG3(USBMS): for infile in files: newpath = path mdata = metadata.next() - + if self.SUPPORTS_SUB_DIRS: if 'tags' in mdata.keys(): for tag in mdata['tags']: - if tag.startswith('/'): + if tag.startswith(('News')): + newpath = os.path.join(newpath, 'news') + newpath = os.path.join(newpath, mdata.get('title', '')) + newpath = os.path.join(newpath, mdata.get('timestamp', '')) + elif tag.startswith('/'): + newpath = path newpath += tag newpath = os.path.normpath(newpath) break + + if newpath == path: + newpath = os.path.join(newpath, mdata.get('authors', '')) + newpath = os.path.join(newpath, mdata.get('title', '')) 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'): @@ -90,7 +99,7 @@ class CYBOOKG3(USBMS): dest = open(filepath, 'wb') shutil.copyfileobj(infile, dest, 10*1024*1024) - dest.flush() + dest.flush() dest.close() else: shutil.copy2(infile, filepath) diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 0c73c4412c..67fbac2fa9 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -37,7 +37,7 @@ class USBMS(Device): SUPPORTS_SUB_DIRS = False def __init__(self, key='-1', log_packets=False, report_progress=None): - Device.__init__(self, key=key, log_packets=log_packets, + Device.__init__(self, key=key, log_packets=log_packets, report_progress=report_progress) def get_device_information(self, end_session=True): @@ -103,10 +103,20 @@ class USBMS(Device): if 'tags' in mdata.keys(): for tag in mdata['tags']: - if tag.startswith('/'): + if tag.startswith(_('News')): + newpath = os.path.join(newpath, 'news') + newpath = os.path.join(newpath, mdata.get('title', '')) + newpath = os.path.join(newpath, mdata.get('timestamp', '')) + break + elif tag.startswith('/'): + newpath = path newpath += tag newpath = os.path.normpath(newpath) break + + if newpath == path: + newpath = os.path.join(newpath, mdata.get('authors', '')) + newpath = os.path.join(newpath, mdata.get('title', '')) if not os.path.exists(newpath): os.makedirs(newpath) diff --git a/src/calibre/ebooks/metadata/pdf.py b/src/calibre/ebooks/metadata/pdf.py index 8ff652c01b..8f73e04050 100644 --- a/src/calibre/ebooks/metadata/pdf.py +++ b/src/calibre/ebooks/metadata/pdf.py @@ -67,6 +67,8 @@ def set_metadata(stream, mi): stream.seek(0) def get_cover(stream): + data = StringIO.StringIO() + try: pdf = PdfFileReader(stream) output = PdfFileWriter() @@ -88,12 +90,12 @@ def get_cover(stream): img = Image.open('%s.jpg' % cover_path) - data = StringIO.StringIO() img.save(data, 'JPEG') - return data.getvalue() except: import traceback traceback.print_exc() + + return data.getvalue() def option_parser(): p = get_parser('pdf') diff --git a/src/calibre/linux.py b/src/calibre/linux.py index 2bd1544e56..427b41ca5f 100644 --- a/src/calibre/linux.py +++ b/src/calibre/linux.py @@ -58,10 +58,10 @@ entry_points = { 'calibredb = calibre.library.cli:main', 'calibre-fontconfig = calibre.utils.fontconfig:main', 'calibre-parallel = calibre.parallel:main', - 'calibre-customize = calibre.customize.ui:main', - 'pdftrim = calibre.ebooks.pdf.pdftrim:main' , + 'calibre-customize = calibre.customize.ui:main', + 'pdftrim = calibre.ebooks.pdf.pdftrim:main' , 'any2pdf = calibre.ebooks.pdf.from_any:main', - ], + ], 'gui_scripts' : [ __appname__+' = calibre.gui2.main:main', 'lrfviewer = calibre.gui2.lrf_renderer.main:main',