move file_to_list to cdist

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-10-07 09:29:22 +02:00
commit e26f612012
3 changed files with 16 additions and 23 deletions

View file

@ -34,3 +34,17 @@ class MissingEnvironmentVariableError(Error):
def __str__(self):
return 'Missing required environment variable: ' + str(self.name)
def file_to_list(filename):
"""Return list from \n seperated file"""
if os.path.isfile(filename):
file_fd = open(filename, "r")
lines = file_fd.readlines()
file_fd.close()
# Remove \n from all lines
lines = map(lambda s: s.strip(), lines)
else:
lines = []
return lines