(paths)
return collectors
Scan for collectors to load from path
Scan for collectors to load from path
Scan for collectors to load from path
def load_collectors_from_paths(paths):
    """
    Scan for collectors to load from path
    """
    # Initialize return value
    collectors = {}

    if paths is None:
        return

    if isinstance(paths, basestring):
        paths = paths.split(',')
        paths = map(str.strip, paths)

    load_include_path(paths)

    for path in paths:
        # Get a list of files in the directory, if the directory exists
        if not os.path.exists(path):
            raise OSError("Directory does not exist: %s" % path)

        if path.endswith('tests') or path.endswith('fixtures'):
            return collectors

        # Load all the files in path
        for f in os.listdir(path):

            # Are we a directory? If so process down the tree
            fpath = os.path.join(path, f)
            if os.path.isdir(fpath):
                subcollectors = load_collectors_from_paths([fpath])
                for key in subcollectors:
                    collectors[key] = subcollectors[key]

            # Ignore anything that isn't a .py file
            elif (os.path.isfile(fpath) and
                  len(f) > 3 and
                  f[-3:] == '.py' and
                  f[0:4] != 'test' and
                  f[0] != '.'):

                modname = f[:-3]

                fp, pathname, description = imp.find_module(modname, [path])

                try:
                    # Import the module
                    mod = imp.load_module(modname, fp, pathname, description)
                except (KeyboardInterrupt, SystemExit) as err:
                    logger.error(
                        "System or keyboard interrupt "
                        "while loading module %s"
                        % modname)
                    if isinstance(err, SystemExit):
                        sys.exit(err.code)
                    raise KeyboardInterrupt
                except Exception:
                    # Log error
                    logger.error("Failed to import module: %s. %s",
                                 modname,
                                 traceback.format_exc())
                else:
                    for name, cls in get_collectors_from_module(mod):
                        collectors[name] = cls
                finally:
                    if fp:
                        fp.close()

    # Return Collector classes
    return collectors
def load_collectors_from_paths ( paths ) : # Initialize return value collectors = { } if paths is None : return if isinstance ( paths , basestring ) : paths = paths . split ( ',' ) paths = map ( str . strip , paths ) load_include_path ( paths ) for path in paths : # Get a list of files in the directory, if the directory exists if not os . path . exists ( path ) : raise OSError ( "Directory does not exist: %s" % path ) if path . endswith ( 'tests' ) or path . endswith ( 'fixtures' ) : return collectors # Load all the files in path for f in os . listdir ( path ) : # Are we a directory? If so process down the tree fpath = os . path . join ( path , f ) if os . path . isdir ( fpath ) : subcollectors = load_collectors_from_paths ( [ fpath ] ) for key in subcollectors : collectors [ key ] = subcollectors [ key ] # Ignore anything that isn't a .py file elif ( os . path . isfile ( fpath ) and len ( f ) > 3 and f [ - 3 : ] == '.py' and f [ 0 : 4 ] != 'test' and f [ 0 ] != '.' ) : modname = f [ : - 3 ] fp , pathname , description = imp . find_module ( modname , [ path ] ) try : # Import the module mod = imp . load_module ( modname , fp , pathname , description ) except ( KeyboardInterrupt , SystemExit ) as err : logger . error ( "System or keyboard interrupt " "while loading module %s" % modname ) if isinstance ( err , SystemExit ) : sys . exit ( err . code ) raise KeyboardInterrupt except Exception : # Log error logger . error ( "Failed to import module: %s. %s" , modname , traceback . format_exc ( ) ) else : for name , cls in get_collectors_from_module ( mod ) : collectors [ name ] = cls finally : if fp : fp . close ( ) # Return Collector classes return collectors