import os
import re
from threading import Event
-from django.utils.http import urlunquote
+from django.utils.http import urlunquote
from django.utils.timezone import localtime, UTC
from gridftp import FTPClient, Buffer, HandleAttr, OperationAttr
class FTPError(Exception):
- pass
+ def __init__(self, message, verbose=None, *args, **kwargs):
+ super(FTPError, self).__init__(message, *args, **kwargs)
+
+ self.verbose = verbose
class FTPOperation:
self._end.clear()
if self._error is not None:
- # TODO logging
- print 'GridFTP ERROR:', self._error
-
match = re.search(r'A system call failed: (.*)$', self._error.replace('\r\n', '\n'), re.MULTILINE)
msg = match.groups()[0] if match else "Unknown error"
- raise FTPError(msg)
+ raise FTPError(msg, self._error)
def listing(self, url):
self.cli.verbose_list(url, self._done, None, self.op_attr)
for attr in attrs.split(';'):
try:
key, value = attr.split('=', 1)
- attrs_dict[key] = value
except ValueError:
- pass
+ key, value = attr, ''
+
+ attrs_dict[key] = value
yield {
'name': name,
- 'type': 'directory' if attrs_dict['Type'] == 'dir' else 'file',
+ 'type': 'directory' if attrs_dict['Type'].endswith('dir') else 'file',
'size': int(attrs_dict['Size']),
'date': localtime(datetime.strptime(attrs_dict['Modify'], "%Y%m%d%H%M%S").replace(tzinfo=UTC())),
}