[pygccxml-commit] SF.net SVN: pygccxml: [415] pydsc_dev/pydsc/pydsc.py
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-08-17 03:37:06
|
Revision: 415 Author: roman_yakovenko Date: 2006-08-16 20:36:58 -0700 (Wed, 16 Aug 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=415&view=rev Log Message: ----------- improving filter interface Modified Paths: -------------- pydsc_dev/pydsc/pydsc.py Modified: pydsc_dev/pydsc/pydsc.py =================================================================== --- pydsc_dev/pydsc/pydsc.py 2006-08-16 18:24:58 UTC (rev 414) +++ pydsc_dev/pydsc/pydsc.py 2006-08-17 03:36:58 UTC (rev 415) @@ -83,27 +83,52 @@ """return os.path.normcase( os.path.normpath( some_path ) )""" return os.path.normcase( os.path.normpath( some_path ) ) -def contains_parent_dir( path, dirs ): - """ - returns true if one of the directories is root directory for the path, - false otherwise +class filter_by_path_t: + class FILTER_TYPE: + """defines few filter constants""" + INCLUDE = 'include' + EXCLUDE = 'exclude' - @param path: path - @type path: str + def __init__( self, what, ftype ): + self.what = what + if None is self.what: + self.what = [] + elif isinstance( self.what, str ): + self.what = [self.what] + self.what = map( normalize_path, self.what ) + self.ftype = ftype - @param dirs: list of directories and\\or files - @type dirs: [ str ] + @staticmethod + def contains_parent_dir( path, dirs ): + """ + returns true if one of the directories is root directory for the path, + false otherwise - @return: bool - """ - #precondition: dirs and fpath should be normalize_path'ed before calling this function - return bool( filter( lambda dir: path.startswith( dir ), dirs ) ) + @param path: path + @type path: str -class FILTER_TYPE: - """defines few filter constants""" - INCLUDE = 'include' - EXCLUDE = 'exclude' + @param dirs: list of directories and\\or files + @type dirs: [ str ] + @return: bool + """ + #precondition: dirs and fpath should be normalize_path'ed before calling this function + return bool( filter( lambda dir: path.startswith( dir ), dirs ) ) + + def check( self, source_file ): + source_file = normalize_path( source_file ) + if source_file in self.what or self.contains_parent_dir( source_file, self.what ): + return self.ftype == self.FILTER_TYPE.INCLUDE + else: + return self.ftype == self.FILTER_TYPE.EXCLUDE + +def exclude( what ): + return filter_by_path_t( what, filter_t.FILTER_TYPE.EXCLUDE ) + +def include( what ): + return filter_by_path_t( what, filter_t.FILTER_TYPE.INCLUDE ) + + class checker_t( object ): """ applies spell check process on every imported module @@ -119,7 +144,6 @@ , speller , writer=None , filter=None - , filter_type=None , ignore_identifiers=True ): """ initialization method @@ -157,11 +181,6 @@ if self.writer is None: self.writer = sys.stdout self.filter = filter - if self.filter is None: - self.filter = [] - self.filter_type = None - if self.filter_type is None: - self.filter_type = FILTER_TYPE.EXCLUDE self.identifiers = set() self.ignore_identifiers = ignore_identifiers @@ -173,18 +192,16 @@ if inspect.ismodule( obj ): if obj.__name__ in self.__already_imported: return False #do not check already imported modules - try: - source_file = inspect.getsourcefile(obj) - if source_file is None: - source_file = inspect.getfile( obj ) - source_file = normalize_path( source_file ) - if source_file in self.filter \ - or contains_parent_dir( source_file, self.filter ): - return self.filter_type == FILTER_TYPE.INCLUDE - else: - return self.filter_type == FILTER_TYPE.EXCLUDE - except TypeError: - return False #built in module + if self.filter: + try: + source_file = inspect.getsourcefile(obj) + if source_file is None: + source_file = inspect.getfile( obj ) + return self.filter.check( source_file ) + except TypeError: + return False #built in module + else: + return True obj_module = inspect.getmodule( obj ) if not obj_module is module: return False @@ -198,7 +215,6 @@ return False def import_( self, name, globals=None, locals=None, fromlist=None ): - self.filter = map( normalize_path, self.filter ) pymodule = self.__orig_import( name, globals, locals, fromlist ) if self.should_be_checked(pymodule): #write = self.writer.write This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |