projects
/
qcg-portal.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6ba99e0
)
ftp exists and mkdir with parents methods
author
Maciej Tronowski
<mtro@man.poznan.pl>
Tue, 28 Apr 2015 13:35:12 +0000
(15:35 +0200)
committer
Maciej Tronowski
<mtro@man.poznan.pl>
Tue, 28 Apr 2015 13:35:12 +0000
(15:35 +0200)
filex/ftp.py
patch
|
blob
|
history
diff --git
a/filex/ftp.py
b/filex/ftp.py
index
af06c27
..
3ccd8c6
100644
(file)
--- a/
filex/ftp.py
+++ b/
filex/ftp.py
@@
-4,6
+4,7
@@
from itertools import chain
import os
import re
from threading import Event
import os
import re
from threading import Event
+from urlparse import urlparse, urlunparse
from django.utils.http import urlunquote
from django.utils.timezone import localtime, UTC
from django.utils.http import urlunquote
from django.utils.timezone import localtime, UTC
@@
-142,6
+143,18
@@
class FTPOperation:
return data
return data
+ def exists(self, url):
+ self.cli.exists(url, self._done, None, self.op_attr)
+
+ try:
+ self.wait()
+ except FTPError as e:
+ if 'No such file or directory' in e.message:
+ return False
+ raise
+ else:
+ return True
+
def delete(self, url):
self.cli.delete(url, self._done, None, self.op_attr)
def delete(self, url):
self.cli.delete(url, self._done, None, self.op_attr)
@@
-152,7
+165,16
@@
class FTPOperation:
self.wait()
self.wait()
- def mkdir(self, url):
+ def mkdir(self, url, parents=False):
+ if parents:
+ if self.exists(url):
+ return
+
+ u = urlparse(url)
+ parent_url = urlunparse((u.scheme, u.netloc, os.path.dirname(os.path.normpath(u.path)), '', '', ''))
+
+ self.mkdir(parent_url, parents=True)
+
self.cli.mkdir(url, self._done, None, self.op_attr)
self.wait()
self.cli.mkdir(url, self._done, None, self.op_attr)
self.wait()