hgbook
diff en/examples/run-example @ 172:5f305adeb584
Try to tighten up the run environment to make things more reproducible.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue Mar 27 15:04:47 2007 -0700 (2007-03-27) |
parents | f8b5b782e150 |
children | 754312dc23d5 |
line diff
1.1 --- a/en/examples/run-example Mon Mar 26 23:20:59 2007 -0700 1.2 +++ b/en/examples/run-example Tue Mar 27 15:04:47 2007 -0700 1.3 @@ -46,6 +46,13 @@ 1.4 raise 1.5 return False 1.6 1.7 +def find_path_to(program): 1.8 + for p in os.environ.get('PATH', os.defpath).split(os.pathsep): 1.9 + name = os.path.join(p, program) 1.10 + if os.access(name, os.X_OK): 1.11 + return p 1.12 + return None 1.13 + 1.14 class example: 1.15 shell = '/usr/bin/env bash' 1.16 ps1 = '__run_example_ps1__ ' 1.17 @@ -147,6 +154,16 @@ 1.18 print >> rcfp, 'PS1="%s"' % self.ps1 1.19 print >> rcfp, 'PS2="%s"' % self.ps2 1.20 print >> rcfp, 'unset HISTFILE' 1.21 + path = ['/usr/bin', '/bin'] 1.22 + hg = find_path_to('hg') 1.23 + if hg and hg not in path: 1.24 + path.append(hg) 1.25 + def re_export(envar): 1.26 + v = os.getenv(envar) 1.27 + if v is not None: 1.28 + print >> rcfp, 'export ' + envar + '=' + v 1.29 + print >> rcfp, 'export PATH=' + ':'.join(path) 1.30 + re_export('PYTHONPATH') 1.31 print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd() 1.32 print >> rcfp, 'export HGMERGE=merge' 1.33 print >> rcfp, 'export LANG=C' 1.34 @@ -160,8 +177,8 @@ 1.35 sys.stderr.flush() 1.36 self.pid, self.cfd = pty.fork() 1.37 if self.pid == 0: 1.38 - cmdline = ['/usr/bin/env', 'bash', '--noediting', '--noprofile', 1.39 - '--norc'] 1.40 + cmdline = ['/usr/bin/env', '-i', 'bash', '--noediting', 1.41 + '--noprofile', '--norc'] 1.42 try: 1.43 os.execv(cmdline[0], cmdline) 1.44 except OSError, err: