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

Update image metadata for v2 #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions image/metadata/ncsa.image.metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pyclowder.files
import pyclowder.utils

clowder_version = os.getenv('CLOWDER_VERSION', '1.0')

class ImageMetadataExtractor(Extractor):
"""Count the number of characters, words and lines in a text file."""
Expand Down Expand Up @@ -37,17 +38,21 @@ def process_message(self, connector, host, secret_key, resource, parameters):
result = self.parse_exif(subprocess.check_output(
[self.args.image_binary, "-verbose", inputfile], stderr=subprocess.STDOUT).decode("utf-8"))

metadata = {
"@context": {
"@vocab": "http://www.w3.org/2003/12/exif/ns"
},
"file_id": file_id,
"content": result,
"agent": {
"@type": "cat:extractor",
"extractor_id": host + "/api/extractors/ncsa.image.metadata"
if float(clowder_version) >= 2.0:
Copy link
Member

@robkooper robkooper Feb 20, 2023

Choose a reason for hiding this comment

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

would it make sense to use the same function here? I assume the self.get_metadata returns the same object? same for #29. If leverage of that, we don't need the CLOWDER_VERSION above either.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed for both pull requests. You are right - the method will work either way and then there's no need to check clowder version here, it'll be done on the pyclowder side.

Copy link
Author

Choose a reason for hiding this comment

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

For the metadata and v1, this branch of pyclowder:

clowder-framework/pyclowder#60

Allows the context to be passed to the get_metadata so that the method can be used for both instead of this call.

context = {"@vocab": "http://www.w3.org/2003/12/exif/ns"}
metadata = self.get_metadata(result, 'file', resource['id'], host, contexts=[context])
else:
metadata = {
"@context": {
"@vocab": "http://www.w3.org/2003/12/exif/ns"
},
"file_id": file_id,
"content": result,
"agent": {
"@type": "cat:extractor",
"extractor_id": host + "/api/extractors/ncsa.image.metadata"
}
}
}
pyclowder.files.upload_metadata(connector, host, secret_key, file_id, metadata)

def fix_map(self, data):
Expand Down