def _find_common_roots(paths):
 paths = [x.split(os.path.sep) for x in paths]
 root = {}
 for chunks in sorted(paths, key=len, reverse=True):
  node = root
  for chunk in chunks:
   node = node.setdefault(chunk, {})
  node.clear()
 rv = set()
 def _walk(node, path):
  for (prefix, child) in iteritems(node):
   _walk(child, (path + (prefix,)))
  if (not node):
   rv.add('/'.join(path))
 _walk(root, ())
 return rv

def _find_common_roots ( paths ) : paths = [ x . split ( os . path . sep ) for x in paths ] root = { } for chunks in sorted ( paths , key = len , reverse = True ) : node = root for chunk in chunks : node = node . setdefault ( chunk , { } ) node . clear ( ) rv = set ( ) def _walk ( node , path ) : for ( prefix , child ) in iteritems ( node ) : _walk ( child , ( path + ( prefix , ) ) ) if ( not node ) : rv . add ( '/' . join ( path ) ) _walk ( root , ( ) ) return rv
out of some paths it finds the common roots that need monitoring .