pvl.dhcp.config: Block(comment=...)
authorTero Marttila <terom@paivola.fi>
Sun, 01 Mar 2015 22:38:02 +0200
changeset 668 794f943c835d
parent 667 2d5750797b8a
child 669 83e9bff09a0b
pvl.dhcp.config: Block(comment=...)
pvl/dhcp/config.py
--- a/pvl/dhcp/config.py	Sun Mar 01 22:27:03 2015 +0200
+++ b/pvl/dhcp/config.py	Sun Mar 01 22:38:02 2015 +0200
@@ -54,7 +54,7 @@
         A block in a dhcp conf includes parameters and sub-blocks.
     """
 
-    def __init__ (self, key, items=None, blocks=None):
+    def __init__ (self, key, items=None, blocks=None, comment=None):
         """
             key: tuple      - name of block
         """
@@ -62,6 +62,7 @@
         self.key = key
         self.items = items or [ ]
         self.blocks = blocks or [ ]
+        self.comment = comment
 
     def __str__ (self):
         return ' '.join(self.key)
@@ -246,7 +247,7 @@
 
     return build_line(item, end=';', **opts)
 
-def build_block (block, indent=0, comment=None):
+def build_block (block, indent=0):
     """
         Build a complete Block, recursively, yielding output lines.
 
@@ -267,8 +268,8 @@
         }
     """
 
-    if comment:
-        yield build_line((), end="# {comment}".format(comment=comment), indent=indent)
+    if block.comment:
+        yield build_line((), end="# {comment}".format(comment=block.comment), indent=indent)
 
     yield build_line(block.key, end=' {', indent=indent)