#
# 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
class FileSearcher:
def __init__(self):
self.currentDir = "."
self.exclude=[]
self.include=[]
self.fileFilter=None
def defaultFilter(self, path, stat):
return 1
def setFilter(self, f):
self.fileFilter = f
def setDir(self, d):
self.currentDir = d
def addExclude(self, excluded):
self.exclude.append(excluded)
def addInclude(self, included):
self.include.append(included)
def find(self, currentDir=None, currentList=[]):
if ( currentDir == None ):
currentDir=self.currentDir
if ( self.fileFilter == None ):
self.fileFilter = self.defaultFilter
contents=os.listdir(currentDir)
for f in contents:
path=os.path.join(currentDir, f)
fileInfo = os.stat( path )
if ( self.fileFilter(path, fileInfo) ):
currentList.append(path)
if ( os.path.isDir(path) ):
self.find( path, currentList)
|