Revision 20206179 kamaki/cli/commands/pithos.py
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
163 | 163 |
|
164 | 164 |
|
165 | 165 |
@command(file_cmds) |
166 |
class file_info(_pithos_container, _optional_json): |
|
167 |
"""Get information/details about a file""" |
|
168 |
|
|
169 |
arguments = dict( |
|
170 |
object_version=ValueArgument( |
|
171 |
'download a file of a specific version', '--object-version'), |
|
172 |
hashmap=FlagArgument( |
|
173 |
'Get file hashmap instead of details', '--hashmap'), |
|
174 |
matching_etag=ValueArgument( |
|
175 |
'show output if ETags match', '--if-match'), |
|
176 |
non_matching_etag=ValueArgument( |
|
177 |
'show output if ETags DO NOT match', '--if-none-match'), |
|
178 |
modified_since_date=DateArgument( |
|
179 |
'show output modified since then', '--if-modified-since'), |
|
180 |
unmodified_since_date=DateArgument( |
|
181 |
'show output unmodified since then', '--if-unmodified-since'), |
|
182 |
permissions=FlagArgument( |
|
183 |
'show only read/write permissions', '--permissions') |
|
184 |
) |
|
185 |
|
|
186 |
@errors.generic.all |
|
187 |
@errors.pithos.connection |
|
188 |
@errors.pithos.container |
|
189 |
@errors.pithos.object_path |
|
190 |
def _run(self): |
|
191 |
if self['hashmap']: |
|
192 |
r = self.client.get_object_hashmap( |
|
193 |
self.path, |
|
194 |
version=self['object_version'], |
|
195 |
if_match=self['matching_etag'], |
|
196 |
if_none_match=self['non_matching_etag'], |
|
197 |
if_modified_since=self['modified_since_date'], |
|
198 |
if_unmodified_since=self['unmodified_since_date']) |
|
199 |
elif self['permissions']: |
|
200 |
r = self.client.get_object_sharing(self.path) |
|
201 |
else: |
|
202 |
r = self.client.get_object_info( |
|
203 |
self.path, version=self['object_version']) |
|
204 |
self._print(r, self.print_dict) |
|
205 |
|
|
206 |
def main(self, path_or_url): |
|
207 |
super(self.__class__, self)._run(path_or_url) |
|
208 |
self._run() |
|
209 |
|
|
210 |
|
|
211 |
@command(file_cmds) |
|
166 | 212 |
class file_list(_pithos_container, _optional_json, _name_filter): |
167 | 213 |
"""List all objects in a container or a directory object""" |
168 | 214 |
|
... | ... | |
247 | 293 |
|
248 | 294 |
|
249 | 295 |
@command(file_cmds) |
296 |
class file_modify(_pithos_container): |
|
297 |
"""Modify the attributes of a file or directory object""" |
|
298 |
|
|
299 |
arguments = dict( |
|
300 |
publish=FlagArgument( |
|
301 |
'Make an object public (returns the public URL)', '--publish'), |
|
302 |
unpublish=FlagArgument( |
|
303 |
'Make an object unpublic', '--unpublish'), |
|
304 |
uuid_for_read_permission=RepeatableArgument( |
|
305 |
'Give read access to user/group (can be repeated, accumulative). ' |
|
306 |
'Format for users: UUID . Format for groups: UUID:GROUP . ' |
|
307 |
'Use * for all users/groups', '--read-permission'), |
|
308 |
uuid_for_write_permission=RepeatableArgument( |
|
309 |
'Give write access to user/group (can be repeated, accumulative). ' |
|
310 |
'Format for users: UUID . Format for groups: UUID:GROUP . ' |
|
311 |
'Use * for all users/groups', '--write-permission'), |
|
312 |
no_permissions=FlagArgument('Remove permissions', '--no-permissions') |
|
313 |
) |
|
314 |
required = [ |
|
315 |
'publish', 'unpublish', 'uuid_for_read_permission', |
|
316 |
'uuid_for_write_permission', 'no_permissions'] |
|
317 |
|
|
318 |
@errors.generic.all |
|
319 |
@errors.pithos.connection |
|
320 |
@errors.pithos.container |
|
321 |
@errors.pithos.object_path |
|
322 |
def _run(self): |
|
323 |
if self['publish']: |
|
324 |
self.writeln(self.client.publish_object(self.path)) |
|
325 |
if self['unpublish']: |
|
326 |
self.client.unpublish_object(self.path) |
|
327 |
if self['uuid_for_read_permission'] or self[ |
|
328 |
'uuid_for_write_permission']: |
|
329 |
perms = self.client.get_object_sharing(self.path) |
|
330 |
read, write = perms.get('read', ''), perms.get('write', '') |
|
331 |
read = read.split(',') if read else [] |
|
332 |
write = write.split(',') if write else [] |
|
333 |
read += self['uuid_for_read_permission'] |
|
334 |
write += self['uuid_for_write_permission'] |
|
335 |
self.client.set_object_sharing( |
|
336 |
self.path, read_permission=read, write_permission=write) |
|
337 |
self.print_dict(self.client.get_object_sharing(self.path)) |
|
338 |
if self['no_permissions']: |
|
339 |
self.client.del_object_sharing(self.path) |
|
340 |
|
|
341 |
def main(self, path_or_url): |
|
342 |
super(self.__class__, self)._run(path_or_url) |
|
343 |
if self['publish'] and self['unpublish']: |
|
344 |
raise CLIInvalidArgument( |
|
345 |
'Arguments %s and %s cannot be used together' % ( |
|
346 |
'/'.join(self.arguments['publish'].parsed_name), |
|
347 |
'/'.join(self.arguments['publish'].parsed_name))) |
|
348 |
if self['no_permissions'] and ( |
|
349 |
self['uuid_for_read_permission'] or self[ |
|
350 |
'uuid_for_write_permission']): |
|
351 |
raise CLIInvalidArgument( |
|
352 |
'%s cannot be used with other permission arguments' % '/'.join( |
|
353 |
self.arguments['no_permissions'].parsed_name)) |
|
354 |
self._run() |
|
355 |
|
|
356 |
|
|
357 |
@command(file_cmds) |
|
250 | 358 |
class file_create(_pithos_container, _optional_output_cmd): |
251 | 359 |
"""Create an empty file""" |
252 | 360 |
|
... | ... | |
285 | 393 |
self._run() |
286 | 394 |
|
287 | 395 |
|
396 |
@command(file_cmds) |
|
397 |
class file_delete(_pithos_container, _optional_output_cmd): |
|
398 |
"""Delete a file or directory object""" |
|
399 |
|
|
400 |
arguments = dict( |
|
401 |
until_date=DateArgument('remove history until then', '--until'), |
|
402 |
yes=FlagArgument('Do not prompt for permission', '--yes'), |
|
403 |
recursive=FlagArgument( |
|
404 |
'If a directory, empty first', ('-r', '--recursive')), |
|
405 |
delimiter=ValueArgument( |
|
406 |
'delete objects prefixed with <object><delimiter>', '--delimiter') |
|
407 |
) |
|
408 |
|
|
409 |
@errors.generic.all |
|
410 |
@errors.pithos.connection |
|
411 |
@errors.pithos.container |
|
412 |
@errors.pithos.object_path |
|
413 |
def _run(self): |
|
414 |
if self.path: |
|
415 |
if self['yes'] or self.ask_user( |
|
416 |
'Delete /%s/%s ?' % (self.container, self.path)): |
|
417 |
self._optional_output(self.client.del_object( |
|
418 |
self.path, |
|
419 |
until=self['until_date'], |
|
420 |
delimiter='/' if self['recursive'] else self['delimiter'])) |
|
421 |
else: |
|
422 |
self.error('Aborted') |
|
423 |
else: |
|
424 |
raiseCLIError('Nothing to delete', details=[ |
|
425 |
'Format for path or url: [/CONTAINER/]path']) |
|
426 |
|
|
427 |
def main(self, path_or_url): |
|
428 |
super(self.__class__, self)._run(path_or_url) |
|
429 |
self._run() |
|
430 |
|
|
431 |
|
|
288 | 432 |
class _source_destination(_pithos_container, _optional_output_cmd): |
289 | 433 |
|
290 | 434 |
sd_arguments = dict( |
... | ... | |
624 | 768 |
'specify objects presentation style', '--content-disposition'), |
625 | 769 |
content_type=ValueArgument('specify content type', '--content-type'), |
626 | 770 |
uuid_for_read_permission=RepeatableArgument( |
627 |
'Give read access to a user of group (can be repeated)', |
|
771 |
'Give read access to a user or group (can be repeated) ' |
|
772 |
'Use * for all users', |
|
628 | 773 |
'--read-permission'), |
629 | 774 |
uuid_for_write_permission=RepeatableArgument( |
630 |
'Give write access to a user of group (can be repeated)', |
|
775 |
'Give write access to a user or group (can be repeated) ' |
|
776 |
'Use * for all users', |
|
631 | 777 |
'--write-permission'), |
632 | 778 |
public=FlagArgument('make object publicly accessible', '--public'), |
633 | 779 |
overwrite=FlagArgument('Force (over)write', ('-f', '--force')), |
... | ... | |
891 | 1037 |
'show output iff remote file is unmodified since then', |
892 | 1038 |
'--if-unmodified-since'), |
893 | 1039 |
object_version=ValueArgument( |
894 |
'download a file of a specific version', |
|
895 |
('-O', '--object-version')), |
|
1040 |
'download a file of a specific version', '--object-version'), |
|
896 | 1041 |
max_threads=IntArgument('default: 5', '--threads'), |
897 | 1042 |
progress_bar=ProgressBarArgument( |
898 | 1043 |
'do not show progress bar', ('-N', '--no-progress-bar'), |
Also available in: Unified diff