Replace sed with python script
sed escaping is wrong: e.g. re.escape() will escape `+`, but with BRE escaped plus is quantifier
This commit is contained in:
parent
03245f192b
commit
0f0a5e92d3
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
|
||||
fname = sys.argv[1]
|
||||
new_fname = fname + '.new'
|
||||
pid_fname = 'tests/shell/3rd/pid'
|
||||
|
||||
with open(pid_fname, 'r') as P:
|
||||
pid = P.read().strip()
|
||||
hostname = socket.gethostname()
|
||||
user = os.environ['USER']
|
||||
|
||||
with codecs.open(fname, 'r', encoding='utf-8') as R:
|
||||
with codecs.open(new_fname, 'w', encoding='utf-8') as W:
|
||||
found_cd = False
|
||||
for line in R:
|
||||
if not found_cd:
|
||||
found_cd = ('cd tests/shell/3rd' in line)
|
||||
continue
|
||||
line = line.replace(pid, 'PID')
|
||||
line = line.replace(hostname, 'HOSTNAME')
|
||||
line = line.replace(user, 'USER')
|
||||
W.write(line)
|
||||
|
||||
os.rename(new_fname, fname)
|
|
@ -24,12 +24,8 @@ run_test() {
|
|||
while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do
|
||||
sleep 1s
|
||||
done
|
||||
sed -i -e "1,3 d" \
|
||||
-e s/$(cat tests/shell/3rd/pid)/PID/g \
|
||||
-e "s/$(python -c 'import re, socket; print (re.escape(socket.gethostname()))')/HOSTNAME/g" \
|
||||
-e "s/$(python -c 'import os, re; print (re.escape(os.environ["USER"]))')/USER/g" \
|
||||
tests/shell/screen.log
|
||||
if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log ; then
|
||||
./tests/test_shells/postproc.py tests/shell/screen.log
|
||||
if ! diff -u tests/test_shells/${SH}.ok tests/shell/screen.log | cat -v ; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
[0m[23m[24m[J[0;38;5;231;48;5;31;1m USER [0;38;5;31;48;5;240;22m [0;38;5;250;48;5;240m⋯ [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240mtests [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240mshell [0;38;5;245;48;5;240;22m [0;38;5;252;48;5;240;1m3rd [0;38;5;240;49;22m [0mPOWERLINE_COMMAND=( $POWERLINE_COMMAND -c ext.shell.theme=default_leftonly )
|
||||
[0m[23m[24m[J[0;38;5;231;48;5;31;1m USER [0;38;5;31;48;5;236;22m [0;38;5;250;48;5;236m BRANCH [0;38;5;236;48;5;240;22m [0;38;5;250;48;5;240m⋯ [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240mtests [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240mshell [0;38;5;245;48;5;240;22m [0;38;5;252;48;5;240;1m3rd [0;38;5;240;49;22m [0mcd .git
|
||||
[0m[23m[24m[J[0;38;5;231;48;5;31;1m USER [0;38;5;31;48;5;236;22m [0;38;5;250;48;5;236m BRANCH [0;38;5;236;48;5;240;22m [0;38;5;250;48;5;240m⋯ [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240mshell [0;38;5;245;48;5;240;22m [0;38;5;250;48;5;240m3rd [0;38;5;245;48;5;240;22m [0;38;5;252;48;5;240;1m.git [0;38;5;240;49;22m [0mcd ..
|
||||
|
|
Loading…
Reference in New Issue