Compare commits

..

2 Commits

Author SHA1 Message Date
James Pace c8385f4b55 Add env. 2025-11-23 06:55:13 -05:00
James Pace 4cbde2749d Cleanup error handling. 2025-11-22 12:35:08 -05:00
1 changed files with 23 additions and 7 deletions

View File

@ -22,7 +22,8 @@ def main():
web.get('/', routes.root),
web.get('/ping', routes.ping),
web.get('/uptime', routes.uptime),
web.get('/build_info', routes.build_info)
web.get('/build_info', routes.build_info),
web.get('/env', routes.env)
])
web.run_app(app)
@ -33,12 +34,27 @@ class Facts:
def get_uptime(self):
return time.monotonic() - self._start_time
def get_env(self):
env = {}
# We're not going to return the whole environment because
# of security.
# Let's pick the ones we want.
env['ROS_AUTOMATIC_DISCOVERY_RANGE'] = os.environ.get('ROS_AUTOMATIC_DISCOVERY_RANGE', None)
env['AMENT_PREFIX_PATH'] = os.environ.get('AMENT_PREFIX_PATH', None)
env['ROS_DISTRO'] = os.environ.get('ROS_DISTRO', None)
env['RMW_IMPLEMENTATION'] = os.environ.get('RMW_IMPLEMENTATION', None)
env['ROS_NAMESPACE'] = os.environ.get('ROS_NAMESPACE', None)
env['CYCLONEDDS_URI'] = os.environ.get('CYCLONEDDS_URI', None)
return env
def get_buildinfo(self):
# Find the share directory for 'build_info_getter'.
build_info_getter_directory = None
try:
build_info_getter_directory = get_package_share_directory('build_info_getter')
except:
except Exception as e:
print("Can't find build info.\n{}".format(e))
return None
# Find and read the project_state.repos file in it.
project_state_file = build_info_getter_directory + "/project_state.repos"
@ -46,11 +62,10 @@ class Facts:
try:
with open(project_state_file, 'r') as file_obj:
project_state_content = yaml.safe_load(file_obj)
except:
except Exception as e:
# We either didn't load the file or couldn't read it
# as json.
# If we ignore the error, we'll respond with a None which is the right thing.
pass
print("Can't find build info.\n{}".format(e))
return project_state_content
class Routes:
@ -77,5 +92,6 @@ class Routes:
project_state["status"] = True
return web.json_response(project_state)
async def env(self, request):
env = self._facts.get_env()
return web.json_response(env)