2019-12-11 13:23:03 +01:00
|
|
|
from __future__ import print_function
|
2012-10-19 19:20:32 +02:00
|
|
|
import sys
|
2019-12-11 13:22:28 +01:00
|
|
|
|
2012-10-19 19:20:32 +02:00
|
|
|
import logging
|
2019-12-11 13:22:28 +01:00
|
|
|
from ckan.lib.cli import CkanCommand
|
2012-10-19 19:20:32 +02:00
|
|
|
|
2019-12-11 13:22:28 +01:00
|
|
|
import ckanext.spatial.util as util
|
2012-10-19 19:20:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class Validation(CkanCommand):
|
|
|
|
'''Validation commands
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
validation report [package-name]
|
|
|
|
Performs validation on the harvested metadata, either for all
|
2012-12-05 12:42:57 +01:00
|
|
|
packages or the one specified.
|
2012-10-19 19:20:32 +02:00
|
|
|
|
|
|
|
validation report-csv <filename>.csv
|
2012-12-05 12:42:57 +01:00
|
|
|
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
|
|
|
|
2012-12-05 12:42:57 +01:00
|
|
|
validation file <filename>.xml
|
|
|
|
Performs validation on the given metadata file.
|
2012-10-19 19:20:32 +02:00
|
|
|
'''
|
|
|
|
summary = __doc__.split('\n')[0]
|
|
|
|
usage = __doc__
|
|
|
|
max_args = 3
|
|
|
|
min_args = 0
|
|
|
|
|
|
|
|
def command(self):
|
|
|
|
if not self.args or self.args[0] in ['--help', '-h', 'help']:
|
2019-12-11 13:23:03 +01:00
|
|
|
print(self.usage)
|
2012-10-19 19:20:32 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
self._load_config()
|
|
|
|
|
|
|
|
cmd = self.args[0]
|
|
|
|
if cmd == 'report':
|
|
|
|
self.report()
|
|
|
|
elif cmd == 'report-csv':
|
|
|
|
self.report_csv()
|
2012-12-05 12:42:57 +01:00
|
|
|
elif cmd == 'file':
|
|
|
|
self.validate_file()
|
2012-10-19 19:20:32 +02:00
|
|
|
else:
|
2019-12-11 13:23:03 +01:00
|
|
|
print('Command %s not recognized' % cmd)
|
2012-10-19 19:20:32 +02:00
|
|
|
|
|
|
|
def report(self):
|
|
|
|
|
|
|
|
if len(self.args) >= 2:
|
2019-12-11 13:22:28 +01:00
|
|
|
pkg = self.args[1]
|
2012-10-19 19:20:32 +02:00
|
|
|
else:
|
|
|
|
pkg = None
|
2019-12-11 13:22:28 +01:00
|
|
|
return util.report(pkg)
|
2012-10-19 19:20:32 +02:00
|
|
|
|
2012-12-05 12:42:57 +01:00
|
|
|
def validate_file(self):
|
|
|
|
if len(self.args) > 2:
|
2019-12-11 13:23:03 +01:00
|
|
|
print('Too many parameters %i' % len(self.args))
|
2012-12-05 12:42:57 +01:00
|
|
|
sys.exit(1)
|
|
|
|
if len(self.args) < 2:
|
2019-12-11 13:23:03 +01:00
|
|
|
print('Not enough parameters %i' % len(self.args))
|
2012-12-05 12:42:57 +01:00
|
|
|
sys.exit(1)
|
2019-12-11 13:22:28 +01:00
|
|
|
|
|
|
|
return util.validate_file(self.args[1])
|
2012-12-05 12:42:57 +01:00
|
|
|
|
2012-10-19 19:20:32 +02:00
|
|
|
def report_csv(self):
|
|
|
|
if len(self.args) != 2:
|
2019-12-11 13:23:03 +01:00
|
|
|
print('Wrong number of arguments')
|
2012-10-19 19:20:32 +02:00
|
|
|
sys.exit(1)
|
2019-12-11 13:22:28 +01:00
|
|
|
return util.report_csv(self.args[1])
|