Skip to content

Commit 4600875

Browse files
committed
fix PR comments
1 parent a66e2bd commit 4600875

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ pygeometa metadata validate path/to/file.yml
6565
pygeometa metadata import path/to/file.xml --schema=iso19139
6666

6767
# import a metadata document to MCF, autodetecting the metadata file format
68-
pygeometa metadata import path/to/file.xml --schema=autodetect
68+
pygeometa metadata import path/to/file.xml --schema=autodetect # --schema=autodetect is default
6969

7070
# transform from one metadata representation to another
7171
pygeometa metadata transform path/to/file.xml --input-schema=iso19139 --output-schema=oarec-record
7272

7373
# transform from one metadata representation to another, autodetecting the metadata file format
74-
pygeometa metadata transform path/to/file.xml --input-schema=autodetect --output-schema=oarec-record
74+
pygeometa metadata transform path/to/file.xml --input-schema=autodetect --output-schema=oarec-record # --input-schema=autodetect is default
7575
```
7676

7777
### Supported schemas

docs/content/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ pygeometa validate path/to/file.yml
6363
pygeometa metadata import path/to/file.xml --schema=iso19139
6464

6565
# import a metadata document to MCF, autodetecting the metadata file format
66-
pygeometa metadata import path/to/file.xml --schema=autodetect
66+
pygeometa metadata import path/to/file.xml --schema=autodetect # --schema=autodetect is default
6767

6868
# transform from one metadata representation to another
6969
pygeometa metadata transform path/to/file.xml --input-schema=iso19139 --output-schema=oarec-record
7070

7171
# transform from one metadata representation to another, autodetecting the metadata file format
72-
pygeometa metadata transform path/to/file.xml --input-schema=autodetect --output-schema=oarec-record
72+
pygeometa metadata transform path/to/file.xml --input-schema=autodetect --output-schema=oarec-record # --input-schema=autodetect is default
7373
```
7474

7575
## For Developers

pygeometa/core.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,16 @@ def __parse_mcf_dict_recursive(dict2):
324324
return mcf_dict
325325

326326

327-
def import_metadata(schema: str, metadata: str) -> Union[dict, None]:
327+
def import_metadata(schema: str, metadata: str) -> dict:
328328
"""
329329
Import metadata
330330
331331
:param schema: schema / format
332332
:metadata: metadata string
333333
334-
:returns: MCF object or `None`
334+
:returns: MCF object
335335
"""
336336

337-
content = None
338-
339337
if schema == 'autodetect':
340338
schemas = get_supported_schemas()
341339
else:
@@ -346,13 +344,11 @@ def import_metadata(schema: str, metadata: str) -> Union[dict, None]:
346344
schema_object = load_schema(s)
347345

348346
try:
349-
content = schema_object.import_(metadata)
347+
return schema_object.import_(metadata)
350348
except NotImplementedError:
351-
LOGGER.debug(f'Import not supported for {s}')
349+
raise RuntimeError(f'Import not supported for {s}')
352350
except Exception as err:
353-
LOGGER.debug(f'Import failed: {err}')
354-
355-
return content
351+
raise RuntimeError(f'Import failed: {err}')
356352

357353

358354
def transform_metadata(input_schema: str, output_schema: str,
@@ -367,15 +363,16 @@ def transform_metadata(input_schema: str, output_schema: str,
367363
:returns: transformed metadata or `None`
368364
"""
369365

370-
content = import_metadata(input_schema, metadata)
366+
try:
367+
content = import_metadata(input_schema, metadata)
371368

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)
373374
return None
374375

375-
LOGGER.info(f'Processing into {output_schema}')
376-
schema_object_output = load_schema(output_schema)
377-
content = schema_object_output.write(content)
378-
379376
return content
380377

381378

@@ -535,19 +532,19 @@ class MCFValidationError(Exception):
535532
@cli_options.OPTION_VERBOSITY
536533
@click.option('--schema', required=True,
537534
type=click.Choice(get_supported_schemas(include_autodetect=True)), # noqa
535+
default='autodetect',
538536
help='Metadata schema')
539537
def import_(ctx, metadata_file, schema, output, verbosity):
540538
"""import metadata"""
541539

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}')
551548

552549

553550
@click.command()
@@ -638,6 +635,7 @@ def validate(ctx, mcf, verbosity):
638635
@cli_options.OPTION_VERBOSITY
639636
@click.option('--input-schema', required=True,
640637
type=click.Choice(get_supported_schemas(include_autodetect=True)), # noqa
638+
default='autodetect',
641639
help='Metadata schema of input file')
642640
@click.option('--output-schema', required=True,
643641
type=click.Choice(get_supported_schemas()),

0 commit comments

Comments
 (0)