diff options
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/util.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index d8e83ab8d..ce5dc51f5 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -182,16 +182,20 @@ def call(command, flag='', shell=None, input=None, timeout=None, env=None, return code -def read_file(fname, defaultonfailure=None): +def read_file(fname, defaultonfailure=None, strip_end=True): """ - read the content of a file, stripping any end characters (space, newlines) + read the content of a file, optionally stripping any end characters (space, newlines) should defaultonfailure be not None, it is returned on failure to read """ try: """ Read a file to string """ with open(fname, 'r') as f: - data = f.read().strip() - return data + data = f.read() + + if strip_end: + return data.strip() + else: + return data except Exception as e: if defaultonfailure is not None: return defaultonfailure |