From 1dd9183252b6b49ff287423ef8b3533919c3940e Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Mon, 19 Jan 2015 14:25:37 -0800 Subject: [PATCH] misc: create prepend_lines helper Signed-off-by: Noah Watkins --- teuthology/misc.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/teuthology/misc.py b/teuthology/misc.py index b818093dfb..6dc366213d 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -661,6 +661,26 @@ def append_lines_to_file(remote, path, lines, sudo=False): # then do a 'mv' to the actual file location move_file(remote, temp_file_path, path, sudo) +def prepend_lines_to_file(remote, path, lines, sudo=False): + """ + Prepend lines to a file. + An intermediate file is used in the same manner as in + Remove_lines_from_list. + """ + + temp_file_path = remote.mktemp() + + data = get_file(remote, path, sudo) + + # add the additional data and write it back out, using a temp file + # in case of connectivity of loss, and then mv it to the + # actual desired location + data = lines + data + write_file(remote, temp_file_path, data) + + # then do a 'mv' to the actual file location + move_file(remote, temp_file_path, path, sudo) + def create_file(remote, path, data="", permissions=str(644), sudo=False): """ -- 2.39.5