From d774a6b5aafdf7ec98b22462127235a956c8b3d3 Mon Sep 17 00:00:00 2001 From: Raffaello Bonghi Date: Mon, 27 Jan 2025 12:25:54 +0000 Subject: [PATCH] Improve insall and minor fixes --- src/nanosaur/main.py | 16 +++++++++------- src/nanosaur/robot.py | 5 +---- src/nanosaur/simulation.py | 7 ++----- src/nanosaur/utilities.py | 8 ++++---- src/nanosaur/workspace.py | 14 +++++++++++--- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/nanosaur/main.py b/src/nanosaur/main.py index ec23faf..ab6d479 100644 --- a/src/nanosaur/main.py +++ b/src/nanosaur/main.py @@ -130,11 +130,15 @@ def info(platform, params: Params, args): def install(platform, params: Params, args): + # Initialize the robot configuration if it doesn't exist + first_install = 'robots' not in params + if first_install and not wizard(platform, params, args): + return False # Questions to ask the user questions = [ inquirer.List( 'choice', - message="What would you like to install?", + message="Select the type of installation to perform", choices=[key for key, value in NANOSAUR_INSTALL_OPTIONS_RULES.items() if value['show']], ignore=lambda answers: args.name is not None, ), @@ -154,20 +158,18 @@ def install(platform, params: Params, args): if answers['confirm'] is False: print(TerminalFormatter.color_text("Installation cancelled", color='red')) return False + # Get the selected install type print(TerminalFormatter.color_text(f"Installing {install_type} workspace...", bold=True)) if not NANOSAUR_INSTALL_OPTIONS_RULES[install_type]['function'](platform, params, args): return False - # Initialize the robot configuration if it doesn't exist - if 'robots' not in params: - wizard(platform, params, args) # Set params in maintainer mode current_mode = params.get('mode') if ( - current_mode not in NANOSAUR_INSTALL_OPTIONS_RULES - or install_type not in NANOSAUR_INSTALL_OPTIONS_RULES[current_mode] + install_type not in NANOSAUR_INSTALL_OPTIONS_RULES[current_mode]['rule'] ): params['mode'] = install_type + print(TerminalFormatter.color_text(f"Installation of {install_type} workspace complete", color='green')) return True @@ -230,7 +232,7 @@ def main(): parser_info.set_defaults(func=info) # Subcommand: install (hidden if workspace already exists) - if 'mode' not in params: + if 'mode' not in params or params['mode'] not in ['maintainer']: parser_install = subparsers.add_parser('install', help=f"Install nanosaur on your {device_type}") else: parser_install = subparsers.add_parser('install') diff --git a/src/nanosaur/robot.py b/src/nanosaur/robot.py index 769fdff..be3f8ff 100644 --- a/src/nanosaur/robot.py +++ b/src/nanosaur/robot.py @@ -118,10 +118,7 @@ def wizard(platform, params: Params, args): robot = Robot() robot.simulation = device_type == 'desktop' RobotList.add_robot(params, robot, save=False) - # Run the robot configuration wizard - for func in functions_list: - if not func(platform, params, args): - return False + return all(func(platform, params, args) for func in functions_list) def robot_set_name(platform, params: Params, args): diff --git a/src/nanosaur/simulation.py b/src/nanosaur/simulation.py index 37750d6..2ecb5c0 100644 --- a/src/nanosaur/simulation.py +++ b/src/nanosaur/simulation.py @@ -126,7 +126,7 @@ def simulation_info(platform, params: Params, verbose): print(TerminalFormatter.color_text("Simulation:", bold=True)) if 'simulation_tool' in params: isaac_sim_version = "" - if 'isaac_sim_path' in params and params['simulation_tool'] == 'isaac-sim': + if 'isaac_sim_path' in params and params['simulation_tool'] == 'isaac-sim' and params['isaac_sim_path']: isaac_sim_version = params['isaac_sim_path'].split("isaac-sim-")[-1] # Extract version after "isaac-sim-" text_message = f"{TerminalFormatter.color_text(' selected:', bold=True)} {params['simulation_tool']} {isaac_sim_version}" print(text_message) @@ -283,9 +283,6 @@ def simulation_set(platform, params: Params, args): simulation_tools.pop('gazebo', None) # Find all installed Isaac Sim versions isaac_sim_list = find_all_isaac_sim() - # Remove Isaac Sim from the list if no versions are found - if not isaac_sim_list: - simulation_tools.pop('isaac-sim', None) # Get the version of Isaac Sim if it is already set version = None if 'isaac_sim_path' in params: @@ -304,7 +301,7 @@ def simulation_set(platform, params: Params, args): ), inquirer.List( 'isaac-sim', - message="Select Isaac Sim version", + message="Select Isaac Sim version for run on host", choices=list(isaac_sim_list.keys()), default=version, ignore=lambda answers: answers['simulation_tool'] != 'Isaac-sim' or not isaac_sim_list diff --git a/src/nanosaur/utilities.py b/src/nanosaur/utilities.py index dd83a6e..979dc06 100644 --- a/src/nanosaur/utilities.py +++ b/src/nanosaur/utilities.py @@ -376,7 +376,7 @@ def get_nanosaur_docker_user(params: Params) -> str: def get_nanosaur_raw_github_url(params: Params) -> str: nanosaur_github_url = params.get('nanosaur_github', NANOSAUR_MAIN_GITHUB_URL) - nanosaur_branch = params.get('nanosaur_branch', NANOSAUR_MAIN_BRANCH) + nanosaur_branch = params['nanosaur_branch'] # Replace 'github.com' with 'raw.githubusercontent.com' in the URL nanosaur_github_url = nanosaur_github_url.replace('www.github.com', 'raw.githubusercontent.com') nanosaur_github_url = nanosaur_github_url.replace('github.com', 'raw.githubusercontent.com') @@ -412,7 +412,7 @@ def download_file(url, folder_path, file_name, force=False) -> str: # Check if the file already exists if not force and os.path.exists(file_path): - print(TerminalFormatter.color_text(f"File '{file_name}' already exists in '{folder_path}'. Skip download", color='yellow')) + logger.debug(TerminalFormatter.color_text(f"File '{file_name}' already exists in '{folder_path}'. Skip download", color='yellow')) return file_path # Cancel download # Send a request to download the file @@ -423,10 +423,10 @@ def download_file(url, folder_path, file_name, force=False) -> str: file_path = os.path.join(folder_path, file_name) with open(file_path, 'wb') as file: file.write(response.content) - print(TerminalFormatter.color_text(f"File '{file_name}' downloaded successfully to '{folder_path}'.", color='green')) + logger.debug(TerminalFormatter.color_text(f"File '{file_name}' downloaded successfully to '{folder_path}'.", color='green')) return file_path else: - print(TerminalFormatter.color_text(f"Failed to download file. Status code: {response.status_code}", color='red')) + logger.debug(TerminalFormatter.color_text(f"Failed to download file. Status code: {response.status_code}", color='red')) return None diff --git a/src/nanosaur/workspace.py b/src/nanosaur/workspace.py index 1562e6f..b8d498f 100644 --- a/src/nanosaur/workspace.py +++ b/src/nanosaur/workspace.py @@ -93,7 +93,8 @@ def workspaces_info(params: utilities.Params, verbose: bool): def ros_info(params): # Print ROS 2 installation path ros2_path = ros.get_ros2_path(ROS_DISTRO) - ros2_string = TerminalFormatter.color_text(f"ROS 2 {ROS_DISTRO.capitalize()} path:", bold=True) + ros2_version_color = TerminalFormatter.color_text(ROS_DISTRO.capitalize(), color='blue', bold=True) + ros2_string = TerminalFormatter.color_text(f"ROS 2 {ros2_version_color}:", bold=True) print(f"{ros2_string} {TerminalFormatter.clickable_link(ros2_path)}") # Print Isaac ROS installation path isaac_ros_version = params.get('isaac_ros_branch', ISAAC_ROS_RELEASE) @@ -245,7 +246,7 @@ def update_workspace(params, workspace_type, workspace_name_key, force, skip_ros } if args.all: print(TerminalFormatter.color_text("Updating isaac_ros_common repository", bold=True)) - isaac_ros_branch = params.get('isaac_ros_branch', ISAAC_ROS_RELEASE) + isaac_ros_branch = params['isaac_ros_branch'] ros.manage_isaac_ros_common_repo(nanosaur_home_path, isaac_ros_branch, args.force) print(TerminalFormatter.color_text("Updating all workspaces", bold=True)) update_shared_workspace(args.force) @@ -258,7 +259,7 @@ def update_workspace(params, workspace_type, workspace_name_key, force, skip_ros return False # Update the workspace print(TerminalFormatter.color_text("Updating isaac_ros_common repository", bold=True)) - isaac_ros_branch = params.get('isaac_ros_branch', ISAAC_ROS_RELEASE) + isaac_ros_branch = params['isaac_ros_branch'] ros.manage_isaac_ros_common_repo(nanosaur_home_path, isaac_ros_branch, args.force) print(TerminalFormatter.color_text(f"Updating {workspace}", bold=True)) if action := workspace_actions.get(workspace): @@ -568,6 +569,8 @@ def clean_workspace(nanosaur_ws_name) -> bool: def create_simple(platform, params: utilities.Params, args) -> bool: # Create the Nanosaur home folder nanosaur_home_path = utilities.create_nanosaur_home() + # Store nanosaur distro and Isaac ROS distro + params['nanosaur_branch'] = params.get('nanosaur_branch', utilities.NANOSAUR_MAIN_BRANCH) # Determine the device type workspace_type = "robot" if platform['Machine'] == 'jetson' else "simulation" docker_compose = f"docker-compose.{workspace_type}.yml" @@ -584,6 +587,8 @@ def create_developer_workspace(platform, params: utilities.Params, args, passwor create_simple(platform, params, args) # Create the Nanosaur home folder nanosaur_home_path = utilities.create_nanosaur_home() + # Store nanosaur distro and Isaac ROS distro + params['isaac_ros_branch'] = params.get('isaac_ros_branch', ISAAC_ROS_RELEASE) # Create the shared source folder create_shared_workspace() # Create developer workspace @@ -604,6 +609,9 @@ def create_maintainer_workspace(platform, params: utilities.Params, args, passwo device_type = "robot" if platform['Machine'] == 'jetson' else "desktop" # Create the Nanosaur home folder nanosaur_home_path = utilities.create_nanosaur_home() + # Store nanosaur distro and Isaac ROS distro + params['nanosaur_branch'] = params.get('nanosaur_branch', utilities.NANOSAUR_MAIN_BRANCH) + params['isaac_ros_branch'] = params.get('isaac_ros_branch', ISAAC_ROS_RELEASE) # Create the shared source folder create_shared_workspace() if device_type == "robot" or args.all: