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

Fred L. Drake, Jr. fred@zope.com
Wed, 26 Feb 2003 13:01:37 -0500


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

Modified Files:
	autotester.py 
Log Message:
Large disruption:
- import modules, not individual names
- don't require the sandbox to already exist
- whitespace normalization


=== Packages/TestScripts/autotester.py 1.20 => 1.21 ===
--- Packages/TestScripts/autotester.py:1.20	Wed Feb 26 11:41:21 2003
+++ Packages/TestScripts/autotester.py	Wed Feb 26 13:01:36 2003
@@ -3,34 +3,36 @@
 # 1. CVS accessible via the command line
 # 2. Python 2.1 or above available via the command line
 
-from os.path import join
-from sys import argv
-from os import system, makedirs, rmdir, chdir, environ, getcwd, popen3, environ
-from shutil import rmtree
-from mailer import send
-from xml2dict import xml2dict
-from StringIO import StringIO
-from threading import Thread
-from re import compile, I, M
+import os
+import re
+import shutil
+import StringIO
+import sys
+import threading
+import traceback
 
-class NonBlockingReader(Thread):
+import mailer
+import xml2dict
+
+
+class NonBlockingReader(threading.Thread):
 
     def __init__(self,file):
-        Thread.__init__(self)
+        threading.Thread.__init__(self)
         self.file = file
-        
+
     def run(self):
         self.result = self.file.read()
 
     def read(self):
         return self.result
 
-f = open(argv[1])
-config = xml2dict(f.read())
+f = open(sys.argv[1])
+config = xml2dict.xml2dict(f.read())
 f.close()
 
 # Set up any necessary environment variables
-environ['CVSROOT']=config['cvs'][0]['root'][0]()
+os.environ['CVSROOT']=config['cvs'][0]['root'][0]()
 
 # Sandbox path
 sandbox = config['sandbox'][0]()
@@ -47,14 +49,14 @@
 # executor
 def execute(location,python,command,options):
     global sandbox
-    chdir(join(sandbox,location))
-    (i,c,e) = popen3(python+' '+command+' '+options)
+    os.chdir(os.path.join(sandbox,location))
+    (i,c,e) = os.popen3(python+' '+command+' '+options)
     ct = NonBlockingReader(c)
     et = NonBlockingReader(e)
     ct.start()
     et.start()
     ct.join()
-    et.join()    
+    et.join()
     result = ct.read()+et.read()
     i.close()
     c.close()
@@ -71,23 +73,26 @@
     return '\n'.join(result)
 
 # get our original directory
-home = getcwd()
+home = os.getcwd()
 
-try: # catch-all for death and badness
+# regular expressions used to check the results:
+failed_re = re.compile('FAILED \((?:failures=(\d+))?(?:, )?(?:errors=(\d+))?')
+other_errors_re = re.compile('error|warning', re.I)
+success_re = re.compile('^OK$', re.M)
 
+try: # catch-all for death and badness
   for scenario in config['scenario']:
+    os.chdir(home)
 
     # blow away the sandbox
-    chdir(home)    
-    # the sandbox MUST now exist before this runs for the first time...
-    rmtree(sandbox)
-
-    # make an empty sand box
-    makedirs(sandbox)
-    
+    if os.path.isdir(sandbox):
+        print "Removing existing sandbox..."
+        shutil.rmtree(sandbox)
+    os.makedirs(sandbox)
+
     # modules tuple: (module, name, tag, location)
     modules=[]
-    
+
     for module in scenario['module']:
         modules.append((
             module['name'][0](),
@@ -104,14 +109,14 @@
                 module['tag'][0](),
                 module['location'][0]()
                 ))
-    
+
     # do the CVS checkouts
     for (module,name,tag,location) in modules:
         # change dir to the right place
-        chdir(join(sandbox,location))
+        os.chdir(os.path.join(sandbox,location))
         # do the checkout
-        system(config['cvs'][0]['command'][0]()
-               +" -z9 export -r "+tag+" -d "+name+" "+module)
+        os.system(config['cvs'][0]['command'][0]()
+                  +" -z9 export -r "+tag+" -d "+name+" "+module)
 
     # get the python command
     p = config['python'][0][scenario['python'][0]()][0]()
@@ -119,30 +124,30 @@
     # set up the environment
     old_environment={}
     for key,value in scenario.get('environment',[{}])[0].items():
-        old_environment[key]=environ.get(key)
-        environ[key]=value[0]()
+        old_environment[key]=os.environ.get(key)
+        os.environ[key]=value[0]()
 
     # get the python version string
     python_version = execute('',p,'',' -c "import sys; print sys.version"')
-    
+
     # execute the build command
     build_result = xml_execute(scenario['build'],p)
     print build_result
-        
+
     # run the tests
     test_result = xml_execute(scenario['test'],p)
-    
+
     # return the environment state
     for key,value in old_environment.items():
         if value is None:
-            del environ[key]
+            del os.environ[key]
         else:
-            environ[key]=value
-    
+            os.environ[key]=value
+
     # write the results to the appropriate StringIO
     address = scenario['email'][0]()
-    body = StringIO()
-        
+    body = StringIO.StringIO()
+
     linewidth=78
     body.write('='*linewidth+'\n')
     for message in scenario.get('message',()):
@@ -160,10 +165,7 @@
     emails.append((address,body,scenario().strip()))
 
   # send the mail
-  failed_re = compile('FAILED \((?:failures=(\d+))?(?:, )?(?:errors=(\d+))?')
-  other_errors_re = compile('error|warning',I)
-  success_re = compile('^OK$', M)
-  for address,body,name in emails:    
+  for address,body,name in emails:
     subject = email['subject'][0]()+ ' - ' + name + ' - '
     content = body.getvalue()
 
@@ -179,12 +181,12 @@
                 failures += int(f)
             if e:
                 errors += int(e)
-    
+
         if failures:
             subject += ' failures:' + `failures`
         if errors:
             subject += ' errors:' + `errors`
-            
+
         if errors or failures:
             pass
         elif other_errors_re.findall(content):
@@ -193,21 +195,19 @@
             subject += ' OK :-)'
         else:
             subject += ' Not OK :-('
-       
-    send(address,
-         subject,
-         content,
-         smtp_server=smtp_server,
-         from_address=from_address)
+
+    mailer.send(address,
+                subject,
+                content,
+                smtp_server=smtp_server,
+                from_address=from_address)
     body.close()
 
 except:
-
     # oh dear, badness happened, better whine.
-    from sys import exc_info
     from traceback import format_exception
-    send(from_address,
-         'Autotester.py failed',
-         '\n'.join(format_exception(*exc_info())),
-         smtp_server=smtp_server,
-         from_address=from_address)
+    mailer.send(from_address,
+                'Autotester.py failed',
+                '\n'.join(format_exception(*sys.exc_info())),
+                smtp_server=smtp_server,
+                from_address=from_address)