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

Get autogeneration of examples more or less working.
author Bryan O'Sullivan <bos@serpentine.com>
date Mon, 09 Mar 2009 22:55:38 -0700
parents 8a9c66da6fcb
children 60ee738fdc0e
line wrap: on
line diff
--- a/en/examples/run-example	Mon Mar 09 21:40:12 2009 -0700
+++ b/en/examples/run-example	Mon Mar 09 22:55:38 2009 -0700
@@ -65,6 +65,8 @@
     
     timeout = 10
 
+    entities = dict.fromkeys(l.rstrip() for l in open('auto-snippets.xml'))
+
     def __init__(self, name, verbose, keep_change):
         self.name = name
         self.verbose = verbose
@@ -240,6 +242,11 @@
                                 err |= self.rename_output(ofp_basename, ignore)
                             if out:
                                 ofp_basename = '%s.%s' % (self.name, out)
+                                norm = os.path.normpath(ofp_basename)
+                                example.entities[
+                                    '<!ENTITY "interaction.%s" '
+                                    'SYSTEM "results/%s.out">'
+                                    % (norm, norm)] = 1
                                 read_hint = ofp_basename + ' '
                                 ofp = open(result_name(ofp_basename + '.tmp'),
                                            'w')
@@ -348,11 +355,16 @@
     sys.exit(exit)
 
 def main(path='.'):
+    if os.path.realpath(path).split(os.sep)[-1] != 'examples':
+        print >> sys.stderr, 'Not being run from the examples directory!'
+        sys.exit(1)
+
     opts, args = getopt.getopt(sys.argv[1:], '?ahv',
                                ['all', 'help', 'keep', 'verbose'])
     verbose = False
     run_all = False
     keep_change = False
+
     for o, a in opts:
         if o in ('-h', '-?', '--help'):
             print_help(0)
@@ -397,6 +409,11 @@
         print >> open(os.path.join(path, '.run'), 'w'), time.asctime()
     else:
         print_help(1, msg='no test names given, and --all not provided')
+
+    fp = open('auto-snippets.xml', 'w')
+    for key in sorted(example.entities.iterkeys()):
+        print >> fp, key
+    fp.close()
     return errs
 
 if __name__ == '__main__':