-
Notifications
You must be signed in to change notification settings - Fork 10
Update create data package utility #104
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
Open
r-b-g-b
wants to merge
6
commits into
DataONEorg:master
Choose a base branch
from
r-b-g-b:update-create-data-package-utility
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ade1b5d
Add missing d1_client import to download_mn_objects
r-b-g-b 9872b41
Fixes to make create data packages helper utility run
r-b-g-b bfb55ac
Revert change that is present in another branch
r-b-g-b 773f7d9
Use context manager for file open
r-b-g-b ccf7225
Serialize resource map, read as bytes
r-b-g-b 7614212
Format, only serialize once
r-b-g-b 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,30 +171,29 @@ def main(): | |
# once, for the MD5 checksum calculation. | ||
def create_science_object_on_member_node(client, file_path): | ||
pid = os.path.basename(file_path) | ||
sci_obj = open(file_path, "rb").read() | ||
with open(file_path, "rb") as fp: | ||
sci_obj = fp.read() | ||
sys_meta = generate_system_metadata_for_science_object( | ||
pid, SYSMETA_FORMATID, sci_obj | ||
) | ||
client.create(pid, io.StringIO(sci_obj), sys_meta) | ||
client.create(pid, io.BytesIO(sci_obj), sys_meta) | ||
|
||
|
||
def create_package_on_member_node(client, files_in_group): | ||
package_pid = group_name(files_in_group[0]) | ||
pids = [os.path.basename(p) for p in files_in_group] | ||
resource_map = create_resource_map_for_pids(package_pid, pids) | ||
sys_meta = generate_system_metadata_for_science_object( | ||
package_pid, RESOURCE_MAP_FORMAT_ID, resource_map | ||
package_pid, RESOURCE_MAP_FORMAT_ID, resource_map.serialize_to_transport() | ||
) | ||
client.create(package_pid, io.StringIO(resource_map), sys_meta) | ||
|
||
|
||
def create_resource_map_for_pids(package_pid, pids): | ||
# Create a resource map generator that will generate resource maps that, by | ||
# default, use the DataONE production environment for resolving the object | ||
# URIs. To use the resource map generator in a test environment, pass the base | ||
# url to the root CN in that environment in the dataone_root parameter. | ||
resource_map_generator = d1_common.resource_map.ResourceMapGenerator() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As is I get the error:
I believe this class has since been removed and its method |
||
return resource_map_generator.simple_generate_resource_map( | ||
# Create a resource map that, by default, uses the DataONE production environment for resolving | ||
# the object URIs. To use the resource map generator in a test environment, pass the base url to | ||
# the root CN in that environment in the dataone_root parameter. | ||
return d1_common.resource_map.createSimpleResourceMap( | ||
package_pid, pids[0], pids[1:] | ||
) | ||
|
||
|
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.
Currently, this line results in the error:
That makes sense, since the file is opened in "rb" binary mode so needs to be wrapped with BytesIO instead of StringIO (which expects a decoded
str
).