Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
caosdb
Software
caosdb-pylib
Commits
ede2a96f
Commit
ede2a96f
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: make retreive substructure work also for referenced records
parent
6710e860
No related branches found
No related tags found
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#19998
failed
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/utils/plantuml.py
+53
-11
53 additions, 11 deletions
src/caosdb/utils/plantuml.py
with
53 additions
and
11 deletions
src/caosdb/utils/plantuml.py
+
53
−
11
View file @
ede2a96f
...
@@ -34,10 +34,13 @@ plantuml FILENAME.pu -> FILENAME.png
...
@@ -34,10 +34,13 @@ plantuml FILENAME.pu -> FILENAME.png
"""
"""
import
os
import
os
import
shutil
import
caosdb
as
db
import
caosdb
as
db
from
caosdb.common.datatype
import
is_reference
,
get_referenced_recordtype
from
caosdb.common.datatype
import
is_reference
,
get_referenced_recordtype
from
typing
import
Optional
REFERENCE
=
"
REFERENCE
"
REFERENCE
=
"
REFERENCE
"
...
@@ -263,6 +266,15 @@ def retrieve_substructure(start_record_types, depth, result_id_set=None, result_
...
@@ -263,6 +266,15 @@ def retrieve_substructure(start_record_types, depth, result_id_set=None, result_
if
is_reference
(
prop
.
datatype
)
and
prop
.
datatype
!=
db
.
FILE
and
depth
>
0
:
if
is_reference
(
prop
.
datatype
)
and
prop
.
datatype
!=
db
.
FILE
and
depth
>
0
:
rt
=
db
.
RecordType
(
name
=
get_referenced_recordtype
(
prop
.
datatype
)).
retrieve
()
rt
=
db
.
RecordType
(
name
=
get_referenced_recordtype
(
prop
.
datatype
)).
retrieve
()
retrieve_substructure
([
rt
],
depth
-
1
,
result_id_set
,
result_container
,
False
)
retrieve_substructure
([
rt
],
depth
-
1
,
result_id_set
,
result_container
,
False
)
# TODO: clean up this hack
# TODO: make it also work for files
if
is_reference
(
prop
.
datatype
)
and
prop
.
value
is
not
None
:
r
=
db
.
Record
(
id
=
prop
.
value
).
retrieve
()
retrieve_substructure
([
r
],
depth
-
1
,
result_id_set
,
result_container
,
False
)
if
r
.
id
not
in
result_id_set
:
result_container
.
append
(
r
)
result_id_set
.
add
(
r
.
id
)
if
prop
.
id
not
in
result_id_set
:
if
prop
.
id
not
in
result_id_set
:
result_container
.
append
(
prop
)
result_container
.
append
(
prop
)
...
@@ -281,7 +293,10 @@ def retrieve_substructure(start_record_types, depth, result_id_set=None, result_
...
@@ -281,7 +293,10 @@ def retrieve_substructure(start_record_types, depth, result_id_set=None, result_
return
None
return
None
def
to_graphics
(
recordtypes
,
filename
):
def
to_graphics
(
recordtypes
:
list
[
db
.
Entity
],
filename
:
str
,
output_dirname
:
Optional
[
str
]
=
None
,
formats
:
list
[
str
]
=
[
"
tsvg
"
],
silent
:
bool
=
True
):
"""
Calls recordtypes_to_plantuml_string(), saves result to file and
"""
Calls recordtypes_to_plantuml_string(), saves result to file and
creates an svg image
creates an svg image
...
@@ -293,17 +308,44 @@ def to_graphics(recordtypes, filename):
...
@@ -293,17 +308,44 @@ def to_graphics(recordtypes, filename):
Iterable with the entities to be displayed.
Iterable with the entities to be displayed.
filename : str
filename : str
filename of the image without the extension(e.g. data_structure;
filename of the image without the extension(e.g. data_structure;
also without the preceeding path.
data_structure.pu and data_structure.svg will be created.)
data_structure.pu and data_structure.svg will be created.)
output_dirname : str
the destination directory for the resulting images as defined by the
"
-o
"
option by plantuml
default is to use current working dir
formats : list[str]
list of target formats as defined by the -t
"
...
"
options by plantuml, e.g.
"
tsvg
"
silent : bool
Don
'
t output messages.
"""
"""
pu
=
recordtypes_to_plantuml_string
(
recordtypes
)
pu
=
recordtypes_to_plantuml_string
(
recordtypes
)
pu_filename
=
filename
+
"
.pu
"
if
output_dirname
is
None
:
with
open
(
pu_filename
,
"
w
"
)
as
pu_file
:
output_dirname
=
os
.
getcwd
()
pu_file
.
write
(
pu
)
allowed_formats
=
[
cmd
=
"
plantuml -tsvg %s
"
%
pu_filename
"
tpng
"
,
"
tsvg
"
,
"
teps
"
,
"
tpdf
"
,
"
tvdx
"
,
"
txmi
"
,
print
(
"
Executing:
"
,
cmd
)
"
tscxml
"
,
"
thtml
"
,
"
ttxt
"
,
"
tutxt
"
,
"
tlatex
"
,
"
tlatex:nopreamble
"
]
if
os
.
system
(
cmd
)
!=
0
:
with
tempfile
.
TemporaryDirectory
()
as
td
:
raise
Exception
(
"
An error occured during the execution of plantuml.
"
"
Is plantuml installed?
"
)
pu_filename
=
os
.
path
.
join
(
td
,
filename
+
"
.pu
"
)
with
open
(
pu_filename
,
"
w
"
)
as
pu_file
:
pu_file
.
write
(
pu
)
for
format
in
formats
:
extension
=
format
[
1
:]
if
"
:
"
in
extension
:
extension
=
extension
[:
extension
.
index
(
"
:
"
)]
if
format
not
in
allowed_formats
:
raise
RuntimeError
(
"
Format not allowed.
"
)
cmd
=
"
plantuml -{} {}
"
.
format
(
format
,
pu_filename
)
if
not
silent
:
print
(
"
Executing:
"
,
cmd
)
if
os
.
system
(
cmd
)
!=
0
:
# TODO: replace with subprocess.run
raise
Exception
(
"
An error occured during the execution of plantuml.
"
"
Is plantuml installed?
"
)
shutil
.
copy
(
os
.
path
.
join
(
td
,
filename
+
"
.
"
+
extension
),
output_dirname
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment