Commit 3da2d5c1 authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Gracefully handle files with names that break csv.reader

* If encountered, sift_drive will abandon looking at all sibling and
* child items related to the problematic one, and continue on after
* reporting the error
parent d511334f
...@@ -88,29 +88,37 @@ class Sifter: ...@@ -88,29 +88,37 @@ class Sifter:
delimiter=',', delimiter=',',
quotechar='"' quotechar='"'
) )
for child in children: try:
if not hasattr(self, 'ignore_owner'): for child in children:
if self.account != child['owners.0.emailAddress']: if not hasattr(self, 'ignore_owner'):
continue if self.account != child['owners.0.emailAddress']:
continue
data = {
'owner': child['owners.0.emailAddress'], data = {
'name': child['title'], 'owner': child['owners.0.emailAddress'],
'id': child['id'], 'name': child['title'],
'link': child['alternateLink'], 'id': child['id'],
'parent': '\\'.join(self.parent) 'link': child['alternateLink'],
} 'parent': '\\'.join(self.parent)
}
if in_private or child['title'].lower() in self.omit_folders:
self.private_files[child['id']] = data _title = child['title'].lower()
if 'folder' in child['mimeType']: if in_private or _title in self.omit_folders:
self.parent.append(child['title']) self.private_files[child['id']] = data
self.sift(child['id'], in_private=True) if 'folder' in child['mimeType']:
else: self.parent.append(child['title'])
self.transfer_files[child['id']] = data self.sift(child['id'], in_private=True)
if 'folder' in child['mimeType']: else:
self.parent.append(child['title']) self.transfer_files[child['id']] = data
self.sift(child['id'], in_private=False) if 'folder' in child['mimeType']:
self.parent.append(child['title'])
self.sift(child['id'], in_private=False)
except csv.Error:
self.logger.warning(
'Failed reading files in {}.'
'Check for bad file title(s)?'.format(self.parent),
extra={'entity': self.account}
)
self.parent.pop() self.parent.pop()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment