Skip to content

Commit

Permalink
Support both script and api version of troubleshoot publications
Browse files Browse the repository at this point in the history
  • Loading branch information
claravox committed Oct 2, 2024
1 parent 11889b3 commit f84b6f7
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 84 deletions.
7 changes: 4 additions & 3 deletions meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,14 @@ def copy_user_metadata(ctx, source, target):
log.write(ctx, "copy_user_metadata: failed to copy user metadata from <{}> to <{}/original>".format(source, target))


def vault_metadata_matches_schema(ctx, coll_name, schema_cache, report_name):
def vault_metadata_matches_schema(ctx, coll_name, schema_cache, report_name, write_stdout):
"""Process a single data package to retrieve and validate that its metadata conforms to the schema.
:param ctx: Combined type of a callback and rei struct
:param coll_name: String representing the data package collection path.
:param schema_cache: Dictionary storing schema blueprints, can be empty.
:param report_name: Name of report script (for logging)
:param write_stdout: A boolean representing whether to write to stdout or rodsLog
:returns: A dictionary result containing if schema matches and the schema short name.
"""
Expand All @@ -813,7 +814,7 @@ def vault_metadata_matches_schema(ctx, coll_name, schema_cache, report_name):
metadata = jsonutil.read(ctx, metadata_path)
except Exception as exc:
log.write(ctx, "{} skips {}, because of exception while reading metadata file {}: {}".format(report_name, coll_name, metadata_path, str(exc)))
log.write_stdout(ctx, "vault_metadata_matches_schema: Error while reading metadata file {} of data package {}: {}".format(metadata_path, coll_name, str(exc)))
log.write(ctx, "vault_metadata_matches_schema: Error while reading metadata file {} of data package {}: {}".format(metadata_path, coll_name, str(exc)), write_stdout)
return None

# Determine schema
Expand All @@ -834,6 +835,6 @@ def vault_metadata_matches_schema(ctx, coll_name, schema_cache, report_name):
if not match_schema:
errors_formatted = [meta_form.humanize_validation_error(e).encode('utf-8') for e in error_list]
log.write(ctx, "{}: metadata {} did not match schema {}: {}".format(report_name, metadata_path, schema_shortname, str(errors_formatted)))
log.write_stdout(ctx, "vault_metadata_matches_schema: Metadata {} of data package {} did not match the schema {}. Error list: {}".format(metadata_path, coll_name, schema_shortname, str(errors_formatted)))
log.write(ctx, "vault_metadata_matches_schema: Metadata {} of data package {} did not match the schema {}. Error list: {}".format(metadata_path, coll_name, schema_shortname, str(errors_formatted)), write_stdout)

return {"schema": schema_shortname, "match_schema": match_schema}
Loading

0 comments on commit f84b6f7

Please sign in to comment.