Skip to content

Commit

Permalink
Merge pull request #709 from OnroerendErfgoed/develop
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
goessebr authored Jul 4, 2022
2 parents 4566a9e + e2e4e07 commit 9dee5aa
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ python:
- "3.8"
before_install:
- pip install --upgrade pip
- pip install -U setuptools
- pip install setuptools==59.6.0 #https://github.com/pypa/setuptools/issues/3293
install:
- pip install -r requirements-dev.txt
- python setup.py develop
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ keywords:
- vocabulary
- python
license: GPL-3.0
version: 1.0.3
version: 1.1.0
date-released: '2021-12-22'
2 changes: 1 addition & 1 deletion atramhasis/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3

info:
title: Atramhasis API
version: 1.0.3
version: 1.1.0

servers:
- url: '/'
Expand Down
151 changes: 76 additions & 75 deletions atramhasis/scripts/generate_ldf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,30 @@

import json

from atramhasis.errors import (
SkosRegistryNotFoundException
)

from atramhasis.errors import SkosRegistryNotFoundException


def main():
description = """\
Generate a config file for a LDF server.
"""
usage = "usage: %prog config_uri"
parser = optparse.OptionParser(
usage=usage,
description=textwrap.dedent(description)
)
parser = optparse.OptionParser(usage=usage, description=textwrap.dedent(description))
parser.add_option(
'-l', '--location', dest='config_location', type='string',
help='Specify where to put the config file. If not specified, this \
is set to the atramhasis.ldf.config_location from your ini file.'
"-l",
"--location",
dest="config_location",
type="string",
help=(
"Specify where to put the config file. If not specified, this is set to the"
" atramhasis.ldf.config_location from your ini file."
),
)

options, args = parser.parse_args(sys.argv[1:])

if not len(args) >= 1:
print('You must provide at least one argument.')
print("You must provide at least one argument.")
return 2

config_uri = args[0]
Expand All @@ -44,102 +43,104 @@ def main():

