Skip to content
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

Add batch processing to 'draft' action, add test artifacts for zero, … #54

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

qchaupds
Copy link

@qchaupds qchaupds commented Jul 28, 2020

Pull request to close DOI Batch Processing capability #25

Batch processing allow to process series of PDS4 labels.

@tloubrieu-jpl tloubrieu-jpl self-assigned this Jul 29, 2020
Copy link
Member

@tloubrieu-jpl tloubrieu-jpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank Qui. I mostly have a proposition to simplify a bit the resolve_input_into...
There is one test which is not useful also I think.

Thanks very much,

"""Function receives an input which can be one name or a list of names separated by a comma or a directory. Function will return a list of names.
"""
o_list_of_names = []
if ',' in input:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can have the same code for a list of pds4 labels or a single one. If you split on ',' and there is no ',' you get one list with a single result.

Then you can test if the token is a dir or a file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I started with one train of thought and kept going.
Splitting using the comma ',' right away allow you to use the for loop to check if the token is a directory or a file.
Code is much simpler now.

# -i ,
if len(token) > 0:
o_list_of_names.append(token)
elif os.path.isdir(input):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This elif and the following else would be in the for token loop. Each step will append (file) or extend (dir) the list with new entries.

Does that work ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the elif and the following code inside the for loop works now.

list_of_names = self._resolve_input_into_list_of_names(input)
# Return immediately if there are no files found.
# Note that exit() function is not used as it would interfere with the unit test.
if len(list_of_names) == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that happen ? if the argument input is mandatory then there is at least one input. You should be able to remove this test and the lines inside it.

We could have an un-existing input or empty input but that is not what you are testing here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can happen if the input for the -i is a directory and there is nothing inside. As it turns out, we don't need to do the check since the while loop will take care of that (iterating over a list of zero).

I removed len() check and the code still runs OK. You are right. There's no need to do an additional check when the for loop works just fine.

# Write a transaction for the 'reserve' action.
transaction_obj.log()
# The returned label can be None if it is not an expected XML file.
if doi_label:
Copy link
Member

@tloubrieu-jpl tloubrieu-jpl Jul 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks like an implicit error management. That would be more readable to have an explicit exception (invalid PDS4Input...) raised by the method _transform_pds4_label_into_osti_record().
But
I don't know what case would raise this exception. Do you know what case can make the doi_abel == None ? Ah yes maybe if the input file does not exists... yes in this case an exception will be more explicit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid having to check for doi_label be None, the function _transform_pds4_label_into_osti_record() can return an empty tree (which is not None). There's no need to check for None-ness.

The code is much simpler now.

…one and two files directory, expand unit tests, fix parsing of 'first_name' when splitting with space fail

Simplify function parsing for input files/directories, delete unit test for empty directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants