#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import os
#
# Visitor class which visits all files and dirs
# in a subtree
#
class FileVisitor:
def __init__(self, dirFunc, fileFunc):
self.dirFunc = dirFunc
self.fileFunc = fileFunc
def visit(self, path):
if ( not os.path.isdir(path) ):
stop = self.fileFunc(path)
if (stop):
return stop
else:
self.dirFunc(path)
try:
list = os.listdir(path)
for f in list:
stop = self.visit( os.path.join( path, f ) )
if (stop):
return stop
except:
self.getLogger().writeln("Cannot open directory: " + path )
#
# Class which visits all files and dirs
# in a subtree which have been changed
# since the given time.
#
class ChangedFileVisitor(FileVisitor):
def __init__(self, time, dirFunc, fileFunc):
self.time = time
self.changedDirFunc = dirFunc
self.changedFileFunc = fileFunc
FileVisitor.__init__(self, self.myDirFunc, self.myFileFunc)
def myDirFunc(self, path):
if ( os.path.getmtime(path) > self.time ):
return self.changedDirFunc(path)
return None
def myFileFunc(self, path):
if ( os.path.getmtime(path) > self.time ):
return self.changedFileFunc(path)
return None
#
# Class which visits all the files newer than the
# given file.
#
class NewerFileVisitor(ChangedFileVisitor):
def __init__(self, markerFile, dirFunc, fileFunc):
time = 0
if (os.path.exists(markerFile)):
time = os.path.getmtime(markerFile)
ChangedFileVisitor.__init__( self, time, dirFunc, fileFunc)
|