Skip to content

Commit

Permalink
Separate raw changes into different schema for now
Browse files Browse the repository at this point in the history
Signed-off-by: ruffsl <[email protected]>
  • Loading branch information
ruffsl committed Aug 8, 2019
1 parent 0dca9b3 commit a67dbc7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
17 changes: 10 additions & 7 deletions sros2/scripts/dds_sql_to_sros2_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,24 @@ def df_to_dds_policy(df):
def dds_policy_to_sros2_policy(dds_policy):

# Parse files
policy_xsd = etree.XMLSchema(
sros2_policy_xsd = etree.XMLSchema(
etree.parse(
get_policy_schema('policy.xsd')))
demangle_xsl = etree.XSLT(
dds_policy_xsd = etree.XMLSchema(
etree.parse(
get_transport_schema('dds', 'policy.xsd')))
dds_demangle_xsl = etree.XSLT(
etree.parse(
get_transport_template('dds', 'demangle.xsl')))

# Validate policy schema
policy_xsd.assertValid(dds_policy)
# Validate input schema
dds_policy_xsd.assertValid(dds_policy)

# Transform policy
sros2_policy = demangle_xsl(dds_policy)
sros2_policy = dds_demangle_xsl(dds_policy)

# Validate policy schema
policy_xsd.assertValid(sros2_policy)
# Validate output schema
sros2_policy_xsd.assertValid(sros2_policy)

return sros2_policy

Expand Down
56 changes: 56 additions & 0 deletions sros2/sros2/policy/schemas/dds/policy.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="http://www.w3.org/2001/03/xml.xsd" />
<!-- TODO: Use namespaces for xs:import so schemas can be DRY -->

<xs:element name="policy" type="Policy" />
<xs:complexType name="Policy">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="profiles" type="Profiles" />
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required" />
</xs:complexType>

<xs:complexType name="Profiles">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="profile" type="Profile" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="Profile">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="raws" minOccurs="1" type="RawExpressionList" />
</xs:choice>
</xs:sequence>
<xs:attribute name="ns" type="xs:string" use="required" />
<xs:attribute name="node" type="xs:string" use="required" />
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:complexType name="RawExpressionList">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="raw" type="Expression" />
</xs:sequence>
<xs:attribute name="publish" type="RuleQualifier" use="optional" />
<xs:attribute name="relay" type="RuleQualifier" use="optional" />
<xs:attribute name="subscribe" type="RuleQualifier" use="optional" />
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:simpleType name="Expression">
<xs:restriction base="xs:string" />
</xs:simpleType>

<xs:simpleType name="RuleQualifier">
<xs:restriction base="xs:string">
<xs:enumeration value="ALLOW" />
<xs:enumeration value="DENY" />
</xs:restriction>
</xs:simpleType>

</xs:schema>
11 changes: 0 additions & 11 deletions sros2/sros2/policy/schemas/policy.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<xs:complexType name="Profile">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="raws" minOccurs="1" type="RawExpressionList" />
<xs:element name="topics" minOccurs="1" type="TopicExpressionList" />
<xs:element name="services" minOccurs="1" type="ServicesExpressionList" />
<xs:element name="actions" minOccurs="1" type="ActionsExpressionList" />
Expand All @@ -35,16 +34,6 @@
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:complexType name="RawExpressionList">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="raw" type="Expression" />
</xs:sequence>
<xs:attribute name="publish" type="RuleQualifier" use="optional" />
<xs:attribute name="relay" type="RuleQualifier" use="optional" />
<xs:attribute name="subscribe" type="RuleQualifier" use="optional" />
<xs:attribute ref="xml:base" />
</xs:complexType>

<xs:complexType name="TopicExpressionList">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="topic" type="Expression" />
Expand Down

0 comments on commit a67dbc7

Please sign in to comment.