--- orig-search.py 2010-03-13 00:50:44.000000000 -0800 +++ search.py 2010-03-13 01:34:55.000000000 -0800 @@ -21,6 +21,7 @@ #from gentoolkit.package import Package from gentoolkit.helpers import walk +from functools import partial # Misc. shortcuts to some portage stuff: port_settings = portage.settings @@ -141,75 +142,78 @@ size_limit, time_limit, exclude, - clean_me={} + clean_me=None ): """Checks files if they exceed size and/or time_limits, etc. """ - checks = [self._isreg_limit_] + + if clean_me is None: + clean_me = {} + checks = [] + if 'filenames' in exclude: + checks.append(partial(self._filenames_limit_, exclude)) + else: + self.output(" - skipping exclude filenames check") + checks.append(self._isreg_limit_) if size_limit: - checks.append(self._size_limit_) - self.size_limit = size_limit + checks.append(partial(self._size_limit_, size_limit)) else: self.output(" - skipping size limit check") if time_limit: - checks.append(self._time_limit_) - self.time_limit = time_limit + checks.append(partial(self._time_limit_, time_limit)) else: self.output(" - skipping time limit check") - if 'filenames' in exclude: - checks.append(self._filenames_limit_) - self.exclude = exclude - else: - self.output(" - skipping exclude filenames check") - max_index = len(checks) + for file in os.listdir(_distdir): filepath = os.path.join(_distdir, file) try: file_stat = os.stat(filepath) - except: - continue - _index = 0 - next = True - skip_file = False - while _index= self.size_limit): #print( "size match ", file, file_stat[stat.ST_SIZE]) return False, True return True, False - def _time_limit_(self, file_stat, file): + @staticmethod + def _time_limit_(time_limit, file_stat, file): """checks if the file exceeds the time_limit""" - if (file_stat[stat.ST_MTIME] >= self.time_limit): + if (file_stat[stat.ST_MTIME] >= time_limit): #print( "time match ", file, file_stat[stat.ST_MTIME]) return False, True return True,False - def _filenames_limit_(self, file_stat, file): + @staticmethod + def _filenames_limit_(excludes, file_stat, file): """checks if the file matches an exclusion file listing""" # Try to match file name directly - if file in self.exclude['filenames']: + if file in exclude['filenames']: return False, True # See if file matches via regular expression matching else: file_match = False - for file_entry in self.exclude['filenames']: - if self.exclude['filenames'][file_entry].match(file): + for file_entry in exclude['filenames']: + if exclude['filenames'][file_entry].match(file): file_match = True break if file_match: