def cleanup_dirs(patterns, dry_run=False, workdir='.'):
 current_dir = Path(workdir)
 python_basedir = Path(Path(sys.executable).dirname()).joinpath('..').abspath()
 warn2_counter = 0
 for dir_pattern in patterns:
  for directory in path_glob(dir_pattern, current_dir):
   directory2 = directory.abspath()
   if sys.executable.startswith(directory2):
    print ("SKIP-SUICIDE: '%s' contains current python executable" % directory)
    continue
   elif directory2.startswith(python_basedir):
    if (warn2_counter <= 4):
     print ("SKIP-SUICIDE: '%s'" % directory)
    warn2_counter += 1
    continue
   if dry_run:
    print ('RMTREE: %s (dry-run)' % directory)
   else:
    print ('RMTREE: %s' % directory)
    directory.rmtree_p()

def cleanup_dirs ( patterns , dry_run = False , workdir = '.' ) : current_dir = Path ( workdir ) python_basedir = Path ( Path ( sys . executable ) . dirname ( ) ) . joinpath ( '..' ) . abspath ( ) warn2_counter = 0 for dir_pattern in patterns : for directory in path_glob ( dir_pattern , current_dir ) : directory2 = directory . abspath ( ) if sys . executable . startswith ( directory2 ) : print ( "SKIP-SUICIDE: '%s' contains current python executable" % directory ) continue elif directory2 . startswith ( python_basedir ) : if ( warn2_counter <= 4 ) : print ( "SKIP-SUICIDE: '%s'" % directory ) warn2_counter += 1 continue if dry_run : print ( 'RMTREE: %s (dry-run)' % directory ) else : print ( 'RMTREE: %s' % directory ) directory . rmtree_p ( )
remove directories recursively .