nuno ревизий этого фрагмента 1 month ago. К ревизии
1 file changed, 31 insertions
gistfile1.txt(файл создан)
| @@ -0,0 +1,31 @@ | |||
| 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 | + | } | |
Новее
Позже