spatial-d4science/ckanext/spatial/cli.py

74 lines
1.6 KiB
Python
Raw Normal View History

2019-12-11 13:22:28 +01:00
# encoding: utf-8
import click
import logging
import ckanext.spatial.util as util
log = logging.getLogger(__name__)
2019-12-13 15:48:20 +01:00
def get_commands():
return [
spatial,
spatial_validation
]
2019-12-11 13:22:28 +01:00
@click.group(u"spatial-validation", short_help=u"Spatial formats validation commands")
2019-12-13 15:48:20 +01:00
def spatial_validation():
pass
2019-12-11 13:22:28 +01:00
2019-12-13 15:48:20 +01:00
@spatial_validation.command()
2019-12-11 13:22:28 +01:00
@click.argument('pkg', required=False)
def report(pkg):
"""
Performs validation on the harvested metadata, either for all
packages or the one specified.
"""
2019-12-11 13:22:28 +01:00
return util.report(pkg)
2019-12-13 15:48:20 +01:00
@spatial_validation.command('report-csv')
2019-12-11 13:22:28 +01:00
@click.argument('filepath')
def report_csv(filepath):
"""
Performs validation on all the harvested metadata in the db and
writes a report in CSV format to the given filepath.
"""
2019-12-11 13:22:28 +01:00
return util.report_csv(filepath)
2019-12-13 15:48:20 +01:00
@spatial_validation.command('file')
2019-12-11 13:22:28 +01:00
@click.argument('filepath')
def validate_file(filepath):
"""Performs validation on the given metadata file."""
2019-12-11 13:22:28 +01:00
return util.validate_file(filepath)
@click.group(short_help=u"Performs spatially related operations.")
2019-12-13 15:48:20 +01:00
def spatial():
pass
2019-12-11 13:22:28 +01:00
@spatial.command()
@click.argument('srid', required=False)
def initdb(srid):
"""
Creates the necessary tables. You must have PostGIS installed
and configured in the database.
You can provide the SRID of the geometry column. Default is 4326.
"""
2019-12-11 13:22:28 +01:00
return util.initdb(srid)
@spatial.command('extents')
def update_extents():
"""
Creates or updates the extent geometry column for datasets with
an extent defined in the 'spatial' extra.
"""
2019-12-11 13:22:28 +01:00
return util.update_extents()