Skip to content

Commit

Permalink
Merge pull request #180 from will-moore/bom_fix_populate_metadata
Browse files Browse the repository at this point in the history
bom fix populate metadata
  • Loading branch information
sbesson authored Jun 17, 2021
2 parents 68c7505 + 9042010 commit dddc749
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions omero/import_scripts/Populate_Metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,29 @@ def populate_metadata(client, conn, script_params):
conn, data_type, object_id, file_ann_id)
provider = DownloadingOriginalFileProvider(conn)
data_for_preprocessing = provider.get_original_file_data(original_file)
data = provider.get_original_file_data(original_file)
temp_name = data_for_preprocessing.name
# 5.9.1 returns NamedTempFile where name is a string.
if isinstance(temp_name, int):
print("omero-py 5.9.1 DownloadingOriginalFileProvider returns "
"NamedTempFile. Please Upgrade to omero-py 5.9.1 or later")
return "Please upgrade omero-py to 5.9.1 or later"
objecti = getattr(omero.model, data_type + 'I')
omero_object = objecti(int(object_id), False)
ctx = ParsingContext(client, omero_object, "")

try:
# Old
ctx.parse_from_handle(data)
ctx.write_to_omero()
with open(temp_name, 'rt', encoding='utf-8-sig') as f1:
ctx.parse_from_handle(f1)
ctx.write_to_omero()
except AttributeError:
# omero-metadata >= 0.3.0
ctx.preprocess_from_handle(data_for_preprocessing)
ctx.parse_from_handle_stream(data)
with open(temp_name, 'rt', encoding='utf-8-sig') as f1:
ctx.preprocess_from_handle(f1)
with open(temp_name, 'rt', encoding='utf-8-sig') as f2:
ctx.parse_from_handle_stream(f2)
finally:
data_for_preprocessing.close()
return "Table data populated for %s: %s" % (data_type, object_id)


Expand Down

0 comments on commit dddc749

Please sign in to comment.