Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions patchwork/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def contains(c, runner, filename, text, exact=False, escape=True):


@set_runner
def append(c, runner, filename, text, partial=False, escape=True):
def append(c, runner, filename, text, partial=False, escape=True, overwrite=False):
"""
Append string (or list of strings) ``text`` to ``filename``.

Expand Down Expand Up @@ -114,6 +114,8 @@ def append(c, runner, filename, text, partial=False, escape=True):
necessary.
:param bool escape:
Whether to perform regex-oriented escaping on ``text``.
:param bool overwrite:
Whether to overwrite the file or not.
"""
# Normalize non-list input to be a list
if isinstance(text, six.string_types):
Expand All @@ -127,7 +129,11 @@ def append(c, runner, filename, text, partial=False, escape=True):
):
continue
line = line.replace("'", r"'\\''") if escape else line
runner("echo '{}' >> {}".format(line, filename))
if overwrite:
io_redirect = ">"
else:
io_redirect = ">>"
runner("echo '{}' {} {}".format(line, io_redirect, filename))


def _escape_for_regex(text):
Expand Down