def rm(pattern, directory=False):
 def safe_remove(path):
  try:
   os.remove(path)
  except OSError as err:
   if (err.errno != errno.ENOENT):
    raise
  else:
   print ('rm %s' % path)
 def safe_rmtree(path):
  def onerror(fun, path, excinfo):
   exc = excinfo[1]
   if (exc.errno != errno.ENOENT):
    raise
  existed = os.path.isdir(path)
  shutil.rmtree(path, onerror=onerror)
  if existed:
   print ('rmdir -f %s' % path)
 if ('*' not in pattern):
  if directory:
   safe_rmtree(pattern)
  else:
   safe_remove(pattern)
  return
 for (root, subdirs, subfiles) in os.walk('.'):
  root = os.path.normpath(root)
  if root.startswith('.git/'):
   continue
  found = fnmatch.filter((subdirs if directory else subfiles), pattern)
  for name in found:
   path = os.path.join(root, name)
   if directory:
    print ('rmdir -f %s' % path)
    safe_rmtree(path)
   else:
    print ('rm %s' % path)
    safe_remove(path)

def rm ( pattern , directory = False ) : def safe_remove ( path ) : try : os . remove ( path ) except OSError as err : if ( err . errno != errno . ENOENT ) : raise else : print ( 'rm %s' % path ) def safe_rmtree ( path ) : def onerror ( fun , path , excinfo ) : exc = excinfo [ 1 ] if ( exc . errno != errno . ENOENT ) : raise existed = os . path . isdir ( path ) shutil . rmtree ( path , onerror = onerror ) if existed : print ( 'rmdir -f %s' % path ) if ( '*' not in pattern ) : if directory : safe_rmtree ( pattern ) else : safe_remove ( pattern ) return for ( root , subdirs , subfiles ) in os . walk ( '.' ) : root = os . path . normpath ( root ) if root . startswith ( '.git/' ) : continue found = fnmatch . filter ( ( subdirs if directory else subfiles ) , pattern ) for name in found : path = os . path . join ( root , name ) if directory : print ( 'rmdir -f %s' % path ) safe_rmtree ( path ) else : print ( 'rm %s' % path ) safe_remove ( path )
remove stopped containers in the docker-compose file .