Форум сайта python.su
0
подскажите пожалуйста, начал использовать fabric и не знаю как правильно решить следующую задачу
есть файл /etc/bash.bashrc хочу в нем раскоментирвоать блок
# enable bash completion in interactive shells #if ! shopt -oq posix; then # if [ -f /usr/share/bash-completion/bash_completion ]; then # . /usr/share/bash-completion/bash_completion # elif [ -f /etc/bash_completion ]; then # . /etc/bash_completion # fi #fi
from fabric.contrib.files import uncomment uncomment('/etc/bash.bashrc','if ! shopt -oq posix; then') uncomment('/etc/bash.bashrc','if [ -f /usr/share/bash-completion/bash_completion ]; then") uncomment('/etc/bash.bashrc',' . /usr/share/bash-completion/bash_completion') uncomment('/etc/bash.bashrc',' elif [ -f /etc/bash_completion ]; then') uncomment('/etc/bash.bashrc',' . /etc/bash_completion') uncomment('/etc/bash.bashrc',' fi') uncomment('/etc/bash.bashrc','fi')

Офлайн
9
Попробуйте так:
uncomment('/etc/bash.bashrc','#if ! shopt -oq posix; then', char='#')
Офлайн
0
первая строчка как раз срабатывает
а вот дальше нет
uncomment('/etc/bash.bashrc','if ! shopt -oq posix; then') uncomment('/etc/bash.bashrc','if [ -f /usr/share/bash-completion/bash_completion ]; then') uncomment('/etc/bash.bashrc',' . /usr/share/bash-completion/bash_completion') uncomment('/etc/bash.bashrc',' elif [ -f /etc/bash_completion ]; then') uncomment('/etc/bash.bashrc',' . /etc/bash_completion') uncomment('/etc/bash.bashrc',' fi') uncomment('/etc/bash.bashrc','fi')
[root@127.0.0.1] run: sed -i.bak -r -e '/if ! shopt -oq posix; then/ s/^([[:space:]]*)#[[:space:]]?/\1/g' "$(echo /etc/bash.bashrc)" [root@127.0.0.1] run: sed -i.bak -r -e '/if [ -f /usr/share/bash-completion/bash_completion ]; then/ s/^([[:space:]]*)#[[:space:]]?/\1/g' "$(echo /etc/bash.bashrc)" [root@127.0.0.1] out: sed: -e выражение #1, символ 61: Неверный конец диапазона [root@127.0.0.1] out: Fatal error: run() received nonzero return code 1 while executing! Requested: sed -i.bak -r -e '/if [ -f /usr/share/bash-completion/bash_completion ]; then/ s/^([[:space:]]*)#[[:space:]]?/\1/g' "$(echo /etc/bash.bashrc)" Executed: sed -i.bak -r -e '/if [ -f /usr/share/bash-completion/bash_completion ]; then/ s/^([[:space:]]*)#[[:space:]]?/\1/g' "$(echo /etc/bash.bashrc)" Aborting. Disconnecting from 127.0.0.1... done.
Отредактировано Danik (Окт. 25, 2014 15:15:20)
Офлайн