From e7270d2db88f36e4e921316e7f50b9e1bcef49b9 Mon Sep 17 00:00:00 2001 From: John Schember Date: Tue, 3 Mar 2009 20:00:11 -0500 Subject: [PATCH] USBMS: Devices that support subdirs use a similar layout as Calibre on the computer --- src/calibre/devices/cybookg3/driver.py | 13 +++++++++++-- src/calibre/devices/usbms/driver.py | 18 +++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index eef32594eb..6a77c09479 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -69,14 +69,23 @@ 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) diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index abdf2f0d81..a088bf1a32 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -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) @@ -166,14 +176,8 @@ class USBMS(Device): def get_file(self, path, outfile, end_session=True): path = self.munge_path(path) -<<<<<<< TREE - src = open(path, 'rb') - shutil.copyfileobj(src, outfile, 10*1024*1024) - src.close() -======= with open(path, 'rb') as src: shutil.copyfileobj(src, outfile, 10*1024*1024) ->>>>>>> MERGE-SOURCE def put_file(self, infile, path, replace_file=False, end_session=True): path = self.munge_path(path)