Найти - Пользователи
Полная версия: вопрос по fabric
Начало » Python для новичков » вопрос по fabric
1
Danik
подскажите пожалуйста, начал использовать 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')

но не получается

как можно решить задачку, подскажите пожалуйста
alexsis
Попробуйте так:
uncomment('/etc/bash.bashrc','#if ! shopt -oq posix; then', char='#')
Danik
первая строчка как раз срабатывает
а вот дальше нет

   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.

пробовал экранировать - безуспешно
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB