'Append a line to a file unless the line already exists in the file.  This method creates the file if
it doesn\'t exist.  If make_executable is True, the permissions on the file are set to executable by
the owner.'

def file_append(self, text, file_path, make_executable=True):

    file_dir = os.path.dirname(file_path)
    if (not os.path.exists(file_dir)):
        try:
            os.makedirs(file_dir)
        except Exception as e:
            log.exception(str(e))
            return 1
    if os.path.exists(file_path):
        try:
            new_env_file_contents = []
            env_file_contents = open(file_path, 'r').readlines()
            for line in env_file_contents:
                line = line.rstrip()
                if line:
                    new_env_file_contents.append(line)
            env_file_contents = new_env_file_contents
        except Exception as e:
            log.exception(str(e))
            return 1
    else:
        env_file_handle = open(file_path, 'w')
        env_file_handle.close()
        env_file_contents = []
    if make_executable:
        try:
            os.chmod(file_path, (int('111', base=8) | os.stat(file_path)[stat.ST_MODE]))
        except Exception as e:
            log.exception(str(e))
            return 1
    if isinstance(text, string_types):
        text = [text]
    for line in text:
        line = line.rstrip()
        if (line and (line not in env_file_contents)):
            env_file_contents.append(line)
    try:
        open(file_path, 'w').write('\n'.join(env_file_contents))
    except Exception as e:
        log.exception(str(e))
        return 1
    return 0
