Revision 606f5b54 kamaki/cli/commands/pithos.py
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
1054 | 1054 |
to longer path).""" |
1055 | 1055 |
ret = [] |
1056 | 1056 |
try: |
1057 |
obj = self.client.get_object_info( |
|
1058 |
self.path, version=self['object_version']) |
|
1059 |
obj.setdefault('name', self.path.strip('/')) |
|
1057 |
if self.path: |
|
1058 |
obj = self.client.get_object_info( |
|
1059 |
self.path, version=self['object_version']) |
|
1060 |
obj.setdefault('name', self.path.strip('/')) |
|
1061 |
else: |
|
1062 |
obj = None |
|
1060 | 1063 |
except ClientError as ce: |
1061 | 1064 |
if ce.status in (404, ): |
1062 | 1065 |
raiseCLIError(ce, details=[ |
1063 |
'To download an object, the object must exist either as a'
|
|
1064 |
' file or as a directory.',
|
|
1066 |
'To download an object, it must exist either as a file or'
|
|
1067 |
' as a directory.', |
|
1065 | 1068 |
'For example, to download everything under prefix/ the ' |
1066 | 1069 |
'directory "prefix" must exist.', |
1067 | 1070 |
'To see if an remote object is actually there:', |
... | ... | |
1077 | 1080 |
self.container)]) |
1078 | 1081 |
raise |
1079 | 1082 |
rpath = self.path.strip('/') |
1080 |
local_path = local_path[-1:] if (
|
|
1081 |
local_path.endswith('/')) else local_path
|
|
1083 |
if local_path and self.path and local_path.endswith('/'):
|
|
1084 |
local_path = local_path[-1:]
|
|
1082 | 1085 |
|
1083 |
if self._is_dir(obj): |
|
1086 |
if (not obj) or self._is_dir(obj):
|
|
1084 | 1087 |
if self['recursive']: |
1088 |
if not (self.path or local_path.endswith('/')): |
|
1089 |
# Download the whole container |
|
1090 |
local_path = '' if local_path in ('.', ) else local_path |
|
1091 |
local_path = '%s/' % (local_path or self.container) |
|
1092 |
obj = obj or dict( |
|
1093 |
name='', content_type='application/directory') |
|
1085 | 1094 |
dirs, files = [obj, ], [] |
1086 | 1095 |
objects = self.client.container_get( |
1087 |
path=self.path or '/',
|
|
1096 |
path=self.path, |
|
1088 | 1097 |
if_modified_since=self['modified_since_date'], |
1089 | 1098 |
if_unmodified_since=self['unmodified_since_date']) |
1090 |
for obj in objects.json:
|
|
1091 |
(dirs if self._is_dir(obj) else files).append(obj)
|
|
1099 |
for o in objects.json: |
|
1100 |
(dirs if self._is_dir(o) else files).append(o)
|
|
1092 | 1101 |
|
1093 | 1102 |
# Put the directories on top of the list |
1094 | 1103 |
for dpath in sorted(['%s%s' % ( |
... | ... | |
1124 | 1133 |
self.arguments['resume'].parsed_name)]) |
1125 | 1134 |
else: |
1126 | 1135 |
ret.append((opath, lpath, None)) |
1127 |
else:
|
|
1136 |
elif self.path:
|
|
1128 | 1137 |
raise CLIError( |
1129 | 1138 |
'Remote object /%s/%s is a directory' % ( |
1130 | 1139 |
self.container, local_path), |
1131 | 1140 |
details=['Use %s to download directories' % '/'.join( |
1132 | 1141 |
self.arguments['recursive'].parsed_name)]) |
1142 |
else: |
|
1143 |
parsed_name = '/'.join(self.arguments['recursive'].parsed_name) |
|
1144 |
raise CLIError( |
|
1145 |
'Cannot download container %s' % self.container, |
|
1146 |
details=[ |
|
1147 |
'Use %s to download containers' % parsed_name, |
|
1148 |
' [kamaki] file download %s /%s [LOCAL_PATH]' % ( |
|
1149 |
parsed_name, self.container)]) |
|
1133 | 1150 |
else: |
1134 | 1151 |
# Remote object is just a file |
1135 | 1152 |
if path.exists(local_path) and not self['resume']: |
... | ... | |
1150 | 1167 |
@errors.pithos.container |
1151 | 1168 |
@errors.pithos.object_path |
1152 | 1169 |
@errors.pithos.local_path |
1170 |
@errors.pithos.local_path_download |
|
1153 | 1171 |
def _run(self, local_path): |
1154 | 1172 |
self.client.MAX_THREADS = self['max_threads'] or 5 |
1155 | 1173 |
progress_bar = None |
Also available in: Unified diff