2014-01-13 19:37:33 +01:00
|
|
|
#!/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
|
2014-01-17 22:59:19 +01:00
|
|
|
if 'true is the last line' in line:
|
|
|
|
break
|
2014-01-17 18:34:18 +01:00
|
|
|
line = line.translate({
|
|
|
|
ord('\r'): None
|
|
|
|
})
|
2014-01-13 19:37:33 +01:00
|
|
|
line = line.replace(pid, 'PID')
|
|
|
|
line = line.replace(hostname, 'HOSTNAME')
|
|
|
|
line = line.replace(user, 'USER')
|
|
|
|
W.write(line)
|
|
|
|
|
|
|
|
os.rename(new_fname, fname)
|