Beispiel #1
0
def get_jarvis_configuration_file(create_if_not_exists=False):

    # Get host system
    #
    host_system = jarvis_misc.check_platform()

    jarvis_configuration_file_full_path = None
    if (host_system == "Linux") or (host_system == "Darwin"):
        jarvis_configuration_file_full_path = os.environ["JARVIS_HOME"] + \
            "/" + _jarvis_configuration_file_
    elif host_system == "Windows":
        jarvis_configuration_file_full_path = os.environ["JARVIS_HOME"] + \
            "\\" + _jarvis_configuration_file_
    else:
        print("Host OS unknown, cannot process Jarvis configuration file.")
        return False

    # Check that file exists
    #
    if (os.path.isfile(jarvis_configuration_file_full_path) is False) and (create_if_not_exists is True):

        # Create file
        #
        with open(jarvis_configuration_file_full_path, "w") as f:
            print("Creating %s" % jarvis_configuration_file_full_path)
            f.write("{}\n")

    # Read/write file content
    #
    read_configuration = None
    try:
        with open(jarvis_configuration_file_full_path, "r") as f:
            read_configuration = json.load(f)
    except Exception as ex:
        print("Error during configuration reading/parsing.")
        print(ex)

    # Check for non-present values
    #
    if "perform_ssl_verification" not in read_configuration:
        read_configuration["perform_ssl_verification"] = False

    if "client_ssl_certificate" not in read_configuration:
        read_configuration["client_ssl_certificate"] = ""

    # Make sur those variables are set
    #
    # SSL_CERT_FILE
    #
    if read_configuration["client_ssl_certificate"] is not None:
        os.environ["SSL_CERT_FILE"] = read_configuration["client_ssl_certificate"]
    else:
        del os.environ["SSL_CERT_FILE"]

    print("SSL Cert. : {}".format(os.environ["SSL_CERT_FILE"]))

    return read_configuration
Beispiel #2
0
def get_jarvis_home():

    # Get host system
    #
    host_system = jarvis_misc.check_platform()

    if (host_system == "Linux") or (host_system == "Darwin"):
        return os.environ["JARVIS_HOME"] + "/"
    elif host_system == "Windows":
        return os.environ["JARVIS_HOME"] + "\\"
    else:
        return None
Beispiel #3
0
def set_jarvis_configuration_file(data):

    # Get host system
    #
    host_system = jarvis_misc.check_platform()

    jarvis_configuration_file_full_path = None
    if (host_system == "Linux") or (host_system == "Darwin"):
        jarvis_configuration_file_full_path = os.environ["JARVIS_HOME"] + \
            "/" + _jarvis_configuration_file_
    elif host_system == "Windows":
        jarvis_configuration_file_full_path = os.environ["JARVIS_HOME"] + \
            "\\" + _jarvis_configuration_file_
    else:
        print("Host OS unknown, cannot process Jarvis configuration file.")
        return False

    with open(jarvis_configuration_file_full_path, "w") as f:
        json.dump(data, f)
Beispiel #4
0
def process_sql_query(read_configuration, input_conf_file):

    # Get path
    #
    filepath = os.path.dirname(input_conf_file)
    print("File path : {}".format(filepath))

    # Read associated SQL file
    #
    host_system = jarvis_misc.check_platform()

    path_element = None
    if (host_system == "Linux") or (host_system == "Darwin"):
        path_element = "/"
    elif host_system == "Windows":
        path_element = "\\"
    else:
        print("Host OS unknown, cannot process SQL file reading.")
        return None

    if (filepath is None) or (filepath == ""):
        sql_full_filename = read_configuration["sql_file"]
    else:
        sql_full_filename = filepath + path_element + \
            read_configuration["sql_file"]

    print("SQL file path : {}".format(sql_full_filename))

    try:

        # Read the content of the file, UTF-8 converted
        #
        read_sql_file = jarvis_misc.read_file_as_utf_8(sql_full_filename)

        # Convert SQL query into Base64
        #
        return str(base64.b64encode(read_sql_file), "utf-8")
    
    except Exception as ex:
        print("Error while reading SQL file : " + ex)
        
    return None
Beispiel #5
0
def jarvis_config():

    print("Installing Jarvis SDK ...")

    # Step 1 : check platform
    #
    host_system = jarvis_misc.check_platform(print_infos=True)

    # Step 2 : check SUDO / ADMINISTRATOR execution
    # Darwin, Linux, Windows, ...
    #
    if check_administrator(host_system) is True:
        return False

    # Step 3 : manage "jarvis sdk" directory
    #
    jarvis_home_directory = process_jarvis_home_directory(host_system)

    # Set temporarily the env. variable
    #
    os.environ["JARVIS_HOME"] = jarvis_home_directory

    if jarvis_home_directory is None:
        print("ERROR while processing Jarvis home directory. Please check console output. Exiting.")
        return False

    # Step 4 : manage JARVIS_HOME environment variable
    #
    if process_jarvis_home_env_variable(host_system) is not True:
        print("ERROR while processing Jarvis home environment variable. Please check console output. Exiting.")
        return False

    # Step 5 : create/update configuration file
    #
    if process_configuration_file(host_system) is False:
        print("Error while creating/upgrading configuration file.")

    # Final step
    #
    print("\nJarvis SDK installation is now complete. Please exit and re-launch your terminal.\n")

    return True