PRS505/700: Put books in author/title dir structure and use USBMS style / tag paths.

This commit is contained in:
John Schember 2009-04-16 19:10:38 -04:00
parent 7814dda6d8
commit 4c6599fd45
2 changed files with 43 additions and 19 deletions

View File

@ -77,22 +77,21 @@ class CYBOOKG3(USBMS):
newpath = path newpath = path
mdata = metadata.next() mdata = metadata.next()
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(_('News')):
if tag.startswith(_('News')): newpath = os.path.join(newpath, 'news')
newpath = os.path.join(newpath, 'news') newpath = os.path.join(newpath, mdata.get('title', ''))
newpath = os.path.join(newpath, mdata.get('title', '')) newpath = os.path.join(newpath, mdata.get('timestamp', ''))
newpath = os.path.join(newpath, mdata.get('timestamp', '')) elif tag.startswith('/'):
elif tag.startswith('/'): newpath = path
newpath = path newpath += tag
newpath += tag newpath = os.path.normpath(newpath)
newpath = os.path.normpath(newpath) break
break
if newpath == path: if newpath == path:
newpath = os.path.join(newpath, mdata.get('authors', _('Unknown'))) newpath = os.path.join(newpath, mdata.get('authors', _('Unknown')))
newpath = os.path.join(newpath, mdata.get('title', _('Unknown'))) newpath = os.path.join(newpath, mdata.get('title', _('Unknown')))
if not os.path.exists(newpath): if not os.path.exists(newpath):
os.makedirs(newpath) os.makedirs(newpath)

View File

@ -119,19 +119,44 @@ class PRS505(CLI, Device):
paths, ctimes = [], [] paths, ctimes = [], []
names = iter(names) names = iter(names)
metadata = iter(metadata)
for infile in files: for infile in files:
close = False close = False
if not hasattr(infile, 'read'): if not hasattr(infile, 'read'):
infile, close = open(infile, 'rb'), True infile, close = open(infile, 'rb'), True
infile.seek(0) infile.seek(0)
name = names.next()
paths.append(os.path.join(path, name)) newpath = path
if not os.path.exists(os.path.dirname(paths[-1])): mdata = metadata.next()
os.makedirs(os.path.dirname(paths[-1]))
if 'tags' in mdata.keys():
for tag in mdata['tags']:
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', _('Unknown')))
newpath = os.path.join(newpath, mdata.get('title', _('Unknown')))
if not os.path.exists(newpath):
os.makedirs(newpath)
filepath = os.path.join(newpath, names.next())
paths.append(filepath)
self.put_file(infile, paths[-1], replace_file=True) self.put_file(infile, paths[-1], replace_file=True)
if close: if close:
infile.close() infile.close()
ctimes.append(os.path.getctime(paths[-1])) ctimes.append(os.path.getctime(paths[-1]))
return zip(paths, sizes, ctimes, cycle([on_card])) return zip(paths, sizes, ctimes, cycle([on_card]))
@classmethod @classmethod