From 7aa4b2d40ab176ceee1800fd6fe115fca6d5c93e Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Fri, 19 Aug 2016 13:37:57 +0200 Subject: [PATCH] Support comments in hostfile, skip empty lines. --- cdist/config.py | 11 +++++++++-- docs/changelog | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cdist/config.py b/cdist/config.py index 31b41781..8d83a072 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -99,8 +99,15 @@ class Config(object): import fileinput try: for host in fileinput.input(files=(source)): - # remove leading and trailing whitespace - yield host.strip() + # remove comment if present + comment_index = host.find('#') + if comment_index >= 0: + host = host[:comment_index] + # remove leading and trailing whitespaces + host = host.strip() + # skip empty lines + if host: + yield host except (IOError, OSError) as e: raise cdist.Error("Error reading hosts from \'{}\'".format( source)) diff --git a/docs/changelog b/docs/changelog index db86de45..12510041 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,6 +1,7 @@ Changelog --------- next: + * Core: Improve hostfile: support comments, skip empty lines (Darko Poljak) * Documentation: Add Parallelization chapter (Darko Poljak) * Core: Add -b, --enable-beta option for enabling beta functionalities (Darko Poljak) * Core: Add -j, --jobs option for parallel execution and add parallel support for global explorers (currently in beta) (Darko Poljak)