hgbook

diff en/examples/run-example @ 566:27043f385f3f

Get autogeneration of examples more or less working.
author Bryan O'Sullivan <bos@serpentine.com>
date Mon Mar 09 22:55:38 2009 -0700 (2009-03-09)
parents 8a9c66da6fcb
children 60ee738fdc0e
line diff
     1.1 --- a/en/examples/run-example	Mon Mar 09 21:40:12 2009 -0700
     1.2 +++ b/en/examples/run-example	Mon Mar 09 22:55:38 2009 -0700
     1.3 @@ -65,6 +65,8 @@
     1.4      
     1.5      timeout = 10
     1.6  
     1.7 +    entities = dict.fromkeys(l.rstrip() for l in open('auto-snippets.xml'))
     1.8 +
     1.9      def __init__(self, name, verbose, keep_change):
    1.10          self.name = name
    1.11          self.verbose = verbose
    1.12 @@ -240,6 +242,11 @@
    1.13                                  err |= self.rename_output(ofp_basename, ignore)
    1.14                              if out:
    1.15                                  ofp_basename = '%s.%s' % (self.name, out)
    1.16 +                                norm = os.path.normpath(ofp_basename)
    1.17 +                                example.entities[
    1.18 +                                    '<!ENTITY "interaction.%s" '
    1.19 +                                    'SYSTEM "results/%s.out">'
    1.20 +                                    % (norm, norm)] = 1
    1.21                                  read_hint = ofp_basename + ' '
    1.22                                  ofp = open(result_name(ofp_basename + '.tmp'),
    1.23                                             'w')
    1.24 @@ -348,11 +355,16 @@
    1.25      sys.exit(exit)
    1.26  
    1.27  def main(path='.'):
    1.28 +    if os.path.realpath(path).split(os.sep)[-1] != 'examples':
    1.29 +        print >> sys.stderr, 'Not being run from the examples directory!'
    1.30 +        sys.exit(1)
    1.31 +
    1.32      opts, args = getopt.getopt(sys.argv[1:], '?ahv',
    1.33                                 ['all', 'help', 'keep', 'verbose'])
    1.34      verbose = False
    1.35      run_all = False
    1.36      keep_change = False
    1.37 +
    1.38      for o, a in opts:
    1.39          if o in ('-h', '-?', '--help'):
    1.40              print_help(0)
    1.41 @@ -397,6 +409,11 @@
    1.42          print >> open(os.path.join(path, '.run'), 'w'), time.asctime()
    1.43      else:
    1.44          print_help(1, msg='no test names given, and --all not provided')
    1.45 +
    1.46 +    fp = open('auto-snippets.xml', 'w')
    1.47 +    for key in sorted(example.entities.iterkeys()):
    1.48 +        print >> fp, key
    1.49 +    fp.close()
    1.50      return errs
    1.51  
    1.52  if __name__ == '__main__':