def load_collectors(paths=None, filter=None):
 collectors = {}
 log = logging.getLogger('diamond')
 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:
  if (not os.path.exists(path)):
   raise OSError(('Directory does not exist: %s' % path))
  if (path.endswith('tests') or path.endswith('fixtures')):
   return collectors
  for f in os.listdir(path):
   fpath = os.path.join(path, f)
   if os.path.isdir(fpath):
    subcollectors = load_collectors([fpath])
    for key in subcollectors:
     collectors[key] = subcollectors[key]
   elif (os.path.isfile(fpath) and (len(f) > 3) and (f[(-3):] == '.py') and (f[0:4] != 'test') and (f[0] != '.')):
    if (filter and (os.path.join(path, f) != filter)):
     continue
    modname = f[:(-3)]
    try:
     mod = __import__(modname, globals(), locals(), ['*'])
    except (KeyboardInterrupt, SystemExit) as err:
     log.error(('System or keyboard interrupt while loading module %s' % modname))
     if isinstance(err, SystemExit):
      sys.exit(err.code)
     raise KeyboardInterrupt
    except:
     log.error('Failed to import module: %s. %s', modname, traceback.format_exc())
     continue
    for attrname in dir(mod):
     attr = getattr(mod, attrname)
     if (inspect.isclass(attr) and issubclass(attr, Collector) and (attr != Collector)):
      if attrname.startswith('parent_'):
       continue
      fqcn = '.'.join([modname, attrname])
      try:
       cls = load_dynamic_class(fqcn, Collector)
       collectors[cls.__name__] = cls
      except Exception:
       log.error('Failed to load Collector: %s. %s', fqcn, traceback.format_exc())
       continue
 return collectors

def load_collectors ( paths = None , filter = None ) : collectors = { } log = logging . getLogger ( 'diamond' ) 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 : if ( not os . path . exists ( path ) ) : raise OSError ( ( 'Directory does not exist: %s' % path ) ) if ( path . endswith ( 'tests' ) or path . endswith ( 'fixtures' ) ) : return collectors for f in os . listdir ( path ) : fpath = os . path . join ( path , f ) if os . path . isdir ( fpath ) : subcollectors = load_collectors ( [ fpath ] ) for key in subcollectors : collectors [ key ] = subcollectors [ key ] elif ( os . path . isfile ( fpath ) and ( len ( f ) > 3 ) and ( f [ ( - 3 ) : ] == '.py' ) and ( f [ 0 : 4 ] != 'test' ) and ( f [ 0 ] != '.' ) ) : if ( filter and ( os . path . join ( path , f ) != filter ) ) : continue modname = f [ : ( - 3 ) ] try : mod = __import__ ( modname , globals ( ) , locals ( ) , [ '*' ] ) except ( KeyboardInterrupt , SystemExit ) as err : log . error ( ( 'System or keyboard interrupt while loading module %s' % modname ) ) if isinstance ( err , SystemExit ) : sys . exit ( err . code ) raise KeyboardInterrupt except : log . error ( 'Failed to import module: %s. %s' , modname , traceback . format_exc ( ) ) continue for attrname in dir ( mod ) : attr = getattr ( mod , attrname ) if ( inspect . isclass ( attr ) and issubclass ( attr , Collector ) and ( attr != Collector ) ) : if attrname . startswith ( 'parent_' ) : continue fqcn = '.' . join ( [ modname , attrname ] ) try : cls = load_dynamic_class ( fqcn , Collector ) collectors [ cls . __name__ ] = cls except Exception : log . error ( 'Failed to load Collector: %s. %s' , fqcn , traceback . format_exc ( ) ) continue return collectors
load all collectors .