Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
a298f2ab
Commit
a298f2ab
authored
Aug 09, 2012
by
Stavros Sachtouris
Browse files
Add options to store_delete
parent
09967245
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/clients/pithos.py
View file @
a298f2ab
...
...
@@ -260,14 +260,18 @@ class PithosClient(StorageClient):
success
=
kwargs
.
pop
(
'success'
,
202
)
return
self
.
post
(
path
,
*
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
"""
self
.
assert_container
()
path
=
path4url
(
self
.
account
,
self
.
container
)
path
+=
''
if
until
is
None
else
params4url
(
dict
(
until
=
until
))
param_dict
=
{}
if
until
is
not
None
:
param_dict
[
'until'
]
=
until
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
self
.
post
(
path
,
*
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
"""
self
.
assert_container
()
path
=
path4url
(
self
.
account
,
self
.
container
,
object
)
path
+=
''
if
until
is
None
else
params4url
(
dict
(
until
=
until
))
param_dict
=
{}
if
until
is
not
None
:
param_dict
[
'until'
]
=
until
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
):
self
.
assert_container
()
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
.
assert_container
()
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
)
...
...
kamaki/clients/pithos_cli.py
View file @
a298f2ab
...
...
@@ -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'
,
default
=
None
,
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'
)
try
:
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
):
try
:
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__
)
try
:
if
self
.
path
is
None
:
self
.
client
.
del
ete
_container
(
self
.
container
)
self
.
client
.
del_container
(
until
=
self
.
getuntil
(),
delimiter
=
self
.
getdelimiter
()
)
else
:
self
.
client
.
delete_object
(
self
.
path
)
#self.client.delete_object(self.path)
self
.
client
.
del_object
(
self
.
path
,
until
=
self
.
getuntil
(),
delimiter
=
self
.
getdelimiter
())
except
ClientError
as
err
:
raiseCLIError
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment