Package pygccxml :: Package declarations :: Module filtering'

Source Code for Module pygccxml.declarations.filtering'

 1  # Copyright 2004-2008 Roman Yakovenko. 
 2  # Distributed under the Boost Software License, Version 1.0. (See 
 3  # accompanying file LICENSE_1_0.txt or copy at 
 4  # http://www.boost.org/LICENSE_1_0.txt) 
 5   
 6  """ 
 7  deprecated! 
 8   
 9  This module defines few algorithms for filtering declarations. 
10  """ 
11   
12  import os 
13  import algorithm 
14 15 -class filtering:
16 """deprecated! 17 18 defines few algorithms for filtering declarations 19 """ 20 21 @staticmethod
22 - def normalize_path( some_path ):
23 """return os.path.normcase( os.path.normpath( some_path ) )""" 24 return os.path.normcase( os.path.normpath( some_path ) )
25 26 @staticmethod
27 - def contains_parent_dir( fpath, dirs ):
28 #precondition: dirs and fpath should be normalize_path'ed before calling this function 29 return bool( filter( lambda dir: fpath.startswith( dir ), dirs ) )
30 31 @staticmethod
32 - def by_location( decls, locations ):
33 """ 34 returns list of declarations that belongs to specified locations. 35 36 This function works recursively. Pay attention: if you remove namespace, 37 then you remove all declarations defined within the namespace. 38 39 @param decls: declaration or list of declarations 40 @type decls: L{declaration<declaration_t>} or list of L{declarations<declaration_t>} 41 42 @param locations: list of directories and/or files names 43 @type locations: list of strings 44 45 @return: list of L{declarations<declaration_t>} 46 """ 47 #precondition: decls is a list of op level namespaces 48 #locations is list of directories and\or files 49 temp_decls = algorithm.make_flatten( decls ) 50 locations = map( filtering.normalize_path, locations ) 51 dirs = filter( lambda location: os.path.isdir( location ), locations ) 52 files = filter( lambda location: os.path.isfile( location ), locations ) 53 result = [] 54 for decl in temp_decls: 55 if not decl.location: 56 result.append( decl ) 57 continue 58 fpath = filtering.normalize_path( decl.location.file_name ) 59 if filtering.contains_parent_dir( fpath, dirs ) or fpath in files: 60 result.append( decl ) 61 return result
62 63 @staticmethod
64 - def user_defined( decls, matcher ):
65 """ 66 returns list of declarations that match user specified criteria. 67 68 This function works recursively. 69 70 @param decls: declaration or list of declarations 71 @type decls: L{declaration<declaration_t>} or list of L{declarations<declaration_t>} 72 73 @param matcher: callable object, that takes 1 argument - declaration 74 and returns True if object should stay, and false otherwise 75 76 @return: list of L{declarations<declaration_t>} 77 """ 78 #precondition: decls is a list of op level namespaces 79 return filter( matcher, algorithm.make_flatten( decls ) )
80