[Zope-CVS] CVS: Packages/TestScripts - autotester.py:1.2

Chris Withers chrisw@nipltd.com
Thu, 7 Mar 2002 13:15:00 -0500


Update of /cvs-repository/Packages/TestScripts
In directory cvs.zope.org:/tmp/cvs-serv13875

Modified Files:
	autotester.py 
Log Message:
New super-duper XML-configurable hyper extendable nightly test runner. *droooool* :-)

=== Packages/TestScripts/autotester.py 1.1 => 1.2 ===
 
 from os.path import join
-from os import system, mkdir, rmdir, chdir, environ, getcwd
-# tweak stuff here for your setup
-
-# Mail info
-email_address = 'chrisw@nipltd.com'
-email_subject = 'Win32 Zope Test Results'
-email_smtp    = 'smtp.nipltd.com'
-
-# Set up any necessary environment variables
-environ['CVSROOT']=':pserver:anonymous@cvs.zope.org:/cvs-repository'
-
-# CVS info
-cvs_command = r'cvs'
-
-# this maps python version string to command line to use
-python = {
-    '2.1':'python',
-    }
-
-# Where stuff happens, this must exist
-wd = r"E:\ZopeTests\\"
-
-# This is a list of scenarios to test
-# Each scenario is, in turn, a tupe of the form:
-# (python_version, modules)
-#
-# where:
-#
-# python_version if a key into the 'python' dictionary
-# modules is a list of tuples of the form:
-#
-# (module,name,tag,location)
-# 
-# where:
-#
-# module   is the CVS module to checkout
-# name     is the name to check the module out as
-# tag      is the tag to use when checking the module out
-# location is the location to check the module out relative
-#          to the working directory
-
-scenarios = [
-    # Zope Head + CMF
-    (
-    '2.1',
-    [
-    ('Zope', 'Zope', 'HEAD', ''),
-    ('CMF/CMFCore',     'CMFCore',     'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFCalendar', 'CMFCalendar', 'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFCollector','CMFCollector','HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFDecor',    'CMFDecor',    'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFDefault',  'CMFDefault',  'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFTopic',    'CMFTopic',    'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFTracker',  'CMFTracker',  'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFWiki',     'CMFWiki',     'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/DCWorkflow',  'DCWorkflow',  'HEAD', join('Zope','lib','python','Products')),
-    ]
-    ),
-    # Zope 2.5 branch + CMF
-    (
-    '2.1',
-    [
-    ('Zope', 'Zope', 'Zope-2_5-branch', ''),
-    ('CMF/CMFCore',     'CMFCore',     'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFCalendar', 'CMFCalendar', 'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFCollector','CMFCollector','HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFDecor',    'CMFDecor',    'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFDefault',  'CMFDefault',  'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFTopic',    'CMFTopic',    'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFTracker',  'CMFTracker',  'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/CMFWiki',     'CMFWiki',     'HEAD', join('Zope','lib','python','Products')),
-    ('CMF/DCWorkflow',  'DCWorkflow',  'HEAD', join('Zope','lib','python','Products')),
-    ]
-    ),
-    ]
-    
-# the module containing Zope
-zope_module = "Zope"
-
-# THE CODE
-#
-# nothing tweakable below here
+from sys import argv
+from os import system, makedirs, rmdir, chdir, environ, getcwd, popen3
 from shutil import rmtree
 from mailer import send
+from xml2dict import xml2dict
+from StringIO import StringIO
 
+f = open(argv[1])
+config = xml2dict(f.read())
+f.close()
 
+# Set up any necessary environment variables
+environ['CVSROOT']=config['cvs'][0]['root'][0]()
 
-chdir(wd)
-body = open('body.txt','w')
+# Sandbox path
+sandbox = config['sandbox'][0]()
 
-for python_version, scenario in scenarios:
+# The emails to send (email address->StringIO object)
+emails={}
 
-    chdir(wd)
-    
-    # blow away whatever was there, if there was anything there
-    try:
-        rmtree(zope_module)
-    except:
-        pass
+# executor
+def execute(location,python,command,options):
+    global sandbox
+    chdir(join(sandbox,location))
+    (i,c,e) = popen3(python+' '+command+' '+options)
+    result = c.read()+e.read()
+    i.close()
+    c.close()
+    e.close()
+    return result        
+
+def xml_execute(command,p):
+    command = command[0]
+    return execute(command['location'][0](),p,command['command'][0](),command['options'][0]())
+
+for scenario in config['scenario']:
+
+    # blow away the sandbox
+    #try:
+    #    rmtree(sandbox)
+    #except:
+    #    pass
 
+    # make an empty sand box
+    #makedirs(sandbox)
+    
+    # modules tuple: (module, name, tag, location)
+    modules=[]
+    
+    for module in scenario['module']:
+        modules.append((
+            module['name'][0](),
+            module['rename'][0](),
+            module['tag'][0](),
+            module['location'][0]()
+            ))
+
+    for modulegroup in scenario['modulegroup']:
+        for module in config['modulegroups'][0][modulegroup()][0]['module']:
+            modules.append((
+                module['name'][0](),
+                module['rename'][0](),
+                module['tag'][0](),
+                module['location'][0]()
+                ))
+    
     # do the CVS checkouts
-    for (module,name,tag,location) in scenario:
+    for (module,name,tag,location) in modules:
         # change dir to the right place
-        chdir(join(wd,location))
+        chdir(join(sandbox,location))
         # do the checkout
-        system(cvs_command+" export -r "+tag+" -d "+name+" "+module)
+        #system(config['cvs'][0]['command'][0]()+" export -r "+tag+" -d "+name+" "+module)
 
     # get the python command
-    p = python[python_version]
-    
-    # change to the Zope location
-    chdir(join(wd,zope_module))
-
-    # build Zope
-    system(p+' '+join('Utilities','ExtensionBuilder.py')+" -z")
+    p = config['python'][0][scenario['python'][0]()][0]()
 
     # get the python version string
-    system(p+' -c "import sys; print sys.version" > version.txt')
+    python_version = execute('',p,'',' -c "import sys; print sys.version"')
     
+    # execute the build command
+    #build_result = xml_execute(scenario['build'],p)
+        
     # run the tests
-    system(p+' '+join('Utilities','testrunner.py')+' -v 0 -a -o result.txt')
+    test_result = xml_execute(scenario['test'],p)
 
-    # append the results to body.txt
+    # write the results to the appropriate StringIO
+    address = scenario['email'][0]()
+    body = emails.get(address)
+    if body is None:
+        body = StringIO()
+        emails[address]=body
+        
     body.write('='*80+'\n')
     body.write('='*80+'\n')
-    body.write('Python Version:%s\n' % open('version.txt').read().strip())
+    body.write('Python Version:%s\n' % python_version.strip())
     body.write('\n')
     body.write('Modules included:\n')
-    for (module,name,tag,l) in scenario:
+    for (module,name,tag,l) in modules:
         body.write("%s (%s)\n" % (module,tag))
     body.write('\n')
-    body.write(open('result.txt').read())
+    body.write(test_result)
     body.write('\n')
     body.write('='*80+'\n')
     body.write('='*80+'\n')
 
-# close off the results file
-body.close()
-chdir(wd)
-
 # send the mail
-send(email_address,
-     email_subject,
-     open('body.txt').read(),
-     smtp_server=email_smtp)
+email = config['email'][0]
+for address,body in emails.items():
+    send(address,
+         email['subject'][0](),
+         body.getvalue(),
+         smtp_server=email['smtp'][0](),
+         from_address=email['from'][0]())
+    body.close()