Mercurial > hgbook
comparison 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, 27 Mar 2007 15:04:47 -0700 |
parents | f8b5b782e150 |
children | 754312dc23d5 |
comparison
equal
deleted
inserted
replaced
171:8c1703a98266 | 172:5f305adeb584 |
---|---|
44 except OSError, err: | 44 except OSError, err: |
45 if err.errno != errno.ENOENT: | 45 if err.errno != errno.ENOENT: |
46 raise | 46 raise |
47 return False | 47 return False |
48 | 48 |
49 def find_path_to(program): | |
50 for p in os.environ.get('PATH', os.defpath).split(os.pathsep): | |
51 name = os.path.join(p, program) | |
52 if os.access(name, os.X_OK): | |
53 return p | |
54 return None | |
55 | |
49 class example: | 56 class example: |
50 shell = '/usr/bin/env bash' | 57 shell = '/usr/bin/env bash' |
51 ps1 = '__run_example_ps1__ ' | 58 ps1 = '__run_example_ps1__ ' |
52 ps2 = '__run_example_ps2__ ' | 59 ps2 = '__run_example_ps2__ ' |
53 pi_re = re.compile(r'#\$\s*(name|ignore):\s*(.*)$') | 60 pi_re = re.compile(r'#\$\s*(name|ignore):\s*(.*)$') |
145 rcfile = os.path.join(tmpdir, '.bashrc') | 152 rcfile = os.path.join(tmpdir, '.bashrc') |
146 rcfp = open(rcfile, 'w') | 153 rcfp = open(rcfile, 'w') |
147 print >> rcfp, 'PS1="%s"' % self.ps1 | 154 print >> rcfp, 'PS1="%s"' % self.ps1 |
148 print >> rcfp, 'PS2="%s"' % self.ps2 | 155 print >> rcfp, 'PS2="%s"' % self.ps2 |
149 print >> rcfp, 'unset HISTFILE' | 156 print >> rcfp, 'unset HISTFILE' |
157 path = ['/usr/bin', '/bin'] | |
158 hg = find_path_to('hg') | |
159 if hg and hg not in path: | |
160 path.append(hg) | |
161 def re_export(envar): | |
162 v = os.getenv(envar) | |
163 if v is not None: | |
164 print >> rcfp, 'export ' + envar + '=' + v | |
165 print >> rcfp, 'export PATH=' + ':'.join(path) | |
166 re_export('PYTHONPATH') | |
150 print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd() | 167 print >> rcfp, 'export EXAMPLE_DIR="%s"' % os.getcwd() |
151 print >> rcfp, 'export HGMERGE=merge' | 168 print >> rcfp, 'export HGMERGE=merge' |
152 print >> rcfp, 'export LANG=C' | 169 print >> rcfp, 'export LANG=C' |
153 print >> rcfp, 'export LC_ALL=C' | 170 print >> rcfp, 'export LC_ALL=C' |
154 print >> rcfp, 'export TZ=GMT' | 171 print >> rcfp, 'export TZ=GMT' |
158 rcfp.close() | 175 rcfp.close() |
159 sys.stdout.flush() | 176 sys.stdout.flush() |
160 sys.stderr.flush() | 177 sys.stderr.flush() |
161 self.pid, self.cfd = pty.fork() | 178 self.pid, self.cfd = pty.fork() |
162 if self.pid == 0: | 179 if self.pid == 0: |
163 cmdline = ['/usr/bin/env', 'bash', '--noediting', '--noprofile', | 180 cmdline = ['/usr/bin/env', '-i', 'bash', '--noediting', |
164 '--norc'] | 181 '--noprofile', '--norc'] |
165 try: | 182 try: |
166 os.execv(cmdline[0], cmdline) | 183 os.execv(cmdline[0], cmdline) |
167 except OSError, err: | 184 except OSError, err: |
168 print >> sys.stderr, '%s: %s' % (cmdline[0], err.strerror) | 185 print >> sys.stderr, '%s: %s' % (cmdline[0], err.strerror) |
169 sys.stderr.flush() | 186 sys.stderr.flush() |