import sys, os, signal, time import shutil import subprocess import py import re def check_label(label): try: int(label) except ValueError: # d.xyz or dd.xyz if re.match(r"^\d?\d\.", label): return True else: return True return False def svn_up(checkargv=True, root='pypy-dist'): if checkargv and len(sys.argv) > 1 and sys.argv[1] == '--vrev': del sys.argv[1] VREV = sys.argv[1] if not check_label(VREV): raise ValueError, ("invalid --vrev: should be a number or a string" " starting with 1 or 2 digits and a dot.") del sys.argv[1] return VREV root = py.path.local(root) ROOT = py.path.svnwc(root) if checkargv and len(sys.argv) > 1 and sys.argv[1] == '--no-update': del sys.argv[1] else: # completely clean up the root directory # this comes from ../../svnutil/svnwcrevert.py from svnwcrevert import svnwcrevert svnwcrevert(root) ROOT.update() REV = str(ROOT.info().created_rev) return REV def thread_init(): if os.name == 'nt': try: import pythoncom pythoncom.CoInitialize() except ImportError: pass def symlink_nt(target, name, fallback='copy'): if fallback == 'copy': try: shutil.copyfile(target, name) except IOError, x: raise OSError('Could not copy to simulate link: %r' % (x,)) return else: assert fallback == 'shortcut' if not os.path.isabs(target): target = os.path.join(os.path.dirname(name), target) target = os.path.abspath(target) print 'target', target, 'name', name try: import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shortcut = shell.CreateShortCut(name + ".lnk") shortcut.TargetPath = target shortcut.save() except KeyboardInterrupt: raise except Exception, x: raise OSError('Could not create shortcut: %r' % (x,)) def symlink_posix(src, dst, fallback='copy'): os.symlink(src, dst) if os.name == 'nt': symlink = symlink_nt else: symlink = symlink_posix def unlink(fname): if os.path.exists(fname): os.remove(fname) elif os.path.exists(fname + ".lnk"): os.remove(fname + ".lnk") else: # To provoke the proper error os.remove(fname) def getsignalname(n): for name, value in signal.__dict__.items(): if value == n and name.startswith('SIG'): return name return 'signal %d' % (n,) def execute(testdir, errfilename, htmldir, rawhtmlindex, extra="", interp=None, # should be a list [interp, arg1, arg2, ...] test_driver=None, # should be a list [script, arg1, arg2, ...] root='pypy-dist/pypy'): if test_driver is None: test_driver = [os.path.abspath(os.path.join('py', 'bin', 'py.test'))] if interp is None: interp = [os.path.abspath(sys.executable)] args = interp + test_driver args.extend(["--htmldir=%s" % htmldir, "--session=HTMLSession", "--rawhtmlindex=%s" % rawhtmlindex, testdir]) args = map(str, args) # stringify for convenience print 'wd: %s' % root print ' '.join(args) print '-+-' if sys.platform == "win32": # XXX the following line create processes that hang on wyvern. # XXX absolutely no clue why. The os.system() works fine # (as long as you don't have spaces in directories). exitcode = subprocess.call(args, cwd=str(root)) else: exitcode = os.system("cd '%s' && %s" % (root, ' '.join(args))) print '-+-' print 'exit code %d.' % (exitcode,) failure = None if exitcode >= 0: report = 'Exit with code %d.' % (exitcode,) else: report = 'Killed by %s' % (getsignalname(-exitcode),) if exitcode != 0: # failure! faileddir = htmldir.ensure('failed', dir=1) failure = faileddir.join(errfilename) try: buffer = rawhtmlindex.read() except py.error.Error: buffer = "(Index file not generated! Check logs.)\n" result = (buffer, report, failure) rawhtmlindex.write('%s\n%s\n' % (buffer, report)) if failure: try: symlink(str(rawhtmlindex), str(failure)) except OSError: pass return result def open_index_html(htmldir): f = htmldir.join('index.html').open('w') f.write(""" py.test results """) return f def write_index_html(htmldir, results, REV, nextindices=None, starttime=None): f = open_index_html(htmldir) if nextindices is not None: print >> f, "

py.test results (in-progress)

" else: print >> f, "

py.test results (rev %s)

" % (REV,) if starttime is not None: print >> f, "

Started %s, %d minutes elapsed

" % ( time.ctime(starttime), int((time.time() - starttime) / 60.0)) for buffer, report, failure in results: print >> f, "
"
        print >> f, buffer
        print >> f, "
" if failure: report = '%s' % (failure.basename, report) print >> f, "

%s

" % (report,) print >> f, '
' if nextindices is not None: print >> f, '

Tests now running

' else: print >> f, '

Done.

' print >> f, "" f.close()