Add util.uncomment()
function
copied from fabric v1
This commit is contained in:
parent
88a08fcf8f
commit
f584cf7e16
|
@ -268,3 +268,38 @@ def sed(c, filename, before, after, limit='', use_sudo=False, backup='.bak',
|
||||||
return func(command,
|
return func(command,
|
||||||
# shell=shell
|
# shell=shell
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def uncomment(c, filename, regex, use_sudo=False, char='#', backup='.bak',
|
||||||
|
# shell=False,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
NOTE: This was copied from the upstream ``fabric.contrib.files`` (v1) module.
|
||||||
|
|
||||||
|
Attempt to uncomment all lines in ``filename`` matching ``regex``.
|
||||||
|
|
||||||
|
The default comment delimiter is `#` and may be overridden by the ``char``
|
||||||
|
argument.
|
||||||
|
|
||||||
|
This function uses the `sed` function, and will accept the same
|
||||||
|
``use_sudo``, ``shell`` and ``backup`` keyword arguments that `sed` does.
|
||||||
|
|
||||||
|
`uncomment` will remove a single whitespace character following the comment
|
||||||
|
character, if it exists, but will preserve all preceding whitespace. For
|
||||||
|
example, ``# foo`` would become ``foo`` (the single space is stripped) but
|
||||||
|
`` # foo`` would become `` foo`` (the single space is still stripped,
|
||||||
|
but the preceding 4 spaces are not.)
|
||||||
|
|
||||||
|
.. versionchanged:: 1.6
|
||||||
|
Added the ``shell`` keyword argument.
|
||||||
|
"""
|
||||||
|
return sed(
|
||||||
|
c,
|
||||||
|
filename,
|
||||||
|
before=r'^([[:space:]]*)%s[[:space:]]?' % char,
|
||||||
|
after=r'\1',
|
||||||
|
limit=regex,
|
||||||
|
use_sudo=use_sudo,
|
||||||
|
backup=backup,
|
||||||
|
# shell=shell
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue