
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
			if 'true is the last line' in line:
				break
			line = line.translate({
				ord('\r'): None
			})
			line = line.replace(pid, 'PID')
			line = line.replace(hostname, 'HOSTNAME')
			line = line.replace(user, 'USER')
			W.write(line)

os.rename(new_fname, fname)


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
			if 'true is the last line' in line:
				break
			line = line.translate({
				ord('\r'): None
			})
			line = line.replace(hostname, 'HOSTNAME')
			line = line.replace(user, 'USER')
			line = line.replace(pid, 'PID')
			W.write(line)

os.rename(new_fname, fname)

Fix functional shell tests in travis
Fix functional shell tests in travis

Hostname in travis contains random numbers meaning that it occasionally may 
contain a PID as well. Thus it must be replaced first.
  
  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
  			if 'true is the last line' in line:
  				break
  			line = line.translate({
  				ord('\r'): None
  			})
- 			line = line.replace(pid, 'PID')
  			line = line.replace(hostname, 'HOSTNAME')
  			line = line.replace(user, 'USER')
+ 			line = line.replace(pid, 'PID')
  			W.write(line)
  
  os.rename(new_fname, fname)
  
Fix functional shell tests in travis
## Code Before:

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
			if 'true is the last line' in line:
				break
			line = line.translate({
				ord('\r'): None
			})
			line = line.replace(pid, 'PID')
			line = line.replace(hostname, 'HOSTNAME')
			line = line.replace(user, 'USER')
			W.write(line)

os.rename(new_fname, fname)

## Instruction:
Fix functional shell tests in travis
## Code After:

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
			if 'true is the last line' in line:
				break
			line = line.translate({
				ord('\r'): None
			})
			line = line.replace(hostname, 'HOSTNAME')
			line = line.replace(user, 'USER')
			line = line.replace(pid, 'PID')
			W.write(line)

os.rename(new_fname, fname)
