#!python

import os
import sys
import platform

our_version = "python" + str(sys.version_info.major) + "." + str(sys.version_info.minor)
our_abs_path = os.path.dirname(os.path.abspath(__file__))

#Linux or Windows?
oursystem = platform.system();

if (oursystem == "Linux"):
    program_prefix = "bin";
    program_suffix = "lib/" + our_version + "/site-packages/asciivmssdashboard/console.py"
    python_path = our_abs_path + "/python" + str(sys.version_info.major) + " "
else:
    program_prefix = "Scripts";
    program_suffix = "lib/" + "site-packages/asciivmssdashboard/console.py"
    python_path = our_abs_path.replace("Scripts", "\python.exe ")

#Ok, now we have our packages full path. Or should...
our_abs_final_path  = our_abs_path.replace(program_prefix, program_suffix)

#We got some difficulties with Python installation files on Ubuntu...
#Python Binary first...
if os.path.exists(python_path[:-1]):
    print("-> Python installation seems OK...")
else:
    print(python_path)
    print("--> Seems like the Python installation path: " + python_path + "is broken, trying an alternative path...")
    python_path = python_path.replace("local/", "")

#Now our package files...
if os.path.exists(our_abs_final_path):
    print("-> Our Python package installation seems OK...")
else:
    print("--> Seems like our package installation path: " + our_abs_final_path + " is broken, trying an alternative path...")
    our_abs_final_path = our_abs_final_path.replace("site-packages", "dist-packages")

dash_script  = python_path + our_abs_final_path

#Well, now we have a good guess where our script is installed...
print("Executing: " + dash_script)
print("Wait a second...")
os.system(dash_script)
