Skip to content

Commit 6fb67bb

Browse files
committed
Found uncomitted: Adding catalog config we need to tune etc
note: was conflict in docker-compose.dev.local.override.yml -- copied invocation of datalad-catalog create
1 parent 1eb2ddd commit 6fb67bb

File tree

3 files changed

+127
-22
lines changed

3 files changed

+127
-22
lines changed

datalad_registry/overview.py

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33

44
import logging
55

6-
from flask import Blueprint, render_template, request
7-
from sqlalchemy import Text, nullslast, or_
8-
9-
from datalad_registry.models import RepoUrl, URLMetadata, db
6+
import datalad.api as dl
7+
from flask import (
8+
Blueprint,
9+
render_template,
10+
request,
11+
send_from_directory,
12+
)
13+
from sqlalchemy import (
14+
Text,
15+
nullslast,
16+
or_,
17+
)
18+
19+
from datalad_registry.blueprints.api.url_metadata import URLMetadataModel
20+
from datalad_registry.models import (
21+
RepoUrl,
22+
URLMetadata,
23+
db,
24+
)
1025

1126
lgr = logging.getLogger(__name__)
1227
bp = Blueprint("overview", __name__, url_prefix="/overview")
@@ -85,16 +100,12 @@ def overview(): # No type hints due to mypy#7187.
85100
url_filter=filter,
86101
)
87102

88-
import json
89-
from flask import send_from_directory
90-
import datalad.api as dl
91-
92103

93104
# @bp.route('/catalog/', defaults={'path': ''})
94105
# TODO: move from placing dataset identifier within path -- place into query
95-
# TODO: do not use ID may be but use URL, or allow for both -- that would make it possible to make those URLs
96-
# pointing to datasets easier to create/digest for humans
97-
@bp.route('/catalog/<int:id_>/<path:path>')
106+
# TODO: do not use ID may be but use URL, or allow for both -- that would make it
107+
# possible to make those URLs pointing to datasets easier to create/digest for humans
108+
@bp.route("/catalog/<int:id_>/<path:path>")
98109
def send_report(id_, path):
99110
# ds_id = request.args.get("id", None, type=int)
100111
if not path:
@@ -109,17 +120,31 @@ def send_report(id_, path):
109120
repo_url_row = repo_url_row[0]
110121
metadatas = {}
111122
for mr in repo_url_row.metadata_:
112-
if mr.extractor_name not in {'metalad_core', 'bids_dataset', 'metalad_studyminimeta'}:
123+
if mr.extractor_name not in {
124+
"metalad_core",
125+
"bids_dataset",
126+
"metalad_studyminimeta",
127+
}:
113128
continue
114-
# TODO: here metadta record had only @context and @graph and no other fields
115-
# figure out if enough....
116-
m = mr.extracted_metadata
117-
m['type'] = 'dataset'
118-
m['dataset_id'] = repo_url_row.ds_id
129+
# TODO: here metadta record had only @context and @graph and no other
130+
# fields figure out if enough....
131+
m = URLMetadataModel.from_orm(mr).dict()
132+
# lgr.warning(f"ROW: {m}")
133+
m["type"] = "dataset"
134+
m["dataset_id"] = repo_url_row.ds_id
119135
# Didn't want to translate yet
120136
lgr.warning(f"Translating record with keys {m.keys()}")
121-
metadatas[mr.extractor_name] = dl.catalog_translate(m)
122-
# metadatas[mr.extractor_name] = m
123-
lgr.warning(f"ROW: {metadatas}")
137+
m_translated = dl.catalog_translate(m)[0]["translated_metadata"]
138+
metadatas[mr.extractor_name] = m_translated
139+
140+
if "metalad_studyminimeta" not in metadatas:
141+
metadatas["metalad_core"]["name"] = repo_url_row.url
142+
143+
for m in metadatas.values():
144+
m["name"] = repo_url_row.url
145+
lgr.warning(f"URL: {repo_url_row.url!r} {type(repo_url_row.url)}")
146+
dl.catalog_add("/app-catalog", metadata=m)
124147
# TODO: figure out how to pass all the metadata goodness to the catalog
125-
return send_from_directory('/app-catalog', path)
148+
# f'/app-catalog/dataset/{repo_url_row.ds_id}/'
149+
# f'{metadatas['metalad_core']['dataset_version']}'
150+
return send_from_directory("/app-catalog", path)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"catalog_name": "DataCat of Registry",
3+
"logo_path": "",
4+
"link_color": "#fba304",
5+
"link_hover_color": "#af7714",
6+
"social_links": {
7+
"about": null,
8+
"documentation": "https://docs.datalad.org/projects/catalog/en/latest/",
9+
"github": "https://github.com/datalad/datalad-catalog",
10+
"mastodon": "https://fosstodon.org/@datalad",
11+
"x": "https://x.com/datalad"
12+
},
13+
"dataset_options": {
14+
"include_metadata_export": true
15+
},
16+
"property_sources": {
17+
"dataset": {
18+
"dataset_id": {
19+
"rule": "single",
20+
"source": "metalad_core"
21+
},
22+
"dataset_version": {
23+
"rule": "single",
24+
"source": "metalad_core"
25+
},
26+
"type": {
27+
"rule": "single",
28+
"source": "metalad_core"
29+
},
30+
"children": {
31+
"rule": "merge",
32+
"source": "any"
33+
},
34+
"short_name": {},
35+
"description": {
36+
"rule": "priority",
37+
"source": [
38+
"catalog_readme",
39+
"metalad_studyminimeta",
40+
"datacite_gin",
41+
"bids_dataset"
42+
]
43+
},
44+
"doi": {},
45+
"url": {
46+
"rule": "merge",
47+
"source": "any"
48+
},
49+
"authors": {
50+
"rule": "merge",
51+
"source": "any"
52+
},
53+
"keywords": {
54+
"rule": "merge",
55+
"source": "any"
56+
},
57+
"license": {},
58+
"funding": {
59+
"rule": "merge",
60+
"source": "any"
61+
},
62+
"publications": {
63+
"rule": "merge",
64+
"source": "any"
65+
},
66+
"subdatasets": {
67+
"rule": "merge",
68+
"source": "any"
69+
},
70+
"additional_display": {
71+
"rule": "merge",
72+
"source": "any"
73+
},
74+
"top_display": {
75+
"rule": "merge",
76+
"source": "any"
77+
}
78+
}
79+
}
80+
}

docker-compose.dev.local.override.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
command: [
88
"/sbin/my_init", "--",
99
"bash", "-c",
10-
"git config --global --add safe.directory /app && pip3 install -U -e . && pip install -e /metalad && pip install -e /catalog && flask init-db && exec flask run --host=0.0.0.0 --debug"
10+
"git config --global --add safe.directory /app && pip3 install -U -e . && pip install -e /metalad && pip install -e /catalog && flask init-db && datalad catalog-create -c /app-catalog -F /app/datalad_registry/resources/catalog-config.json && exec flask run --host=0.0.0.0 --debug"
1111
]
1212
volumes:
1313
- ./:/app

0 commit comments

Comments
 (0)