chiark / gitweb /
make-secnet-sites: Introduce a notion of listish types.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 29 Apr 2017 12:55:40 +0000 (13:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:16 +0000 (19:16 +0100)
A property of such a listish type can be assigned multiple times, and
the values accumulate, and get reported as a list in the output
configuration.

Currently none are defined, so you can't see what this does.

Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
README.make-secnet-sites
make-secnet-sites

index cef436851caf633a9c921791bc83e1b0df91b31b..ea767e912f1616d05de31b8872280c1c18cf0d81 100644 (file)
@@ -117,8 +117,9 @@ INPUT SYNTAX
 
        Finally, the properties.
 
-       If a property has already been defined on an item, then it is an
-       error to try to redefine it.
+       Usually, if a property has already been defined on an item, then
+       it is an error to try to redefine it.  But some properties are
+       list-like: the values are accumulated into a single list.
 
        Mostly, properties are written to corresponding assignments in
        the generated Secnet configuration file, .  The entries below
index c93ce90983c61393d86c68348cb68672a0a58509..f4e86020a45f8e6f807c7037a8fb74ba8f3dc06d 100755 (executable)
@@ -70,7 +70,21 @@ VERSION="0.1.18"
 
 class basetype:
        "Common protocol for configuration types."
-       pass
+       def add(self,obj,w):
+               complain("%s %s already has property %s defined"%
+                       (obj.type,obj.name,w[0]))
+
+class conflist:
+       "A list of some kind of configuration type."
+       def __init__(self,subtype,w):
+               self.subtype=subtype
+               self.list=[subtype(w)]
+       def add(self,obj,w):
+               self.list.append(self.subtype(w))
+       def __str__(self):
+               return ', '.join(map(str, self.list))
+def listof(subtype):
+       return lambda w: conflist(subtype, w)
 
 class single_ipaddr (basetype):
        "An IP address"
@@ -328,8 +342,7 @@ prefix=''
 def set_property(obj,w):
        "Set a property on a configuration node"
        if obj.properties.has_key(w[0]):
-               complain("%s %s already has property %s defined"%
-                       (obj.type,obj.name,w[0]))
+               obj.properties[w[0]].add(obj,w)
        else:
                obj.properties[w[0]]=keywords[w[0]][0](w)