Skip to content

Added an option to force overwrite existing remote files. #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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