Skip to content
Snippets Groups Projects

F deprecate yamlapi

Merged Alexander Kreft requested to merge f-deprecate-yamlapi into dev
All threads resolved!
3 files
+ 127
2
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 30
1
@@ -22,7 +22,7 @@
@@ -22,7 +22,7 @@
# ** end header
# ** end header
#
#
"""YAML interface for the database (caosdb)"""
"""!!! Deprecated !!! YAML interface for the database (caosdb)"""
import yaml
import yaml
from lxml import etree
from lxml import etree
@@ -31,9 +31,14 @@ import re
@@ -31,9 +31,14 @@ import re
import caosdb
import caosdb
import caosdb.common.utils as utils
import caosdb.common.utils as utils
from caosdb.connection.connection import get_connection
from caosdb.connection.connection import get_connection
 
import warnings
def append_sublist(v, newel, def_entity_type):
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:
if v is None:
return
return
for i in v:
for i in v:
@@ -46,6 +51,10 @@ def append_sublist(v, newel, def_entity_type):
@@ -46,6 +51,10 @@ def append_sublist(v, newel, def_entity_type):
def kv_to_xml(k, v):
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)
newel = Element(k)
# code.interact(local=locals())
# code.interact(local=locals())
if isinstance(v, list): # Top level loop
if isinstance(v, list): # Top level loop
@@ -69,10 +78,18 @@ def dict_to_xml(d):
@@ -69,10 +78,18 @@ def dict_to_xml(d):
d: The dictionary (possibly loaded from yaml)
d: The dictionary (possibly loaded from yaml)
to convert to caosdb-xml.
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)
return kv_to_xml("Entities", d)
def yaml_to_xml(yamlstr):
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.
"""Load a yaml document from yamlstr and converts it to XML.
Parameters
Parameters
@@ -86,6 +103,10 @@ def yaml_to_xml(yamlstr):
@@ -86,6 +103,10 @@ def yaml_to_xml(yamlstr):
def process(text):
def process(text):
"""Do some replacements on the original file to obtain valid yaml."""
"""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(
processed = re.sub(
"^(\\s*)-\\s*\\{?(.*)\\}?\\s*$",
"^(\\s*)-\\s*\\{?(.*)\\}?\\s*$",
"\\1- {\\2}",
"\\1- {\\2}",
@@ -98,6 +119,10 @@ def process(text):
@@ -98,6 +119,10 @@ def process(text):
def yaml_file_to_xml(yamlfilename):
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:
with open(yamlfilename, "r") as f:
return yaml_to_xml(process(f.read()))
return yaml_to_xml(process(f.read()))
def insert_yaml_file(yamlfilename, simulate=False):
def insert_yaml_file(yamlfilename, simulate=False):
"""Inserts the contents of 'yamlfilename' into the database.
"""Inserts the contents of 'yamlfilename' into the database.
Set 'simulate' to True if you don't actually want to insert the xml,
Set 'simulate' to True if you don't actually want to insert the xml,
but only receive what would be sent.
but only receive what would be sent.
"""
"""
 
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)
con = get_connection()
con = get_connection()
prs = etree.XMLParser(remove_blank_text=True)
prs = etree.XMLParser(remove_blank_text=True)
sent_xml = etree.tostring(
sent_xml = etree.tostring(
Loading