Skip to content

Commit

Permalink
Improve insall and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 27, 2025
1 parent 8d14afc commit d774a6b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
16 changes: 9 additions & 7 deletions src/nanosaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand All @@ -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


Expand Down Expand Up @@ -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')
Expand Down
5 changes: 1 addition & 4 deletions src/nanosaur/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions src/nanosaur/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/nanosaur/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
14 changes: 11 additions & 3 deletions src/nanosaur/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit d774a6b

Please sign in to comment.