|
@@ -1,13 +1,18 @@
|
|
import click
|
|
import click
|
|
import click_log
|
|
import click_log
|
|
|
|
+import csv
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
-import os
|
|
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
+from os import getcwd, path
|
|
|
|
+
|
|
|
|
+import arrow
|
|
|
|
+
|
|
from lakesuperior import env
|
|
from lakesuperior import env
|
|
from lakesuperior.api import admin as admin_api
|
|
from lakesuperior.api import admin as admin_api
|
|
from lakesuperior.config_parser import config
|
|
from lakesuperior.config_parser import config
|
|
|
|
+from lakesuperior.globals import AppGlobals
|
|
from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
|
|
from lakesuperior.store.ldp_rs.lmdb_store import TxnManager
|
|
|
|
|
|
__doc__="""
|
|
__doc__="""
|
|
@@ -23,12 +28,6 @@ for a list of tools and options.
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
click_log.basic_config(logger)
|
|
click_log.basic_config(logger)
|
|
|
|
|
|
-#report = logging.getLogger('report')
|
|
|
|
-#report_formatter = logging.Formatter('"%(asctime)s",%(message)s')
|
|
|
|
-#report_fpath = '{}/lsup-report-{}'.format(
|
|
|
|
-# env.config['application']['data_dir'],
|
|
|
|
-# arrow.utcnow().format('YYYY-MM-DDTHH:mm:ss.S'))
|
|
|
|
-#report_handler = logging.FileHandler(report_fpath)
|
|
|
|
|
|
|
|
@click.group()
|
|
@click.group()
|
|
def admin():
|
|
def admin():
|
|
@@ -69,7 +68,8 @@ def bootstrap():
|
|
click.echo('Initializing binary store at {}'.format(nonrdfly.root))
|
|
click.echo('Initializing binary store at {}'.format(nonrdfly.root))
|
|
nonrdfly.bootstrap()
|
|
nonrdfly.bootstrap()
|
|
click.echo('Binary store initialized.')
|
|
click.echo('Binary store initialized.')
|
|
- click.echo('Repository successfully set up. Go to town.')
|
|
|
|
|
|
+ click.echo('\nRepository successfully set up. Go to town.')
|
|
|
|
+ click.echo('If the HTTP server is running, it must be restarted.')
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
@click.command()
|
|
@@ -117,19 +117,41 @@ def check_refint(config_folder=None, output=None):
|
|
resources. For repositories set up with the `referential_integrity` option
|
|
resources. For repositories set up with the `referential_integrity` option
|
|
(the default), this is a pre-condition for a consistent data set.
|
|
(the default), this is a pre-condition for a consistent data set.
|
|
|
|
|
|
- Note: this check is run regardless of whether the repository enforces
|
|
|
|
|
|
+ If inconsistencies are found, a report is generated in CSV format with the
|
|
|
|
+ following columns: `s`, `p`, `o` (respectively the terms of the
|
|
|
|
+ triple containing the dangling relationship) and `missing` which
|
|
|
|
+ indicates which term is the missing URI (currently always set to `o`).
|
|
|
|
+
|
|
|
|
+ Note: this check can be run regardless of whether the repository enforces
|
|
referential integrity.
|
|
referential integrity.
|
|
"""
|
|
"""
|
|
- check_results = admin_api.integrity_check(config_folder)
|
|
|
|
|
|
+ if config_folder:
|
|
|
|
+ env.app_globals = AppGlobals(parse_config(config_dir))
|
|
|
|
+ else:
|
|
|
|
+ import lakesuperior.env_setup
|
|
|
|
+
|
|
|
|
+ check_results = admin_api.integrity_check()
|
|
|
|
+
|
|
click.echo('Integrity check results:')
|
|
click.echo('Integrity check results:')
|
|
if len(check_results):
|
|
if len(check_results):
|
|
click.echo(click.style('Inconsistencies found!', fg='red', bold=True))
|
|
click.echo(click.style('Inconsistencies found!', fg='red', bold=True))
|
|
- click.echo('Missing object in the following triples:')
|
|
|
|
- for trp in check_results:
|
|
|
|
- click.echo(' '.join([str(t) for t in trp[0]]))
|
|
|
|
|
|
+ if not output:
|
|
|
|
+ output = path.join(getcwd(), 'refint_report-{}.csv'.format(
|
|
|
|
+ arrow.utcnow().format('YYYY-MM-DDTHH:mm:ss.S')))
|
|
|
|
+ elif not output.endswith('.csv'):
|
|
|
|
+ output += '.csv'
|
|
|
|
+
|
|
|
|
+ with open(output, 'w', newline='') as fh:
|
|
|
|
+ writer = csv.writer(fh)
|
|
|
|
+ writer.writerow(('s', 'p', 'o', 'missing'))
|
|
|
|
+ for trp in check_results:
|
|
|
|
+ # ``o`` is always hardcoded for now.
|
|
|
|
+ writer.writerow([t.n3() for t in trp[0]] + ['o'])
|
|
|
|
+
|
|
|
|
+ click.echo('Report generated at {}'.format(output))
|
|
else:
|
|
else:
|
|
click.echo(click.style('Clean. ', fg='green', bold=True)
|
|
click.echo(click.style('Clean. ', fg='green', bold=True)
|
|
- + 'No inconsistency found.')
|
|
|
|
|
|
+ + 'No inconsistency found. No report generated.')
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
@click.command()
|