config_location = options.config_location
if config_location is None:
config_location = env['registry'].settings.get(
'atramhasis.ldf.config_location',
os.path.abspath(os.path.dirname(config_uri))
config_location = env["registry"].settings.get(
"atramhasis.ldf.config_location", os.path.abspath(os.path.dirname(config_uri))
)

dump_location = env['registry'].settings.get(
'atramhasis.dump_location',
os.path.abspath(os.path.dirname(config_uri))
dump_location = env["registry"].settings.get(
"atramhasis.dump_location", os.path.abspath(os.path.dirname(config_uri))
)

ldf_baseurl = env['registry'].settings.get(
'atramhasis.ldf.baseurl',
None
)
ldf_baseurl = env["registry"].settings.get("atramhasis.ldf.baseurl", None)

ldf_protocol = env['registry'].settings.get(
'atramhasis.ldf.protocol',
None
)
ldf_protocol = env["registry"].settings.get("atramhasis.ldf.protocol", None)

request = env['request']
request = env["request"]

if hasattr(request, 'skos_registry') and request.skos_registry is not None:
if hasattr(request, "skos_registry") and request.skos_registry is not None:
skos_registry = request.skos_registry
else:
raise SkosRegistryNotFoundException() # pragma: no cover
raise SkosRegistryNotFoundException() # pragma: no cover

start_time = time.time()
ldfconfig = {
'title': 'Atramhasis LDF server',
'datasources': {},
'prefixes': {
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
'owl': 'http://www.w3.org/2002/07/owl#',
'xsd': 'http://www.w3.org/2001/XMLSchema#',
'hydra': 'http://www.w3.org/ns/hydra/core#',
'void': 'http://rdfs.org/ns/void#',
'skos': 'http://www.w3.org/2004/02/skos/core#',
'skos-thes': 'http://purl.org/iso25964/skos-thes#'
}
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@ldf/server/^3.0.0/components/context.jsonld",
"@id": "urn:ldf-server:my",
"import": "preset-qpf:config-defaults.json",
"title": "Atramhasis LDF server",
"datasources": [],
"prefixes": [
{"prefix": "rdf", "uri": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"},
{"prefix": "rdfs", "uri": "http://www.w3.org/2000/01/rdf-schema#"},
{"prefix": "owl", "uri": "http://www.w3.org/2002/07/owl#"},
{"prefix": "xsd", "uri": "http://www.w3.org/2001/XMLSchema#"},
{"prefix": "hydra", "uri": "http://www.w3.org/ns/hydra/core#"},
{"prefix": "void", "uri": "http://rdfs.org/ns/void#"},
{"prefix": "skos", "uri": "http://www.w3.org/2004/02/skos/core#"},
{"prefix": "skos-thes", "uri": "http://purl.org/iso25964/skos-thes#"},
],
}

if ldf_baseurl:
ldfconfig['baseURL'] = ldf_baseurl
ldfconfig["baseURL"] = ldf_baseurl

if ldf_protocol:
ldfconfig['protocol'] = ldf_protocol
ldfconfig["protocol"] = ldf_protocol

pids = []
for p in skos_registry.get_providers():
if any([not_shown in p.get_metadata()['subject'] for not_shown in ['external']]):
continue;
pid = p.get_metadata()['id']
continue
pid = p.get_metadata()["id"]
title = p.concept_scheme.label().label if p.concept_scheme.label() else pid
pids.append(pid)
filename = os.path.join(dump_location, '%s-full' % pid)
filename_ttl = filename + '.ttl'
filename_hdt = filename + '.hdt'
if os.path.isfile(filename_hdt):
dumptype = 'HdtDatasource'
dumpfile = filename_hdt
else:
dumptype = 'TurtleDatasource'
dumpfile = filename_ttl
filename = os.path.join(dump_location, "%s-full" % pid)
dumptype = "HdtDatasource"
filetype = "hdtFile"
dumpfile = filename + ".hdt"

if not os.path.isfile(dumpfile):
dumptype = "TurtleDatasource"
filetype = "file"
dumpfile = filename + ".ttl"

sourceconfig = {
'title': p.concept_scheme.label().label if p.concept_scheme.label() else pid,
'type': dumptype,
'settings': {
'file': dumpfile
}
"@id": f"urn:ldf-server:myDatasource{pid}",
"@type": dumptype,
"quads": False, # TODO
"datasourcePath": pid,
"datasourceTitle": title,
filetype: dumpfile,
}

for n in p.concept_scheme.notes:
if n.type in ['definition', 'scopeNote']:
sourceconfig['description'] = n.note
if n.type in ["definition", "scopeNote"]:
sourceconfig["description"] = n.note
break
ldfconfig['datasources'][pid] = sourceconfig

ldfconfig["datasources"].append(sourceconfig)

if len(pids):
sourceconfig = {
'title': 'All conceptschemes',
'type': 'CompositeDatasource',
'description': 'All conceptschemes contained in this Atramhasis instance together.',
'settings': {
'references': pids
}
composite_sourceconfig = {
"@id": "urn:ldf-server:myDatasourcecomposite",
"@type": "CompositeDatasource",
"quads": False, # TODO
"datasourcePath": "composite",
"datasourceTitle": "All conceptschemes",
"description": (
"All conceptschemes contained in this Atramhasis instance together."
),
"compose": [f"urn:ldf-server:myDatasource{pid}" for pid in pids],
}
ldfconfig['datasources']['composite'] = sourceconfig

ldfconfig["datasources"].append(composite_sourceconfig)

config_filename = os.path.join(config_location, 'ldf_server_config.json')
config_filename = os.path.join(config_location, "ldf_server_config.json")

with open(config_filename, 'w') as fp:
with open(config_filename, "w") as fp:
json.dump(ldfconfig, fp, indent=4)

print('Config written to %s.' % config_filename)
print("Config written to %s." % config_filename)

print("--- %s seconds ---" % (time.time() - start_time))

env['closer']()
env["closer"]()
65 changes: 36 additions & 29 deletions atramhasis/static/admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions atramhasis/static/admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atramhasis",
"version": "1.0.0",
"version": "1.1.0",
"description": "Node packages for building Atramhasis.",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,7 @@
"foundation-sites": "~5.5.0"
},
"devDependencies": {
"grunt": "^1.4.1",
"grunt": "^1.5.3",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-copy": "^0.8.2",
"grunt-dojo": "^1.1.2",
Expand Down
Loading

0 comments on commit 9dee5aa

Please sign in to comment.