@@ -324,18 +324,16 @@ def __parse_mcf_dict_recursive(dict2):
324
324
return mcf_dict
325
325
326
326
327
- def import_metadata (schema : str , metadata : str ) -> Union [ dict , None ] :
327
+ def import_metadata (schema : str , metadata : str ) -> dict :
328
328
"""
329
329
Import metadata
330
330
331
331
:param schema: schema / format
332
332
:metadata: metadata string
333
333
334
- :returns: MCF object or `None`
334
+ :returns: MCF object
335
335
"""
336
336
337
- content = None
338
-
339
337
if schema == 'autodetect' :
340
338
schemas = get_supported_schemas ()
341
339
else :
@@ -346,13 +344,11 @@ def import_metadata(schema: str, metadata: str) -> Union[dict, None]:
346
344
schema_object = load_schema (s )
347
345
348
346
try :
349
- content = schema_object .import_ (metadata )
347
+ return schema_object .import_ (metadata )
350
348
except NotImplementedError :
351
- LOGGER . debug (f'Import not supported for { s } ' )
349
+ raise RuntimeError (f'Import not supported for { s } ' )
352
350
except Exception as err :
353
- LOGGER .debug (f'Import failed: { err } ' )
354
-
355
- return content
351
+ raise RuntimeError (f'Import failed: { err } ' )
356
352
357
353
358
354
def transform_metadata (input_schema : str , output_schema : str ,
@@ -367,15 +363,16 @@ def transform_metadata(input_schema: str, output_schema: str,
367
363
:returns: transformed metadata or `None`
368
364
"""
369
365
370
- content = import_metadata (input_schema , metadata )
366
+ try :
367
+ content = import_metadata (input_schema , metadata )
371
368
372
- if content is None :
369
+ LOGGER .info (f'Processing into { output_schema } ' )
370
+ schema_object_output = load_schema (output_schema )
371
+ content = schema_object_output .write (content )
372
+ except Exception as err :
373
+ LOGGER .debug (err )
373
374
return None
374
375
375
- LOGGER .info (f'Processing into { output_schema } ' )
376
- schema_object_output = load_schema (output_schema )
377
- content = schema_object_output .write (content )
378
-
379
376
return content
380
377
381
378
@@ -535,19 +532,19 @@ class MCFValidationError(Exception):
535
532
@cli_options .OPTION_VERBOSITY
536
533
@click .option ('--schema' , required = True ,
537
534
type = click .Choice (get_supported_schemas (include_autodetect = True )), # noqa
535
+ default = 'autodetect' ,
538
536
help = 'Metadata schema' )
539
537
def import_ (ctx , metadata_file , schema , output , verbosity ):
540
538
"""import metadata"""
541
539
542
- content = import_metadata (schema , metadata_file .read ())
543
-
544
- if content is None :
545
- raise click .ClickException ('No supported schema detected/found' )
546
-
547
- if output is None :
548
- click .echo (yaml .dump (content ))
549
- else :
550
- output .write (yaml .dump (content , indent = 4 ))
540
+ try :
541
+ content = import_metadata (schema , metadata_file .read ())
542
+ if output is None :
543
+ click .echo (yaml .dump (content ))
544
+ else :
545
+ output .write (yaml .dump (content , indent = 4 ))
546
+ except Exception as err :
547
+ raise click .ClickException (f'No supported schema detecte/found: { err } ' )
551
548
552
549
553
550
@click .command ()
@@ -638,6 +635,7 @@ def validate(ctx, mcf, verbosity):
638
635
@cli_options .OPTION_VERBOSITY
639
636
@click .option ('--input-schema' , required = True ,
640
637
type = click .Choice (get_supported_schemas (include_autodetect = True )), # noqa
638
+ default = 'autodetect' ,
641
639
help = 'Metadata schema of input file' )
642
640
@click .option ('--output-schema' , required = True ,
643
641
type = click .Choice (get_supported_schemas ()),
0 commit comments