Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OWL2YAMS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
OWL2YAMS
Compare revisions
675a57449b39f2d34cf16568b46297132887eee9 to 321af9c4f3e3003e11ab65169eeee30b80fe349f
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
cubicweb/owl2yams
Select target project
No results found
321af9c4f3e3003e11ab65169eeee30b80fe349f
Select Git revision
Swap
Target
cubicweb/owl2yams
Select target project
cubicweb/owl2yams
1 result
675a57449b39f2d34cf16568b46297132887eee9
Select Git revision
Branches
branch/default
Tags
1.4.0
v1.0.1
v1.1.0
v1.2.0
v1.2.1
v1.3.0
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (5)
feat autocreate cube and instance
· e4fdd6264aef
Noé Gaumont
authored
3 years ago
e4fdd6264aef
feat(admin_pwd): Display the admin password
· b0bf397b8847
Fabien Amarger
authored
3 years ago
b0bf397b8847
fix(black)
· e8a5b0b2e850
Fabien Amarger
authored
3 years ago
e8a5b0b2e850
feat(doc): Add help command
· ee8d445e892b
Fabien Amarger
authored
3 years ago
ee8d445e892b
feat(dry-run): Add dry-run arg
· 321af9c4f3e3
Fabien Amarger
authored
3 years ago
321af9c4f3e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
owl2yams/__init__.py
+79
-1
79 additions, 1 deletion
owl2yams/__init__.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
80 additions
and
1 deletion
owl2yams/__init__.py
View file @
321af9c4
from
typing
import
Iterable
import
subprocess
import
re
import
os
from
argparse
import
ArgumentParser
from
rdflib
import
Graph
,
RDF
,
RDFS
,
OWL
,
XSD
,
URIRef
# type: ignore
...
...
@@ -120,9 +123,18 @@
return
schema
def
run_and_print_if_error
(
command
):
res
=
subprocess
.
run
(
command
,
shell
=
True
,
capture_output
=
True
)
if
res
.
returncode
!=
0
:
print
(
res
.
stdout
.
decode
())
print
(
res
.
stderr
.
decode
())
exit
(
1
)
return
res
def
main
():
parser
=
ArgumentParser
()
parser
.
add_argument
(
"
--owl-model
"
,
"
-m
"
,
default
=
"
owl2yams/model.owl
"
,
...
...
@@ -123,11 +135,12 @@
def
main
():
parser
=
ArgumentParser
()
parser
.
add_argument
(
"
--owl-model
"
,
"
-m
"
,
default
=
"
owl2yams/model.owl
"
,
help
=
"
Specify the OWL file to translate
"
,
)
parser
.
add_argument
(
"
--instance-name
"
,
"
-n
"
,
default
=
"
owl_instance
"
,
...
...
@@ -129,11 +142,12 @@
)
parser
.
add_argument
(
"
--instance-name
"
,
"
-n
"
,
default
=
"
owl_instance
"
,
help
=
"
Specify the instance name for the CW instance
"
,
)
parser
.
add_argument
(
"
--parse-format
"
,
"
-f
"
,
choices
=
[
"
turtle
"
,
"
xml
"
,
"
n3
"
,
"
nquads
"
,
"
nt
"
,
"
trix
"
],
default
=
"
turtle
"
,
...
...
@@ -134,9 +148,16 @@
)
parser
.
add_argument
(
"
--parse-format
"
,
"
-f
"
,
choices
=
[
"
turtle
"
,
"
xml
"
,
"
n3
"
,
"
nquads
"
,
"
nt
"
,
"
trix
"
],
default
=
"
turtle
"
,
help
=
"
Specify the OWL file serialization
"
,
)
parser
.
add_argument
(
"
--dry-run
"
,
"
-d
"
,
action
=
"
store_true
"
,
help
=
"
Print the YAMS schema only
"
,
)
args
=
parser
.
parse_args
()
...
...
@@ -146,4 +167,61 @@
schema
=
owl_model_to_yams
(
owl_model
,
args
.
instance_name
)
print
(
serialize_to_python
(
schema
))
if
args
.
dry_run
:
print
(
serialize_to_python
(
schema
))
exit
(
0
)
cube_name
=
args
.
instance_name
.
replace
(
"
_
"
,
"
-
"
)
cube_master_folder
=
f
"
cubicweb-
{
cube_name
}
"
print
(
f
"
creating the cube inside the folder
{
cube_master_folder
}
/
"
"
(the schema is there)
"
)
create_cube
=
(
f
"
cubicweb-ctl newcube
{
args
.
instance_name
}
"
'
-s
"
cube representating {args.owl_model}
"'
)
run_and_print_if_error
(
create_cube
)
cube_subfolder
=
cube_master_folder
.
replace
(
"
-
"
,
"
_
"
)
with
open
(
f
"
{
cube_master_folder
}
/
{
cube_subfolder
}
/schema.py
"
,
"
a
"
)
as
f
:
f
.
write
(
serialize_to_python
(
schema
))
# should pip install the cube
pip_install_cube
=
f
"
pip install -e cubicweb-
{
cube_name
}
"
run_and_print_if_error
(
pip_install_cube
)
print
(
f
"
creating the instance
{
args
.
instance_name
}
.
"
f
"
The parameters are in ~/etc/cubicweb.d/
{
args
.
instance_name
}
/
"
)
create_instance
=
(
"
CW_DB_DRIVER=sqlite cubicweb-ctl create
"
f
"
{
args
.
instance_name
}
{
args
.
instance_name
}
-a --no-db-create
"
)
run_and_print_if_error
(
create_instance
)
db_init
=
(
"
CW_DB_DRIVER=sqlite cubicweb-ctl db-create
"
f
"
{
args
.
instance_name
}
-a --drop=y
"
)
run_and_print_if_error
(
db_init
)
source_path
=
os
.
path
.
expanduser
(
f
"
~/etc/cubicweb.d/
{
args
.
instance_name
}
/sources
"
)
# The source file has to be modified to include sqlite
driver_regexp
=
re
.
compile
(
"
db-driver.*
"
)
admin_pass
=
re
.
compile
(
"
password=(.*)
"
)
with
open
(
source_path
,
"
r
"
)
as
f
:
content
=
f
.
read
()
replaced_content
=
driver_regexp
.
sub
(
"
db-driver=sqlite
"
,
content
)
admin_pwd
=
next
(
admin_pass
.
finditer
(
content
)).
group
(
1
)
with
open
(
source_path
,
"
w
"
)
as
f
:
f
.
write
(
replaced_content
)
print
(
"
Congratulation ! You can run your instance with :
"
f
"
`cubicweb-ctl pyramid -D -l info
{
args
.
instance_name
}
`
"
)
print
(
f
"
(admin password:
{
admin_pwd
}
(from
{
source_path
}
)
"
)
This diff is collapsed.
Click to expand it.
setup.py
View file @
321af9c4
...
...
@@ -14,6 +14,7 @@
author
=
"
Fabien Amarger
"
author_email
=
"
famarger@logilab.fr
"
requires
=
{
"
cubicweb
"
:
"
>=3.30
"
,
"
yams
"
:
None
,
"
rdflib
"
:
None
,
}
...
...
This diff is collapsed.
Click to expand it.