Ejemplo n.º 1
0
def serial_menu(config):
    ota_status = load_ota_sys_markers(config.user)

    def uart_enabling():  # UART enabling prompt is also being shown when entering nodes flash menu for the first time
        # TODO Make this repeatable without adding multiple copies at the end of config.txt.
        os.system("./scripts/sys_conf.sh uart")
        ota_status.uart_support_added = True
        write_ota_sys_markers(ota_status, config.user)
        print("""

        Serial port enabled successfully.
        You have to reboot Raspberry now,
        so changes would be implemented. Ok?



        r - Reboot now{yellow}

        e - Exit{endc}
            """.format(endc=Bcolors.ENDC, yellow=Bcolors.YELLOW_S))
        selection = input()
        if selection == 'r':
            os.system("sudo reboot")
        elif selection == 'e':
            return

    while True:
        clear_the_screen()
        logo_top(config.debug_mode)
        serial_adding_menu = """
            Serial port (UART) has to be enabled. 
            Without it Arduino-nodes cannot be programmed.
            Do you want to enable it now?


     {green}y - for yes {endc}

    {yellow}a - for abort{endc}
            """.format(yellow=Bcolors.YELLOW_S, green=Bcolors.GREEN_S, endc=Bcolors.ENDC)
        selection = input(serial_adding_menu)
        if selection == 'y':
            if ota_status.uart_support_added:
                print("\n\n\t\tLooks like you already enabled Serial port. \n\t\tDo you want to continue anyway?\n")
                selection = input(f"\t\t\t{Bcolors.YELLOW}Press 'y' for yes or 'a' for abort{Bcolors.ENDC}\n")
                if selection == 'y':
                    uart_enabling()
                    break
                elif selection == 'a':
                    break
            else:
                uart_enabling()
                break
        elif selection == 'a':
            break
Ejemplo n.º 2
0
def installation(conf_allowed, config):
    ota_config = load_ota_sys_markers(config.user)
    os.system("sudo systemctl stop rotorhazard >/dev/null 2>&1 &"
              ) if not config.debug_mode else None
    clear_the_screen()
    internet_flag = internet_check()
    if not internet_flag:
        print(
            f"\n\t{Bcolors.RED}Looks like you don't have internet connection. Installation canceled.{Bcolors.ENDC}"
        )
        sleep(2)
    else:
        print(f"\n\t\t\t{Bcolors.GREEN}Internet connection - OK{Bcolors.ENDC}")
        sleep(2)
        clear_the_screen()
        print(
            f"\n\n\t{Bcolors.BOLD}Installation process has been started - please wait...{Bcolors.ENDC}\n\n"
        )
        installation_completed = """
        
        
            ######################################################
            ##                                                  ##
            ##{bold}{green}Installation completed {thumbs}{endc}##
            ##                                                  ##
            ######################################################


        After rebooting please check by typing 'sudo raspi-config' 
        if I2C, SPI and SSH protocols are active.
                    """.format(thumbs="👍👍👍  ",
                               bold=Bcolors.BOLD_S,
                               endc=Bcolors.ENDC_S,
                               green=Bcolors.GREEN_S)

        os.system("./scripts/sys_conf.sh all") if conf_allowed else None
        ota_config.sys_config_done = True
        os.system("./scripts/sys_conf.sh uart"
                  ) if not ota_config.uart_support_added else None
        ota_config.uart_support_added = True
        # UART enabling added here so user won't have to reboot Pi again after doing it in Features Menu
        write_ota_sys_markers(ota_config, config.user)
        os.system(
            f"./scripts/install_rh.sh {config.user} {check_preferred_rh_version(config)[0]}"
        )
        input("press Enter to continue.")
        clear_the_screen()
        print(installation_completed)
        os.system("sudo chmod 777 -R ~/RotorHazard")
        end_installation(config.user)
Ejemplo n.º 3
0
def main_menu(config):
    while True:
        clear_the_screen()
        logo_top(config.debug_mode)
        rh_install_or_update_prompt = rh_update_check(config)
        conf_color = Bcolors.GREEN if config_check() is False else ''
        main_menu_content = """

                                {rmf}MAIN MENU{endc}

                            {blue}{bold}  
                        1 - RotorHazard Manager {rh_prompt} 
                            {blue}{bold}
                        2 - Nodes flash and update {endc}{bold}
                            
                        3 - Additional features{configured}

                        4 - Configuration wizard{endc}{bold}{yellow}

                        e - Exit to Raspberry OS{endc}

                """.format(bold=Bcolors.BOLD_S, underline=Bcolors.UNDERLINE, endc=Bcolors.ENDC, green=Bcolors.GREEN,
                           blue=Bcolors.BLUE, yellow=Bcolors.YELLOW_S, red=Bcolors.RED, configured=conf_color,
                           rmf=Bcolors.RED_MENU_HEADER, rh_prompt=rh_install_or_update_prompt)
        print(main_menu_content)
        selection = input()
        if selection == '1':
            try:
                rpi_update(config)
            except AttributeError:
                attribute_error_handling()
        elif selection == '2':
            try:
                ota_status = load_ota_sys_markers(config.user)
                if ota_status.uart_support_added:
                    old_flash_gpio(config) if config.old_hw_mod else flashing_menu(config)
                # enters "old" flashing menu only when "old_hw_mod" is confirmed
                else:
                    serial_menu(config)
            except AttributeError:
                attribute_error_handling()
        elif selection == '3':
            features_menu(config)
        elif selection == '4':
            config = show_about(config)
        elif selection == 'e':
            end()
Ejemplo n.º 4
0
def aliases_menu(config):
    ota_status = load_ota_sys_markers(config.user)

    def aliases_content():
        """load ota status, update aliases then write ota_status"""
        os.system("cat ./resources/aliases.txt | tee -a ~/.bashrc")
        ota_status.aliases_implemented = True
        write_ota_sys_markers(ota_status, config.user)
        print("\n\n\t\t    Aliases added successfully")
        sleep(2)
        return

    while True:
        clear_the_screen()
        aliases_description = f""" 
        Aliases in Linux act like shortcuts or references to another commands. 
        You can use them every time when you operates in the terminal window. 
        For example instead of typing 'python3 ~/RotorHazard/src/server/server.py' 
        you can just type 'ss' (server start) etc. Aliases can be modified and added 
        anytime you want. You just have to open '~./bashrc' file in text editor 
        - like 'nano'. After that you have reboot or type 'source ~/.bashrc'. 
        {Bcolors.BOLD}
        {read_aliases_file()}
        {Bcolors.ENDC}
            Do you want to use above aliases in your system?
            Reboot should be performed after adding those"""
        print(aliases_description)
        selection = input(f"\n\t\t\t{Bcolors.YELLOW}Press 'y' for yes or 'a' for abort{Bcolors.ENDC}\n")
        if selection == 'y':
            if ota_status.aliases_implemented:
                print("""

            Looks like you already have aliases added. 
            Do you want to continue anyway?

        """)
                selection = input(f"\t\t\t{Bcolors.YELLOW}Press 'y' for yes or 'a' for abort{Bcolors.ENDC}\n")
                if selection == 'y':
                    aliases_content()
                    break
                elif selection == 'a':
                    return
            else:
                aliases_content()
                break
        elif selection == 'a':
            return
