Create sub directories based on metadata when sending books to devices that support sub directories

This commit is contained in:
Kovid Goyal 2009-03-03 17:35:22 -08:00
commit 9883f60ca5
4 changed files with 33 additions and 12 deletions

View File

@ -73,11 +73,20 @@ class CYBOOKG3(USBMS):
if self.SUPPORTS_SUB_DIRS: if self.SUPPORTS_SUB_DIRS:
if 'tags' in mdata.keys(): if 'tags' in mdata.keys():
for tag in mdata['tags']: 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 += tag
newpath = os.path.normpath(newpath) newpath = os.path.normpath(newpath)
break 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): if not os.path.exists(newpath):
os.makedirs(newpath) os.makedirs(newpath)

View File

@ -103,11 +103,21 @@ class USBMS(Device):
if 'tags' in mdata.keys(): if 'tags' in mdata.keys():
for tag in mdata['tags']: 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 += tag
newpath = os.path.normpath(newpath) newpath = os.path.normpath(newpath)
break 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): if not os.path.exists(newpath):
os.makedirs(newpath) os.makedirs(newpath)

View File

@ -67,6 +67,8 @@ def set_metadata(stream, mi):
stream.seek(0) stream.seek(0)
def get_cover(stream): def get_cover(stream):
data = StringIO.StringIO()
try: try:
pdf = PdfFileReader(stream) pdf = PdfFileReader(stream)
output = PdfFileWriter() output = PdfFileWriter()
@ -88,13 +90,13 @@ def get_cover(stream):
img = Image.open('%s.jpg' % cover_path) img = Image.open('%s.jpg' % cover_path)
data = StringIO.StringIO()
img.save(data, 'JPEG') img.save(data, 'JPEG')
return data.getvalue()
except: except:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
return data.getvalue()
def option_parser(): def option_parser():
p = get_parser('pdf') p = get_parser('pdf')
p.remove_option('--category') p.remove_option('--category')

View File

@ -59,9 +59,9 @@ entry_points = {
'calibre-fontconfig = calibre.utils.fontconfig:main', 'calibre-fontconfig = calibre.utils.fontconfig:main',
'calibre-parallel = calibre.parallel:main', 'calibre-parallel = calibre.parallel:main',
'calibre-customize = calibre.customize.ui:main', 'calibre-customize = calibre.customize.ui:main',
'pdftrim = calibre.ebooks.pdf.pdftrim:main' , 'pdftrim = calibre.ebooks.pdf.pdftrim:main' ,
'any2pdf = calibre.ebooks.pdf.from_any:main', 'any2pdf = calibre.ebooks.pdf.from_any:main',
], ],
'gui_scripts' : [ 'gui_scripts' : [
__appname__+' = calibre.gui2.main:main', __appname__+' = calibre.gui2.main:main',
'lrfviewer = calibre.gui2.lrf_renderer.main:main', 'lrfviewer = calibre.gui2.lrf_renderer.main:main',