USBMS: Devices that support subdirs use a similar layout as Calibre on the computer

This commit is contained in:
John Schember 2009-03-03 20:00:11 -05:00
parent 8d2620e516
commit e7270d2db8
2 changed files with 22 additions and 9 deletions

View File

@ -73,11 +73,20 @@ class CYBOOKG3(USBMS):
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)

View File

@ -103,11 +103,21 @@ 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)