diff --git a/cdist/config.py b/cdist/config.py index 8d83a072..2f28a22f 100644 --- a/cdist/config.py +++ b/cdist/config.py @@ -89,6 +89,25 @@ class Config(object): self.local.create_files_dirs() self.remote.create_files_dirs() + @staticmethod + def hostfile_process_line(line): + """Return host from read line or None if no host present.""" + if not line: + return None + # remove comment if present + comment_index = line.find('#') + if comment_index >= 0: + host = line[:comment_index] + else: + host = line + # remove leading and trailing whitespaces + host = host.strip() + # skip empty lines + if host: + return host + else: + return None + @staticmethod def hosts(source): """Yield hosts from source. @@ -99,13 +118,7 @@ class Config(object): import fileinput try: for host in fileinput.input(files=(source)): - # 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 + host = Config.hostfile_process_line(host) if host: yield host except (IOError, OSError) as e: