diff --git a/README.md b/README.md index 0f2a08e92..5a6efe829 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,10 @@ knora-py is a python package containing a command line tool for data model (ontology) creation, a library allowing creation of single resources and mass upload using the bulk import of data into the Knora framework. The package consists of: -- ```Knora``` Python modules for accessing Knora using the API (ontology creation, data import/export etc.) -- ```knora-create-ontology``` A command line program to create an ontology out of a simple JSON description +- `Knora` Python modules for accessing Knora using the API (ontology creation, data import/export etc.) +- `knora-create-ontology` A command line program to create an ontology out of a simple JSON description +- `knora-reset-triplestore` A command line program to reset the content of the ontology. Does not require + a restart of the Knora-Stack. ## Install @@ -135,7 +137,7 @@ The _lists_ object contains an array of lists. Here an example: ``` the _lists_ element is optional. -## Ontology +### Ontology The _ontology_ object contains the definition of the data model. The ontology has the following elemens: @@ -440,7 +442,7 @@ The properties object has the following fields: } ``` -## JSON for lists +### JSON for lists The JSON schema for uploading hierarchical lists only is simplyfied: ```json @@ -453,7 +455,7 @@ The JSON schema for uploading hierarchical lists only is simplyfied: ``` The definition of the lists is the same as in the full upload of an ontology! -### A full example for creating lists only +#### A full example for creating lists only The following JSON definition assumes that there is a project with the shortcode _0808_. ```json @@ -506,8 +508,27 @@ The following JSON definition assumes that there is a project with the shortcode } ``` +## Reseting the triplestore with `knora-reset-triplestore` +This script reads a JSON file containing the data model (ontology) definition, +connects to the Knora server and creates the data model. + +### Usage: + +```bash +$ knora-reset-triplestore +``` +It supports the following options: + +- _"-s server" | "--server server"_: The URl of the Knora server [default: localhost:3333] +- _"-u username" | "--user username"_: Username to log into Knora [default: root@example.com] +- _"-p password" | "--password password"_: The password for login to the Knora server [default: test] + +For resetting of the triplestore through Knora-API to work, it is necessary to start the Knora-API server +with a configuration parameter allowing this operation (e.g., `KNORA_WEBAPI_ALLOW_RELOAD_OVER_HTTP` +environment variable or the corresponding setting in `application.conf`). + ## Bulk data import -In order to make a bulk data import, a properly formatted XML file has to be created. The python module "knora.py" contains +In order to make a bulk data import, a properly formatted XML file has to be created. The python module "knora" contains classes and methods to facilitate the creation of such a XML file. ## Requirements diff --git a/knora/create_ontology.py b/knora/create_ontology.py index ac963a658..d649850aa 100644 --- a/knora/create_ontology.py +++ b/knora/create_ontology.py @@ -8,7 +8,7 @@ import sys -def main(args): +def program(args): # parse the arguments of the command line parser = argparse.ArgumentParser() parser.add_argument("ontofile", help="path to ontology file") @@ -234,5 +234,11 @@ def list_creator(con: Knora, proj_iri: str, list_iri: str, parent_iri: str, node return nodelist +def main(): + program(sys.argv[1:]) + + if __name__ == '__main__': - main(sys.argv[1:]) + print(sys.argv) + print(sys.argv[1:]) + program(sys.argv[1:]) diff --git a/knora/knora-ctl.py b/knora/knora-ctl.py deleted file mode 100644 index bed445b22..000000000 --- a/knora/knora-ctl.py +++ /dev/null @@ -1,20 +0,0 @@ -import click - - -@click.group() -def cli(): - pass - - -@click.command() -def init(): - click.echo('Initializes and loads data into GraphDB') - - -@click.command() -def reload(): - click.echo('Reloads the ontology cache') - - -cli.add_command(init) -cli.add_command(reload) diff --git a/knora/reset_triplestore.py b/knora/reset_triplestore.py index 449a47151..f600c6fde 100644 --- a/knora/reset_triplestore.py +++ b/knora/reset_triplestore.py @@ -1,17 +1,15 @@ -import os -from typing import List, Set, Dict, Tuple, Optional -from pprint import pprint import argparse -import json -from jsonschema import validate -from knora import KnoraError, Knora import sys +from knora import Knora -def main(args): + +def program(args): # parse the arguments of the command line parser = argparse.ArgumentParser() parser.add_argument("-s", "--server", type=str, default="http://0.0.0.0:3333", help="URL of the Knora server") + parser.add_argument("-u", "--user", default="root@example.com", help="Username for Knora") + parser.add_argument("-p", "--password", default="test", help="The password for login") args = parser.parse_args(args) @@ -20,5 +18,10 @@ def main(args): con.login(args.user, args.password) con.reset_triplestore_content() + +def main(): + program(sys.argv[1:]) + + if __name__ == '__main__': - main(sys.argv[1:]) + program(sys.argv[1:]) diff --git a/setup.py b/setup.py index 7b71da710..a2ccd052b 100644 --- a/setup.py +++ b/setup.py @@ -31,8 +31,7 @@ entry_points={ 'console_scripts': [ 'knora-create-ontology=knora.create_ontology:main', - 'knora-reset-triplestore=knora.reset_triplestore:main', - 'knoractl=knora.knora_ctl:cli' + 'knora-reset-triplestore=knora.reset_triplestore:main' ], }, include_package_data=True,