Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: command line scripts
  • Loading branch information
subotic committed Jun 20, 2019
1 parent d078e4a commit 732a0fa
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
33 changes: 27 additions & 6 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions knora/create_ontology.py
Expand Up @@ -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")
Expand Down Expand Up @@ -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:])
20 changes: 0 additions & 20 deletions knora/knora-ctl.py

This file was deleted.

19 changes: 11 additions & 8 deletions 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)

Expand All @@ -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:])
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -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,
Expand Down

0 comments on commit 732a0fa

Please sign in to comment.