parameters: (args)
docstring: Emulate most of the behavior of rm(1).
    Only supports the -r (--recursive) and -f (--force) arguments.
docstring_summary: Emulate most of the behavior of rm(1).
    Only supports the -r (--recursive) and -f (--force) arguments.
docstring_tokens: Emulate most of the behavior of rm ( 1 ) . Only supports the - r ( -- recursive ) and - f ( -- force ) arguments .
function: def rm(args):
    """
    Emulate most of the behavior of rm(1).
    Only supports the -r (--recursive) and -f (--force) arguments.
    """
    try:
      opts, args = getopt(args, "rRf", ["force", "recursive"])
    except GetoptError, e:
      raise PythonException, ("rm: %s" % e, 1)
    force = False
    recursive = False
    for o, a in opts:
      if o in ('-f', '--force'):
        force = True
      elif o in ('-r', '-R', '--recursive'):
        recursive = True
    for f in args:
      if os.path.isdir(f):
        if not recursive:
          raise PythonException, ("rm: cannot remove '%s': Is a directory" % f, 1)
        else:
          shutil.rmtree(f, force)
      elif os.path.exists(f):
        try:
          os.unlink(f)
        except:
          if not force:
            raise PythonException, ("rm: failed to remove '%s': %s" % (f, sys.exc_info()[0]), 1)
      elif not force:
        raise PythonException, ("rm: cannot remove '%s': No such file or directory" % f, 1)
function_tokens: def rm ( args ) : try : opts , args = getopt ( args , "rRf" , [ "force" , "recursive" ] ) except GetoptError , e : raise PythonException , ( "rm: %s" % e , 1 ) force = False recursive = False for o , a in opts : if o in ( '-f' , '--force' ) : force = True elif o in ( '-r' , '-R' , '--recursive' ) : recursive = True for f in args : if os . path . isdir ( f ) : if not recursive : raise PythonException , ( "rm: cannot remove '%s': Is a directory" % f , 1 ) else : shutil . rmtree ( f , force ) elif os . path . exists ( f ) : try : os . unlink ( f ) except : if not force : raise PythonException , ( "rm: failed to remove '%s': %s" % ( f , sys . exc_info ( ) [ 0 ] ) , 1 ) elif not force : raise PythonException , ( "rm: cannot remove '%s': No such file or directory" % f , 1 )