def find_folders_under(root, db, add_root=True, follow_links=False, cancel_callback=(lambda : False)):
 lp = db.library_path
 if lp:
  lp = os.path.abspath(lp)
 root = os.path.abspath(root)
 ans = set([])
 for (dirpath, dirnames, __) in os.walk(root, topdown=True, followlinks=follow_links):
  if cancel_callback():
   break
  for x in list(dirnames):
   path = os.path.join(dirpath, x)
   if (lp and path.startswith(lp)):
    dirnames.remove(x)
  if (lp and dirpath.startswith(lp)):
   continue
  ans.add(dirpath)
 if (not add_root):
  ans.remove(root)
 return ans

def find_folders_under ( root , db , add_root = True , follow_links = False , cancel_callback = ( lambda : False ) ) : lp = db . library_path if lp : lp = os . path . abspath ( lp ) root = os . path . abspath ( root ) ans = set ( [ ] ) for ( dirpath , dirnames , __ ) in os . walk ( root , topdown = True , followlinks = follow_links ) : if cancel_callback ( ) : break for x in list ( dirnames ) : path = os . path . join ( dirpath , x ) if ( lp and path . startswith ( lp ) ) : dirnames . remove ( x ) if ( lp and dirpath . startswith ( lp ) ) : continue ans . add ( dirpath ) if ( not add_root ) : ans . remove ( root ) return ans
find all folders under the specified root path .