Package licensechecker :: Module filescanner :: Class FileScanner
[hide private]
[frames] | no frames]

Class FileScanner

source code

Class used to scan a whole directory tree and to determine which files should be checked for license conformity based on include/exclude patterns.

Instance Methods [hide private]
 
__init__(self, filechecker=None, includes=None, excludes=None)
Builds a new instance of FileScanner.
source code
 
scan(self, topdir, handler=None)
Performs a recursive scan from a directory and calls a handler function for all positive files.
source code
Boolean
matches(self, filename)
Returns True if a file matches a set of conditions, False otherwise.
source code
 
__getDefaultExcludes(self) source code
[string,]
getExcludes(self)
Returns the list of exclude patterns of this instance.
source code
 
setExcludes(self, excludes)
Sets the list of exclude patterns for this instance.
source code
 
__getDefaultIncludes(self) source code
[string,]
getIncludes(self)
Returns the list of include patterns of this instance.
source code
 
setIncludes(self, includes)
Sets the list of include patterns for this instance.
source code
Class Variables [hide private]
  __logger = logging.getLogger('lichk')
Method Details [hide private]

__init__(self, filechecker=None, includes=None, excludes=None)
(Constructor)

source code 

Builds a new instance of FileScanner.

Parameters:
  • filechecker - an instance of FileChecker that will be used to determine the file type from it's extensions. If None a default FileChecker will be used.
  • includes - a list of regular expressions. If None, a default list of includes will be built from the extensions managed by this instance's filechecker.
  • excludes - a list of regular expressions matching files that will not be examined for license conformity. If None, a default list of excludes, read from the excludes.txt file in the data subdirectory of this module will be loaded.

scan(self, topdir, handler=None)

source code 

Performs a recursive scan from a directory and calls a handler function for all positive files. To determine if a file is positive, the matches function must return True.

Parameters:
  • topdir - the name of the directory where the scanning should start.
  • handler - an instance of a handler object whose handle method will be called for each positive file.

To Do: Handler objects are still to be defined.

matches(self, filename)

source code 

Returns True if a file matches a set of conditions, False otherwise.

The conditions for the filename are :

  1. It doesn't match any exclude pattern.
  2. If the list of include patterns is not empty, it must match an include pattern.
  3. If the list of include patterns is empty, the filename is considered a match.
Parameters:
  • filename - the name of the file to test.
Returns: Boolean
True for matching files, False otherwise.

getExcludes(self)

source code 

Returns the list of exclude patterns of this instance.

Returns: [string,]
a list of string with the regexps for the exclude patterns.

setExcludes(self, excludes)

source code 

Sets the list of exclude patterns for this instance.

Parameters:
  • excludes - a list of regexp-strings denoting the exclude patterns.

getIncludes(self)

source code 

Returns the list of include patterns of this instance.

Returns: [string,]
a list of string with the regexps for the include patterns.

setIncludes(self, includes)

source code 

Sets the list of include patterns for this instance.

Parameters:
  • includes - a list of regexp-strings denoting the include patterns.