[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] proposed patch for files.contains
From: |
Thibault Ketterer |
Subject: |
Re: [Fab-user] proposed patch for files.contains |
Date: |
Fri, 19 Aug 2011 15:57:17 +0200 |
oops
you need to modifiy this too
diff --git a/fabric/contrib/files.py b/fabric/contrib/files.py
index 37df85a..0cb4f44 100644
--- a/fabric/contrib/files.py
+++ b/fabric/contrib/files.py
@@ -287,7 +287,7 @@ def contains(filename, text, exact=False,
use_sudo=False, escape
text = "^%s$" % text
with settings(hide('everything'), warn_only=True):
return func('egrep "%s" "%s"' % (
- text.replace('"', r'\"'),
+ text,
filename.replace('"', r'\"')
)).succeeded
On Fri, Aug 19, 2011 at 12:29 PM, Thibault Ketterer
<address@hidden> wrote:
> Hi
> I found astonishing that the contrib.files.contains was not able to
> match a plain text string
> It is somehow related to this http://code.fabfile.org/issues/show/188
> Here is my proposition, a new option in contains to escape or not the
> text string :
>
> diff --git a/fabric/contrib/files.py b/fabric/contrib/files.py
> index 7d9ae77..37df85a 100644
> --- a/fabric/contrib/files.py
> +++ b/fabric/contrib/files.py
> @@ -256,7 +256,7 @@ def comment(filename, regex, use_sudo=False,
> char='#', backup='.
> )
>
>
> -def contains(filename, text, exact=False, use_sudo=False):
> +def contains(filename, text, exact=False, use_sudo=False, escape=False):
> """
> Return True if ``filename`` contains ``text``.
>
> @@ -271,11 +271,18 @@ def contains(filename, text, exact=False,
> use_sudo=False):
>
> If ``use_sudo`` is True, will use `sudo` instead of `run`.
>
> + If ``escape`` is True, text will be regex-escaped, it is not the default
> + to preserve old behavior
> +
> .. versionchanged:: 1.0
> Swapped the order of the ``filename`` and ``text`` arguments to be
> consistent with other functions in this module.
> """
> func = use_sudo and sudo or run
> + if escape:
> + text = re.escape(text).replace('"', r'\"')
> + else:
> + text = text.replace('"', r'\"')
> if exact:
> text = "^%s$" % text
> with settings(hide('everything'), warn_only=True):
>
> --
> Thibault ketterer
>
--
Thibault ketterer