security-admin/src/bin/ranger_install.py
def ModConfig(File, Variable, Setting):
    """
    Modify Config file variable with new setting
    """
    VarFound = False
    AlreadySet = False
    V=str(Variable)
    S=str(Setting)
    # use quotes if setting has spaces #
    if ' ' in S:
        S = '"%s"' % S

    for line in fileinput.input(File, inplace = 1):
        # process lines that look like config settings #
        if not line.lstrip(' ').startswith('#') and '=' in line:
            _infile_var = str(line.split('=')[0].rstrip(' '))
            _infile_set = str(line.split('=')[1].lstrip(' ').rstrip())
            # only change the first matching occurrence #
            if VarFound == False and _infile_var.rstrip(' ') == V:
                VarFound = True
                # don't change it if it is already set #
                if _infile_set.lstrip(' ') == S:
                    AlreadySet = True
                else:
                    line = "%s = %s\n" % (V, S)

        sys.stdout.write(line)


    # Append the variable if it wasn't found #
    if not VarFound:
        log( "Variable '%s' not found.  Adding it to %s" % (V, File), "debug")
        with open(File, "a") as f:
            f.write("%s = %s\n" % (V, S))
    elif AlreadySet == True:
        log( "Variable '%s' unchanged" % (V) , "debug")
    else:
        log( "Variable '%s' modified to '%s'" % (V, S) , "debug")

    return

    Modify Config file variable with new setting
    
Modify Config file variable with new setting
Modify Config file variable with new setting
def ModConfig(File, Variable, Setting):
    VarFound = False
    AlreadySet = False
    V=str(Variable)
    S=str(Setting)
    if ' ' in S:
        S = '"%s"' % S
    for line in fileinput.input(File, inplace = 1):
        if not line.lstrip(' ').startswith('#') and '=' in line:
            _infile_var = str(line.split('=')[0].rstrip(' '))
            _infile_set = str(line.split('=')[1].lstrip(' ').rstrip())
            if VarFound == False and _infile_var.rstrip(' ') == V:
                VarFound = True
                if _infile_set.lstrip(' ') == S:
                    AlreadySet = True
                else:
                    line = "%s = %s\n" % (V, S)
        sys.stdout.write(line)
    if not VarFound:
        log( "Variable '%s' not found.  Adding it to %s" % (V, File), "debug")
        with open(File, "a") as f:
            f.write("%s = %s\n" % (V, S))
    elif AlreadySet == True:
        log( "Variable '%s' unchanged" % (V) , "debug")
    else:
        log( "Variable '%s' modified to '%s'" % (V, S) , "debug")
    return
def ModConfig ( File , Variable , Setting ) : VarFound = False AlreadySet = False V = str ( Variable ) S = str ( Setting ) if ' ' in S : S = '"%s"' % S for line in fileinput . input ( File , inplace = 1 ) : if not line . lstrip ( ' ' ) . startswith ( '#' ) and '=' in line : _infile_var = str ( line . split ( '=' ) [ 0 ] . rstrip ( ' ' ) ) _infile_set = str ( line . split ( '=' ) [ 1 ] . lstrip ( ' ' ) . rstrip ( ) ) if VarFound == False and _infile_var . rstrip ( ' ' ) == V : VarFound = True if _infile_set . lstrip ( ' ' ) == S : AlreadySet = True else : line = "%s = %s\n" % ( V , S ) sys . stdout . write ( line ) if not VarFound : log ( "Variable '%s' not found.  Adding it to %s" % ( V , File ) , "debug" ) with open ( File , "a" ) as f : f . write ( "%s = %s\n" % ( V , S ) ) elif AlreadySet == True : log ( "Variable '%s' unchanged" % ( V ) , "debug" ) else : log ( "Variable '%s' modified to '%s'" % ( V , S ) , "debug" ) return
Modify Config file variable with new setting
Modify Config file variable with new setting
"""
    Modify Config file variable with new setting
    """ # use quotes if setting has spaces # # process lines that look like config settings # # only change the first matching occurrence # # don't change it if it is already set # # Append the variable if it wasn't found #
File
Variable
Setting