def insert_line_in_file_after_regex(path, line, after_regex, use_sudo=False):
tmpfile = str(uuid.uuid4())<EOL>get_file(path, tmpfile, use_sudo=use_sudo)<EOL>with open(tmpfile) as f:<EOL><INDENT>original = f.read()<EOL><DEDENT>has_it_changed = False<EOL>if line not in original:<EOL><INDENT>has_it_changed = True<EOL>outfile = str(uuid.uuid4())<EOL>with open(outfile, '<STR_LIT:w>') as output:<EOL><INDENT>for l in original.split('<STR_LIT:\n>'):<EOL><INDENT>output.write(l + '<STR_LIT:\n>')<EOL>if re.match(after_regex, l) is not None:<EOL><INDENT>output.write(line + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT><DEDENT>upload_file(local_path=outfile,<EOL>remote_path=path,<EOL>use_sudo=use_sudo)<EOL>os.unlink(outfile)<EOL><DEDENT>os.unlink(tmpfile)<EOL>return has_it_changed<EOL>
inserts a line in the middle of a file