Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
OWL2YAMS
Commits
e4fdd6264aef
Commit
e4fdd626
authored
Oct 15, 2021
by
Noé Gaumont
🐙
Browse files
feat autocreate cube and instance
parent
277c9d654dcc
Pipeline
#88900
canceled with stages
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
owl2yams/__init__.py
View file @
e4fdd626
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
...
...
@@ -119,6 +122,14 @@
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
()
...
...
@@ -146,4 +157,49 @@
schema
=
owl_model_to_yams
(
owl_model
,
args
.
instance_name
)
print
(
serialize_to_python
(
schema
))
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.*'
)
with
open
(
source_path
,
'r'
)
as
f
:
content
=
f
.
read
()
replaced_content
=
driver_regexp
.
sub
(
'db-driver=sqlite'
,
content
)
# FIXME:TODO print auto generated admin pass
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
}
`"
)
setup.py
View file @
e4fdd626
...
...
@@ -14,6 +14,7 @@
author
=
"Fabien Amarger"
author_email
=
"famarger@logilab.fr"
requires
=
{
"cubicweb"
:
">=3.30"
,
"yams"
:
None
,
"rdflib"
:
None
,
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment