Skip to content

Commit

Permalink
Merge pull request kubeedge#221 from JimmyYang20/fixbug-init-container
Browse files Browse the repository at this point in the history
storage initializer:  keep dir name in s3 download
  • Loading branch information
kubeedge-bot authored Oct 29, 2021
2 parents a293a29 + 17cbfc1 commit b1ec13e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 6 additions & 2 deletions scripts/storage-initializer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ python3 download.py s3://models/classification/model.tar.gz /tmp/models/
export S3_ENDPOINT_URL=https://play.min.io
export ACCESS_KEY_ID=Q3AM3UQ867SPQQA43P2F
export SECRET_ACCESS_KEY=zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG
python3 download.py s3://datasets/mnist /tmp/mnist
# we then download the content of mnist directory into /tmp/mnist/

python3 download.py s3://datasets/mnist/1.jpg /tmp
# we then download the file 1.jpg into /tmp, and result is /tmp/1.jpg.

python3 download.py s3://datasets/mnist /tmp
# we then download the folder mnist into /tmp, and result is /tmp/mnist.

```
3. http server:
Expand Down
17 changes: 16 additions & 1 deletion scripts/storage-initializer/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ def download_s3_with_multi_files(download_files,


def _download_s3(client, uri, out_dir):
"""
The function downloads specified file or folder to local directory address.
this function supports:
1. when downloading the specified file, keep the name of the file itself.
2. when downloading the specified folder, keep the name of the folder itself.
Parameters:
client: s3 client
s3_url(string): url in s3, e.g. file url: s3://dev/data/data.txt, directory url: s3://dev/data
out_dir(string): local directory address, e.g. /tmp/data/
Returns:
int: files of number in s3_url
"""
bucket_args = uri.replace(_S3_PREFIX, "", 1).split("/", 1)
bucket_name = bucket_args[0]
bucket_path = len(bucket_args) > 1 and bucket_args[1] or ""
Expand All @@ -186,9 +200,10 @@ def _download_s3(client, uri, out_dir):
use_api_v1=True)
count = 0

root_path = os.path.split(os.path.normpath(bucket_path))[0]
for obj in objects:
# Replace any prefix from the object key with out_dir
subdir_object_key = obj.object_name[len(bucket_path):].strip("/")
subdir_object_key = obj.object_name[len(root_path):].strip("/")
# fget_object handles directory creation if does not exist
if not obj.is_dir:
local_file = os.path.join(
Expand Down

0 comments on commit b1ec13e

Please sign in to comment.