Commit a298f2ab authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Add options to store_delete

parent 09967245
......@@ -260,14 +260,18 @@ class PithosClient(StorageClient):
success = kwargs.pop('success', 202)
return, *args, success=success, **kwargs)
def container_delete(self, until=None, *args, **kwargs):
def container_delete(self, until=None, delimiter=None, *args, **kwargs):
""" Full Pithos+ DELETE at container level
--- request parameters ---
@param until (timestamp string): if defined, container is purged up to that time
path=path4url(self.account, self.container)
path += '' if until is None else params4url(dict(until=until))
param_dict = {}
if until is not None:
if delimiter is not None:
param_dict['delimiter'] = delimiter
path=path4url(self.account, self.container)+params4url(param_dict)
success = kwargs.pop('success', 204)
return self.delete(path, success=success)
......@@ -564,14 +568,18 @@ class PithosClient(StorageClient):
success=kwargs.pop('success', (202, 204))
return, *args, success=success, **kwargs)
def object_delete(self, object, until=None, *args, **kwargs):
def object_delete(self, object, until=None, delimiter=None, *args, **kwargs):
""" Full Pithos+ DELETE at object level
--- request parameters ---
@param until (string): Optional timestamp
path = path4url(self.account, self.container, object)
path += '' if until is None else params4url(dict(until=until))
param_dict = {}
if until is not None:
if delimiter is not None:
param_dict['delimiter'] = delimiter
path = path4url(self.account, self.container, object)+params4url(param_dict)
success = kwargs.pop('success', 204)
return self.delete(path, *args, success=success, **kwargs)
......@@ -775,6 +783,14 @@ class PithosClient(StorageClient):
r = self.account_get()
return r.json
def del_container(self, until=None, delimiter=None):
r = self.container_delete(until=until, delimiter=delimiter, success=(204, 404, 409))
if r.status_code == 404:
raise ClientError('Container "%s" does not exist'%self.container, r.status_code)
elif r.status_code == 409:
raise ClientError('Container "%s" is not empty'%self.container, r.status_code)
def get_container_versioning(self, container):
return filter_in(self.get_container_info(container), 'X-Container-Policy-Versioning')
......@@ -800,6 +816,10 @@ class PithosClient(StorageClient):
def set_container_versioning(self, versioning):
self.container_post(update=True, versioning=versioning)
def del_object(self, obj, until=None, delimiter=None):
self.object_delete(obj, until=until, delimiter=delimiter)
def set_object_meta(self, object, metapairs):
assert(type(metapairs) is dict)
self.object_post(object, update=True, metadata=metapairs)
......@@ -414,14 +414,49 @@ class store_download(_store_container_command):
class store_delete(_store_container_command):
"""Delete a container [or an object]"""
def update_parser(self, parser):
parser.add_argument('--until', action='store', dest='until', default=None,
help='remove history until that date')
parser.add_argument('--format', action='store', dest='format', default='%d/%m/%Y %H:%M:%S',
help='format to parse until date (default: d/m/Y H:M:S)')
parser.add_argument('--delimiter', action='store', dest='delimiter',
help='mass delete objects with path staring with <object><delimiter>')
parser.add_argument('-r', action='store_true', dest='recursive', default=False,
help='empty dir or container and delete (if dir)')
def getuntil(self, orelse=None):
if hasattr(self.args, 'until'):
import time
until = getattr(self.args, 'until')
if until is None:
return None
format = getattr(self.args, 'format')
t = time.strptime(until, format)
except ValueError as err:
raise CLIError(message='in --until: '+unicode(err), importance=1)
return int(time.mktime(t))
return orelse
def getdelimiter(self, orelse=None):
dlm = getattr(self.args, 'delimiter')
if dlm is None:
return '/' if getattr(self.args, 'recursive') else orelse
except AttributeError:
return orelse
return dlm
def main(self, container____path__):
super(self.__class__, self).main(container____path__)
if self.path is None:
self.client.del_container(until=self.getuntil(), delimiter=self.getdelimiter())
self.client.del_object(self.path, until=self.getuntil(),
except ClientError as err:
Markdown is supported
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