Ejemplo n.º 5
0
def main_window(config):
    while True:
        rh_config_text, rh_config_flag = check_rotorhazard_config_status(
            config)
        clear_the_screen()
        server_installed_flag, server_version_name = get_rotorhazard_server_version(
            config)
        if server_installed_flag:
            colored_server_version_name = f"{Bcolors.GREEN}{server_version_name}{Bcolors.ENDC}"
            update_prompt = rh_update_check(config)
        else:
            colored_server_version_name = f'{Bcolors.YELLOW}{Bcolors.UNDERLINE}installation not found{Bcolors.ENDC}'
            update_prompt = ''
        ota_config = load_ota_sys_markers(config.user)
        sys_configured_flag = ota_config.sys_config_done
        configured_server_target = check_preferred_rh_version(config)[0]
        sleep(0.1)
        welcome_text = """
        \n\n{red} {bold}
        AUTOMATIC UPDATE AND INSTALLATION OF ROTORHAZARD RACING TIMER SOFTWARE
            {endc}{bold}
        You can automatically install and update RotorHazard timing software. 
        Additional dependencies and libraries also will be installed or updated.
        Current database, configs and custom bitmaps will stay on their place.
        Source of the software is set to {underline}{blue}{server_version}{endc}{bold} version from the official 
        RotorHazard repository.
         
        Please update this (OTA) software, before updating RotorHazard server.
        Also make sure that you are logged as user {underline}{blue}{user}{endc}{bold} and that you don't have 
        other terminal windows opened - especially in RotorHazard directory.
        
        You can change those in configuration wizard in Main Menu.
        
        Server version currently installed: {server} {bold}{update_prompt} {bold}
        
        RotorHazard configuration state: {config_soft}
            
            """.format(bold=Bcolors.BOLD,
                       underline=Bcolors.UNDERLINE,
                       endc=Bcolors.ENDC,
                       blue=Bcolors.BLUE,
                       yellow=Bcolors.YELLOW,
                       red=Bcolors.RED,
                       orange=Bcolors.ORANGE,
                       server_version=configured_server_target,
                       user=config.user,
                       config_soft=rh_config_text,
                       server=colored_server_version_name,
                       update_prompt=update_prompt)
        print(welcome_text)
        if not rh_config_flag and server_installed_flag:
            configure = f"{Bcolors.GREEN}c - Configure RotorHazard server{Bcolors.ENDC}"
        elif not rh_config_flag and not server_installed_flag:
            configure = "c - Reconfigure RotorHazard server"
        else:
            configure = "c - Configure RotorHazard server"
        if not server_installed_flag:
            install = f"{Bcolors.GREEN}i - Install RotorHazard from scratch{Bcolors.ENDC}"
        else:
            install = "i - Install RotorHazard from scratch"
        print("""
                    {install}
                    
                    {configure}
                    
                    u - Update existing installation 
                    
                    s - Start RotorHazard server now{yellow}
                        
                    e - Exit to Main Menu{endc}
                    
                """.format(yellow=Bcolors.YELLOW,
                           endc=Bcolors.ENDC,
                           configure=configure,
                           install=install))
        selection = input()
        if selection == 'c':
            if server_installed_flag:
                conf_rh()
            else:
                print("Please install RH server before configuring.")
                sleep(2)
        elif selection == 's':
            if server_installed_flag:
                server_start()
            else:
                print("Please install the RotorHazard server first")
                sleep(2)
        elif selection == 'i':
            # rh_found_flag = os.path.exists(f"/home/{config.user}/RotorHazard")
            if sys_configured_flag:
                clear_the_screen()
                already_installed_prompt = """{bold}
                
        Looks like you already have your system configured.{endc}{bold}
        
        If so, please perform installation without sys. config.
                
                            
     {green}i - Force installation without sys. config. {endc}{bold}
            
            c - Force installation and system config. {yellow}
            
            a - Abort both {endc}
            """.format(bold=Bcolors.BOLD,
                       endc=Bcolors.ENDC,
                       underline=Bcolors.UNDERLINE,
                       yellow=Bcolors.YELLOW,
                       green=Bcolors.GREEN_S)
                print(already_installed_prompt)
                selection = input()
                if selection == 'i':
                    conf_allowed = False
                    installation(conf_allowed, config)
                elif selection == 'c':
                    confirm_valid_options = [
                        'y', 'yes', 'n', 'no', 'abort', 'a'
                    ]
                    while True:
                        confirm = input(
                            "\n\t\tAre you sure? [yes/abort]\t").strip()
                        if confirm in confirm_valid_options:
                            break
                        else:
                            print(
                                "\ntoo big fingers :( wrong command. try again! :)"
                            )
                    if confirm == 'y' or confirm == 'yes':
                        conf_allowed = True
                        installation(conf_allowed, config)
                    elif confirm in ['n', 'no', 'abort', 'a']:
                        pass
                elif selection == 'a':
                    clear_the_screen()
                    triangle_image_show()
                    sleep(0.5)
                    break
            else:
                conf_allowed = True
                installation(conf_allowed, config)
        elif selection == 'u':
            update(config)
        elif selection == 'e':
            clear_the_screen()
            os.chdir(f"/home/{config.user}/RH-ota")
            triangle_image_show()
            sleep(0.3)
            break