-
Notifications
You must be signed in to change notification settings - Fork 11
PYTHONSDK-97: Adding documentation and code samples for new helper functions. #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2021 Spectra Logic Corporation. All Rights Reserved. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
| # this file except in compliance with the License. A copy of the License is located at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # or in the "license" file accompanying this file. | ||
| # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
|
|
||
| import tempfile | ||
|
|
||
| from os import path, walk | ||
| from ds3 import ds3, ds3Helpers | ||
|
|
||
| # This example gets ALL objects within the bucket books and lands them in a temp folder. | ||
| # This uses the new helper functions which creates and manages the BP jobs behind the scenes. | ||
| # | ||
| # This assumes that there exists a bucket called books on the BP and it contains objects. | ||
| # Running the putting_all_files_in_directory.py example will create this setup. | ||
|
|
||
| # The bucket that contains the objects. | ||
| bucket_name = "books" | ||
|
|
||
| # The directory on the file system where the objects will be landed. | ||
| # In this example, we are using a temporary directory for easy cleanup. | ||
| destination_directory = tempfile.TemporaryDirectory(prefix="books-dir") | ||
|
|
||
| # Create a client which will be used to communicate with the BP. | ||
| client = ds3.createClientFromEnv() | ||
|
|
||
| # Create the helper to gain access to the new data movement utilities. | ||
| helper = ds3Helpers.Helper(client=client) | ||
|
|
||
| # Retrieve all the objects in the desired bucket and land them in the specified directory. | ||
| # | ||
| # You can optionally specify a objects_per_bp_job and max_threads to tune performance. | ||
| get_job_ids = helper.get_all_files_in_bucket(destination_dir=destination_directory.name, bucket=bucket_name) | ||
| print("BP get job IDS: " + get_job_ids.__str__()) | ||
|
|
||
| # Verify that all the files have been landed in the folder. | ||
| for root, dirs, files in walk(top=destination_directory.name): | ||
| for name in files: | ||
| print("File: " + path.join(root, name)) | ||
| for name in dirs: | ||
| print("Dir: " + path.join(root, name)) | ||
|
|
||
| # Clean up the temp directory where we landed the files. | ||
| destination_directory.cleanup() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Copyright 2021 Spectra Logic Corporation. All Rights Reserved. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
| # this file except in compliance with the License. A copy of the License is located at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # or in the "license" file accompanying this file. | ||
| # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
|
|
||
| import tempfile | ||
|
|
||
| from os import path, walk | ||
| from ds3 import ds3, ds3Helpers | ||
|
|
||
| # This example gets ONE objects within the bucket books and lands it in a temp folder. | ||
| # This uses the new helper functions which creates and manages the BP job behind the scenes. | ||
| # | ||
| # This assumes that there exists a bucket called books on the BP and it contains the object beowulf.txt. | ||
| # Running the putting_one_file_in_directory.py example will create this setup. | ||
|
|
||
| # The bucket that contains the objects. | ||
| bucket_name = "books" | ||
|
|
||
| # The directory on the file system where the object will be landed. | ||
| # In this example, we are using a temporary directory for easy cleanup. | ||
| destination_directory = tempfile.TemporaryDirectory(prefix="books-dir") | ||
|
|
||
| # Create a client which will be used to communicate with the BP. | ||
| client = ds3.createClientFromEnv() | ||
|
|
||
| # Create the helper to gain access to the new data movement utilities. | ||
| helper = ds3Helpers.Helper(client=client) | ||
|
|
||
| # Create a HelperGetObject for each item you want to retrieve from the BP bucket. | ||
| # This example only gets one object, but you can transfer more than one at a time. | ||
| # For each object you must specify the name of the object on the BP, and the file path where you want to land the file. | ||
| # Optionally, if versioning is enabled on your bucket, you can specify the specific version to retrieve. | ||
| # If you don't specify a version, the most recent will be retrieved. | ||
| file_path = path.join(destination_directory.name, "beowulf.txt") | ||
| get_objects = [ds3Helpers.HelperGetObject(object_name="beowulf.txt", destination_path=file_path)] | ||
|
|
||
| # Retrieve the objects in the desired bucket. | ||
| # You can optionally specify max_threads to tune performance. | ||
| get_job_id = helper.get_objects(get_objects=get_objects, bucket=bucket_name) | ||
| print("BP get job ID: " + get_job_id) | ||
|
|
||
| # Verify that all the files have been landed in the folder. | ||
| for root, dirs, files in walk(top=destination_directory.name): | ||
| for name in files: | ||
| print("File: " + path.join(root, name)) | ||
| for name in dirs: | ||
| print("Dir: " + path.join(root, name)) | ||
|
|
||
| # Clean up the temp directory where we landed the files. | ||
| destination_directory.cleanup() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Copyright 2021 Spectra Logic Corporation. All Rights Reserved. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
| # this file except in compliance with the License. A copy of the License is located at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # or in the "license" file accompanying this file. | ||
| # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
|
|
||
| import os | ||
|
|
||
| from ds3 import ds3, ds3Helpers | ||
|
|
||
| # This example puts ALL files within the sub-folder /samples/resources to the bucket called books. | ||
| # This uses the new helper functions which creates and manages the BP jobs behind the scenes. | ||
|
|
||
| # The bucket where to land the files. | ||
| bucket_name = "books" | ||
|
|
||
| # The directory that contains files to be archived to BP. | ||
| # In this example, we are moving all files in the ds3_python3_sdk/samples/resources folder. | ||
| directory_with_files = os.path.join(os.path.dirname(str(__file__)), "resources") | ||
|
|
||
| # Create a client which will be used to communicate with the BP. | ||
| client = ds3.createClientFromEnv() | ||
|
|
||
| # Make sure the bucket that we will be sending objects to exists | ||
| client.put_bucket(ds3.PutBucketRequest(bucket_name)) | ||
|
|
||
| # Create the helper to gain access to the new data movement utilities. | ||
| helper = ds3Helpers.Helper(client=client) | ||
|
|
||
| # Archive all the files in the desired directory to the specified bucket. | ||
| # Note that the file's object names will be relative to the root directory you specified. | ||
| # For example: resources/beowulf.txt will be named just beowulf.txt in the BP bucket. | ||
| # | ||
| # You can optionally specify a objects_per_bp_job and max_threads to tune performance. | ||
| put_job_ids = helper.put_all_objects_in_directory(source_dir=directory_with_files, bucket=bucket_name) | ||
| print("BP put job IDs: " + put_job_ids.__str__()) | ||
|
|
||
| # we now verify that all our objects have been sent to DS3 | ||
| bucketResponse = client.get_bucket(ds3.GetBucketRequest(bucket_name)) | ||
|
|
||
| for obj in bucketResponse.result['ContentsList']: | ||
| print(obj['Key']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2021 Spectra Logic Corporation. All Rights Reserved. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
| # this file except in compliance with the License. A copy of the License is located at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # or in the "license" file accompanying this file. | ||
| # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
|
|
||
| import os | ||
|
|
||
| from ds3 import ds3, ds3Helpers | ||
|
|
||
| # This example puts ONE file /samples/resources/beowulf.txt to the bucket called books. | ||
| # This uses the new helper functions which creates and manages a single BP job. | ||
|
|
||
| # The bucket where to land the files. | ||
| bucket_name = "books" | ||
|
|
||
| # The file path being put to the BP. | ||
| file_path = os.path.join(os.path.dirname(str(__file__)), "resources", "beowulf.txt") | ||
|
|
||
| # Create a client which will be used to communicate with the BP. | ||
| client = ds3.createClientFromEnv() | ||
|
|
||
| # Make sure the bucket that we will be sending objects to exists | ||
| client.put_bucket(ds3.PutBucketRequest(bucket_name)) | ||
|
|
||
| # Create the helper to gain access to the new data movement utilities. | ||
| helper = ds3Helpers.Helper(client=client) | ||
|
|
||
| # Create a HelperPutObject for each item you want to send to the BP. | ||
| # This example only puts one file, but you can send more than one at a time. | ||
| # For each object you must specify the name it will be called on the BP, the file path, and the size of the file. | ||
| file_size = os.path.getsize(file_path) | ||
| put_objects = [ds3Helpers.HelperPutObject(object_name="beowulf.txt", file_path=file_path, size=file_size)] | ||
|
|
||
| # Archive the files to the specified bucket | ||
| # You can optionally specify max_threads to tune performance. | ||
| put_job_id = helper.put_objects(put_objects=put_objects, bucket=bucket_name) | ||
| print("BP put job ID: " + put_job_id) | ||
|
|
||
| # we now verify that all our objects have been sent to DS3 | ||
| bucketResponse = client.get_bucket(ds3.GetBucketRequest(bucket_name)) | ||
|
|
||
| for obj in bucketResponse.result['ContentsList']: | ||
| print(obj['Key']) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary comma