# HG changeset patch # User Tero Marttila # Date 1425293957 -7200 # Node ID 668f934bb9587d884c02d357b2635c786160c402 # Parent fbac5a08c9d38de6cb4aeadd5f6231812b2baa51 pvl.dhcp.config: fix build_block() to handle top-level config Blocks diff -r fbac5a08c9d3 -r 668f934bb958 pvl/dhcp/config.py --- a/pvl/dhcp/config.py Mon Mar 02 12:54:27 2015 +0200 +++ b/pvl/dhcp/config.py Mon Mar 02 12:59:17 2015 +0200 @@ -313,17 +313,21 @@ if block.comment: yield build_line((), end="# {comment}".format(comment=block.comment), indent=indent) - - yield build_line(block.key, end=' {', indent=indent, context=block.key[0:1]) + + if block.key: + yield build_line(block.key, end=' {', indent=indent, context=block.key[0:1]) + indent += 1 for item in block.items: - yield build_item(item, indent=indent+1) + yield build_item(item, indent=indent) for subblock in block.blocks: - yield '' + if block.items: + yield '' - for line in build_block(subblock, indent=indent+1): + for line in build_block(subblock, indent=indent): yield line - - yield build_line((), end='}', indent=indent) - + + if block.key: + indent -= 1 + yield build_line((), end='}', indent=indent) diff -r fbac5a08c9d3 -r 668f934bb958 pvl/dhcp/tests.py --- a/pvl/dhcp/tests.py Mon Mar 02 12:54:27 2015 +0200 +++ b/pvl/dhcp/tests.py Mon Mar 02 12:59:17 2015 +0200 @@ -119,7 +119,8 @@ def testBuildConf(self): self.assertLinesEqual( - config.build_block(config.Block(('group', ), [ + config.build_block(config.Block(None, [], [ + config.Block(('group', ), [ ('next-server', 'boot.test'), ('filename', "/debian/wheezy/pxelinux.0"), ('include', "hosts/test.conf"), @@ -129,8 +130,8 @@ ('fixed-address', '192.0.2.1'), ('hardware', 'ethernet', '00:11:22:33:44:55'), ]), - ] - )), + ]), + ])), """ group { next-server boot.test;