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
55c7c589
Commit
55c7c589
authored
Jan 29, 2013
by
Stavros Sachtouris
Browse files
Merge branch 'feature-store' into develop
parents
f2b26be6
ae99b37d
Changes
1
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/commands/pithos_cli.py
View file @
55c7c589
...
...
@@ -987,7 +987,14 @@ class store_cat(_store_container_command):
@
command
(
pithos_cmds
)
class
store_download
(
_store_container_command
):
"""Download remote object as local file"""
"""Download remote object as local file
If local destination is a directory:
* download <container>:<path> <local dir>
will download all files on <container> prefixed as <path>,
to <local dir>/<full path>
* download <container>:<path> <local dir> --exact-match
will download only one file, exactly matching <path>
"""
arguments
=
dict
(
resume
=
FlagArgument
(
'Resume instead of overwrite'
,
'--resume'
),
...
...
@@ -1009,14 +1016,35 @@ class store_download(_store_container_command):
progress_bar
=
ProgressBarArgument
(
'do not show progress bar'
,
'--no-progress-bar'
,
default
=
False
)
default
=
False
),
exact_match
=
FlagArgument
(
'Download only the object that matches path exactly'
,
'--exact-match'
)
)
def
_output_stream
(
self
,
local_path
):
def
_output_stream
s
(
self
,
local_path
):
if
local_path
is
None
:
return
stdout
return
open
(
path
.
abspath
(
local_path
),
'rwb+'
if
self
[
'resume'
]
else
'wb+'
)
return
[(
stdout
,
self
.
path
)]
outpath
=
path
.
abspath
(
local_path
)
wmode
=
'rwb+'
if
self
[
'resume'
]
else
'wb+'
try
:
return
[(
open
(
outpath
,
wmode
),
self
.
path
)]
except
IOError
as
ioe
:
if
'is a directory'
in
(
'%s'
%
ioe
).
lower
():
if
self
[
'exact_match'
]:
return
[(
open
(
'%s/%s'
%
(
outpath
,
self
.
path
),
wmode
),
self
.
path
)]
remotes
=
self
.
client
.
container_get
(
prefix
=
self
.
path
,
if_modified_since
=
self
[
'if_modified_since'
],
if_unmodified_since
=
self
[
'if_unmodified_since'
])
return
[(
open
(
'%s/%s'
%
(
outpath
,
remote
[
'name'
]),
wmode
),
remote
[
'name'
]
)
for
remote
in
remotes
.
json
]
raise
@
errors
.
generic
.
all
@
errors
.
pithos
.
connection
...
...
@@ -1024,24 +1052,34 @@ class store_download(_store_container_command):
@
errors
.
pithos
.
object_path
@
errors
.
pithos
.
local_path
def
_run
(
self
,
local_path
):
out
=
self
.
_output_stream
(
local_path
)
streams
=
self
.
_output_stream
s
(
local_path
)
poolsize
=
self
[
'poolsize'
]
if
poolsize
:
self
.
client
.
POOL_SIZE
=
int
(
poolsize
)
try
:
(
progress_bar
,
download_cb
)
=
self
.
_safe_progress_bar
(
'Downloading'
)
self
.
client
.
download_object
(
if
not
streams
:
raiseCLIError
(
'No objects prefixed as %s on container %s'
%
(
self
.
path
,
out
,
download_cb
=
download_cb
,
range
=
self
[
'range'
],
version
=
self
[
'object_version'
],
if_match
=
self
[
'if_match'
],
resume
=
self
[
'resume'
],
if_none_match
=
self
[
'if_none_match'
],
if_modified_since
=
self
[
'if_modified_since'
],
if_unmodified_since
=
self
[
'if_unmodified_since'
])
self
.
container
))
try
:
for
out
,
rpath
in
streams
:
print
(
'
\n
From %s:%s to %s/%s'
%
(
self
.
container
,
rpath
,
local_path
,
rpath
))
(
progress_bar
,
download_cb
)
=
self
.
_safe_progress_bar
(
'Downloading'
)
self
.
client
.
download_object
(
rpath
,
out
,
download_cb
=
download_cb
,
range
=
self
[
'range'
],
version
=
self
[
'object_version'
],
if_match
=
self
[
'if_match'
],
resume
=
self
[
'resume'
],
if_none_match
=
self
[
'if_none_match'
],
if_modified_since
=
self
[
'if_modified_since'
],
if_unmodified_since
=
self
[
'if_unmodified_since'
])
except
KeyboardInterrupt
:
from
threading
import
enumerate
as
activethreads
stdout
.
write
(
'
\n
Finishing active threads '
)
...
...
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