move some code around, ending up with fewer files logically grouped

This commit is contained in:
holger krekel
2010-09-28 16:08:31 +02:00
parent f7923c692e
commit 3767ce3269
11 changed files with 236 additions and 242 deletions

View File

@@ -11,13 +11,12 @@ import py
import sys
import execnet
from py._test.session import gettopdir
from xdist import util
def looponfail_main(config):
remotecontrol = RemoteControl(config)
# XXX better configure rootdir
rootdirs = [gettopdir(config.args)]
statrecorder = util.StatRecorder(rootdirs)
statrecorder = StatRecorder(rootdirs)
try:
while 1:
remotecontrol.loop_once()
@@ -191,3 +190,54 @@ class SlaveFailSession:
topdir = str(self.topdir)
self.channel.send((topdir, trails, failreports, self.collection_failed))
class StatRecorder:
def __init__(self, rootdirlist):
self.rootdirlist = rootdirlist
self.statcache = {}
self.check() # snapshot state
def fil(self, p):
return p.ext in ('.py', '.txt', '.c', '.h')
def rec(self, p):
return p.check(dotfile=0)
def waitonchange(self, checkinterval=1.0):
while 1:
changed = self.check()
if changed:
return
py.std.time.sleep(checkinterval)
def check(self, removepycfiles=True):
changed = False
statcache = self.statcache
newstat = {}
for rootdir in self.rootdirlist:
for path in rootdir.visit(self.fil, self.rec):
oldstat = statcache.get(path, None)
if oldstat is not None:
del statcache[path]
try:
newstat[path] = curstat = path.stat()
except py.error.ENOENT:
if oldstat:
del statcache[path]
changed = True
else:
if oldstat:
if oldstat.mtime != curstat.mtime or \
oldstat.size != curstat.size:
changed = True
py.builtin.print_("# MODIFIED", path)
if removepycfiles and path.ext == ".py":
pycfile = path + "c"
if pycfile.check():
pycfile.remove()
else:
changed = True
if statcache:
changed = True
self.statcache = newstat
return changed