|
| 1 | +# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | + |
| 6 | +import logging |
| 7 | + |
| 8 | +import carb |
| 9 | + |
| 10 | +from isaaclab.utils import client |
| 11 | + |
| 12 | +logger = logging.getLogger(__name__) |
| 13 | + |
| 14 | +DEFAULT_ASSET_ROOT_PATH_SETTING = "/persistent/isaac/asset_root/default" |
| 15 | +DEFAULT_ASSET_ROOT_TIMEOUT_SETTING = "/persistent/isaac/asset_root/timeout" |
| 16 | + |
| 17 | + |
| 18 | +def check_server(server: str, path: str, timeout: float = 10.0) -> bool: |
| 19 | + """Check a specific server for a path |
| 20 | +
|
| 21 | + Args: |
| 22 | + server (str): Name of Nucleus server |
| 23 | + path (str): Path to search |
| 24 | + timeout (float): Default value: 10 seconds |
| 25 | +
|
| 26 | + Returns: |
| 27 | + bool: True if folder is found |
| 28 | + """ |
| 29 | + logger.info(f"Checking path: {server}{path}") |
| 30 | + result, _ = client.stat(f"{server}{path}") |
| 31 | + if result == client.Result.OK: |
| 32 | + logger.info(f"Success: {server}{path}") |
| 33 | + return True |
| 34 | + else: |
| 35 | + logger.info(f"Failure: {server}{path} not accessible") |
| 36 | + return False |
| 37 | + |
| 38 | + |
| 39 | +def get_assets_root_path(*, skip_check: bool = False) -> str: |
| 40 | + """Tries to find the root path to the Isaac Sim assets on a Nucleus server |
| 41 | +
|
| 42 | + Args: |
| 43 | + skip_check (bool): If True, skip the checking step to verify that the resolved path exists. |
| 44 | +
|
| 45 | + Raises: |
| 46 | + RuntimeError: if the root path setting is not set. |
| 47 | + RuntimeError: if the root path is not found. |
| 48 | +
|
| 49 | + Returns: |
| 50 | + url (str): URL of Nucleus server with root path to assets folder. |
| 51 | + """ |
| 52 | + |
| 53 | + # get timeout |
| 54 | + timeout = carb.settings.get_settings().get(DEFAULT_ASSET_ROOT_TIMEOUT_SETTING) |
| 55 | + if not isinstance(timeout, (int, float)): |
| 56 | + timeout = 10.0 |
| 57 | + |
| 58 | + # resolve path |
| 59 | + logger.info(f"Check {DEFAULT_ASSET_ROOT_PATH_SETTING} setting") |
| 60 | + default_asset_root = carb.settings.get_settings().get(DEFAULT_ASSET_ROOT_PATH_SETTING) |
| 61 | + if not default_asset_root: |
| 62 | + raise RuntimeError(f"The '{DEFAULT_ASSET_ROOT_PATH_SETTING}' setting is not set") |
| 63 | + if skip_check: |
| 64 | + return default_asset_root |
| 65 | + |
| 66 | + # check path |
| 67 | + result = check_server(default_asset_root, "/Isaac", timeout) |
| 68 | + if result: |
| 69 | + result = check_server(default_asset_root, "/NVIDIA", timeout) |
| 70 | + if result: |
| 71 | + logger.info(f"Assets root found at {default_asset_root}") |
| 72 | + return default_asset_root |
| 73 | + |
| 74 | + raise RuntimeError(f"Could not find assets root folder: {default_asset_root}") |
0 commit comments