From: tilly-Q Date: Thu, 27 Mar 2014 17:55:15 +0000 (-0400) Subject: Added exception handling into the metadata format checking function. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=680faaaa855a5fa60178d6b2a7e562619d3a4c4b;p=mediagoblin.git Added exception handling into the metadata format checking function. --- diff --git a/mediagoblin/gmg_commands/batchaddmedia.py b/mediagoblin/gmg_commands/batchaddmedia.py index 83aea7b7..f06bc2e8 100644 --- a/mediagoblin/gmg_commands/batchaddmedia.py +++ b/mediagoblin/gmg_commands/batchaddmedia.py @@ -24,9 +24,11 @@ from mediagoblin.gmg_commands import util as commands_util from mediagoblin.submit.lib import ( submit_media, get_upload_file_limits, FileUploadLimit, UserUploadLimit, UserPastUploadLimit) +from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ from mediagoblin import mg_globals -from jsonschema import validate +from jsonschema import validate +from jsonschema.exceptions import ValidationError def parser_setup(subparser): subparser.description = """\ @@ -135,7 +137,10 @@ zip files and directories" dcterms_context = { 'dcterms':'http://purl.org/dc/terms/' } for media_id in media_locations.keys(): - file_metadata = media_metadata[media_id] + file_metadata = media_metadata[media_id] + santized_metadata = check_metadata_format(file_metadata) + if sanitized_metadata == {}: continue + json_ld_metadata = jsonld.compact(file_metadata, dcterms_context) original_location = media_locations[media_id]['media:original'] url = urlparse(original_location) @@ -248,3 +253,14 @@ def check_metadata_format(metadata_dict): }""") try: validate(metadata_dict, schema) + output_dict = metadata_dict + except ValidationError, exc: + title = metadata_dict.get('title') or metadata_dict.get('media:id') or \ + _(u'UNKNOWN FILE') + print _( +u"""WARN: Could not find appropriate metadata for file {title}. File will be +skipped""".format(title=title)) + output_dict = {} + except: + raise + return output_dict