hgbook
diff en/examples/run-example @ 191:f078515438d2
Account for changed output.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon Apr 16 14:39:20 2007 -0700 (2007-04-16) |
parents | 5f305adeb584 |
children | 06ab90119fa6 |
line diff
1.1 --- a/en/examples/run-example Tue Mar 27 15:04:47 2007 -0700 1.2 +++ b/en/examples/run-example Mon Apr 16 14:39:20 2007 -0700 1.3 @@ -99,21 +99,22 @@ 1.4 1.5 timeout = 5 1.6 1.7 - def read(self): 1.8 + def read(self, hint): 1.9 events = self.poll.poll(self.timeout * 1000) 1.10 if not events: 1.11 - print >> sys.stderr, '[timed out after %d seconds]' % self.timeout 1.12 + print >> sys.stderr, ('[%stimed out after %d seconds]' % 1.13 + (hint, self.timeout)) 1.14 os.kill(self.pid, signal.SIGHUP) 1.15 return '' 1.16 return os.read(self.cfd, 1024) 1.17 1.18 - def receive(self): 1.19 + def receive(self, hint): 1.20 out = cStringIO.StringIO() 1.21 while True: 1.22 try: 1.23 if self.verbose: 1.24 sys.stderr.write('< ') 1.25 - s = self.read() 1.26 + s = self.read(hint) 1.27 except OSError, err: 1.28 if err.errno == errno.EIO: 1.29 return '', '' 1.30 @@ -127,9 +128,9 @@ 1.31 if s.endswith(self.ps2): 1.32 return self.ps2, s.replace('\r\n', '\n')[:-len(self.ps2)] 1.33 1.34 - def sendreceive(self, s): 1.35 + def sendreceive(self, s, hint): 1.36 self.send(s) 1.37 - ps, r = self.receive() 1.38 + ps, r = self.receive(hint) 1.39 if r.startswith(s): 1.40 r = r[len(s):] 1.41 return ps, r 1.42 @@ -205,13 +206,15 @@ 1.43 ] 1.44 1.45 err = False 1.46 + read_hint = '' 1.47 1.48 try: 1.49 try: 1.50 # eat first prompt string from shell 1.51 - self.read() 1.52 + self.read(read_hint) 1.53 # setup env and prompt 1.54 - ps, output = self.sendreceive('source %s\n' % rcfile) 1.55 + ps, output = self.sendreceive('source %s\n' % rcfile, 1.56 + read_hint) 1.57 for hunk in self.parse(): 1.58 # is this line a processing instruction? 1.59 m = self.pi_re.match(hunk) 1.60 @@ -231,6 +234,7 @@ 1.61 err |= self.rename_output(ofp_basename, ignore) 1.62 if out: 1.63 ofp_basename = '%s.%s' % (self.name, out) 1.64 + read_hint = ofp_basename + ' ' 1.65 ofp = open(ofp_basename + '.tmp', 'w') 1.66 else: 1.67 ofp = None 1.68 @@ -238,7 +242,7 @@ 1.69 ignore.append(rest) 1.70 elif hunk.strip(): 1.71 # it's something we should execute 1.72 - newps, output = self.sendreceive(hunk) 1.73 + newps, output = self.sendreceive(hunk, read_hint) 1.74 if not ofp: 1.75 continue 1.76 # first, print the command we ran 1.77 @@ -260,7 +264,7 @@ 1.78 raise 1.79 else: 1.80 try: 1.81 - ps, output = self.sendreceive('exit\n') 1.82 + ps, output = self.sendreceive('exit\n', read_hint) 1.83 if ofp is not None: 1.84 ofp.write(output) 1.85 ofp.close()