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
81d2b4df
Commit
81d2b4df
authored
3 years ago
by
Alexander Kreft
Browse files
Options
Downloads
Patches
Plain Diff
DEP: deprecate yamlapi
parent
5ce0a107
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!33
MAINT: change arguments of create_user
,
!25
F deprecate yamlapi
Pipeline
#13675
passed with warnings
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+8
-0
8 additions, 0 deletions
CHANGELOG.md
src/caosdb/yamlapi.py
+34
-4
34 additions, 4 deletions
src/caosdb/yamlapi.py
unittests/test_yamlapi.py
+88
-0
88 additions, 0 deletions
unittests/test_yamlapi.py
with
130 additions
and
4 deletions
CHANGELOG.md
+
8
−
0
View file @
81d2b4df
...
...
@@ -23,6 +23,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated ###
*
`id_query(ids)`
in apiutils
*
The whole yamlapi with the following functions:
*
`append_sublist`
*
`kv_to_xml`
*
`dict_to_xml`
*
`yaml_to_xml`
*
`process`
*
`yaml_file_to_xml`
*
`insert_yaml_file`
### Removed ###
...
...
This diff is collapsed.
Click to expand it.
src/caosdb/yamlapi.py
+
34
−
4
View file @
81d2b4df
...
...
@@ -22,7 +22,11 @@
# ** end header
#
"""
YAML interface for the database (caosdb)
"""
"""
YAML interface for the database (caosdb)
"""
"""
!!! Deprecated !!!
"""
import
yaml
from
lxml
import
etree
...
...
@@ -31,9 +35,12 @@ import re
import
caosdb
import
caosdb.common.utils
as
utils
from
caosdb.connection.connection
import
get_connection
import
warnings
def
append_sublist
(
v
,
newel
,
def_entity_type
):
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
if
v
is
None
:
return
for
i
in
v
:
...
...
@@ -46,6 +53,10 @@ def append_sublist(v, newel, def_entity_type):
def
kv_to_xml
(
k
,
v
):
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
newel
=
Element
(
k
)
# code.interact(local=locals())
if
isinstance
(
v
,
list
):
# Top level loop
...
...
@@ -69,10 +80,18 @@ def dict_to_xml(d):
d: The dictionary (possibly loaded from yaml)
to convert to caosdb-xml.
"""
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
return
kv_to_xml
(
"
Entities
"
,
d
)
def
yaml_to_xml
(
yamlstr
):
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
"""
Load a yaml document from yamlstr and converts it to XML.
Parameters
...
...
@@ -86,6 +105,10 @@ def yaml_to_xml(yamlstr):
def
process
(
text
):
"""
Do some replacements on the original file to obtain valid yaml.
"""
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
processed
=
re
.
sub
(
"
^(
\\
s*)-
\\
s*
\\
{?(.*)
\\
}?
\\
s*$
"
,
"
\\
1- {
\\
2}
"
,
...
...
@@ -98,6 +121,10 @@ def process(text):
def
yaml_file_to_xml
(
yamlfilename
):
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
with
open
(
yamlfilename
,
"
r
"
)
as
f
:
return
yaml_to_xml
(
process
(
f
.
read
()))
...
...
@@ -108,7 +135,10 @@ def insert_yaml_file(yamlfilename, simulate=False):
Set
'
simulate
'
to True if you don
'
t actually want to insert the xml,
but only receive what would be sent.
"""
con
=
get_connection
()
warnings
.
warn
(
"""
This function is deprecated and will be removed with the next release.
Please use caosdb-advanced-user-tools/models/data_model.py for a
similar functionality.
"""
,
DeprecationWarning
)
prs
=
etree
.
XMLParser
(
remove_blank_text
=
True
)
sent_xml
=
etree
.
tostring
(
etree
.
fromstring
(
...
...
This diff is collapsed.
Click to expand it.
unittests/test_yamlapi.py
0 → 100644
+
88
−
0
View file @
81d2b4df
# -*- coding: utf-8 -*-
#
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2021 Alexander Kreft <akreft@trineo.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# ** end header
#
import
os
import
warnings
import
tempfile
from
caosdb.yamlapi
import
(
append_sublist
,
kv_to_xml
,
dict_to_xml
,
yaml_to_xml
,
process
,
yaml_file_to_xml
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
append_sublist
(
None
,
None
,
None
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
kv_to_xml
(
"
None
"
,
"
None
"
)
assert
len
(
w
)
==
1
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
dict_to_xml
(
None
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
yaml_to_xml
(
"
None
"
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
process
(
"
None
"
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
# Cause all warnings to always be triggered.
warnings
.
simplefilter
(
"
always
"
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
tmpfile
=
os
.
path
.
join
(
tmpdirname
,
'
yamlfile
'
)
with
open
(
tmpfile
,
'
w
'
)
as
tf
:
tf
.
write
(
""
)
yaml_file_to_xml
(
tmpfile
)
assert
issubclass
(
w
[
-
1
].
category
,
DeprecationWarning
)
assert
"
This function is deprecated
"
in
str
(
w
[
-
1
].
message
)
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