gistfile1.txt
· 650 B · Text
Brut
function peers::cleanup_config() {
local config
config=$(config::config_file)
python3 -c "
import re
config = open('${config}').read()
# Normalize multiple blank lines to single blank line
config = re.sub(r'\n{3,}', '\n\n', config)
# Ensure file ends with single newline
config = config.rstrip('\n') + '\n'
open('${config}', 'w').write(config)
"
}
function peers::remove_block() {
local name="$1"
local config
config=$(config::config_file)
python3 -c "
import re
config = open('${config}').read()
pattern = r'\n\[Peer\]\n# ${name}\n[^\n]+\n[^\n]+\n'
result = re.sub(pattern, '\n', config)
open('${config}', 'w').write(result)
"
}
| 1 | function peers::cleanup_config() { |
| 2 | local config |
| 3 | config=$(config::config_file) |
| 4 | |
| 5 | python3 -c " |
| 6 | import re |
| 7 | config = open('${config}').read() |
| 8 | |
| 9 | # Normalize multiple blank lines to single blank line |
| 10 | config = re.sub(r'\n{3,}', '\n\n', config) |
| 11 | |
| 12 | # Ensure file ends with single newline |
| 13 | config = config.rstrip('\n') + '\n' |
| 14 | |
| 15 | open('${config}', 'w').write(config) |
| 16 | " |
| 17 | } |
| 18 | |
| 19 | function peers::remove_block() { |
| 20 | local name="$1" |
| 21 | local config |
| 22 | config=$(config::config_file) |
| 23 | |
| 24 | python3 -c " |
| 25 | import re |
| 26 | config = open('${config}').read() |
| 27 | pattern = r'\n\[Peer\]\n# ${name}\n[^\n]+\n[^\n]+\n' |
| 28 | result = re.sub(pattern, '\n', config) |
| 29 | open('${config}', 'w').write(result) |
| 30 | " |
| 31 | } |
| 32 |