Compare commits

..

No commits in common. "c8385f4b55173c10c33c165d375f3aadfb947644" and "a6b490f049da40cbb3dfc43de0263d7fb6760f06" have entirely different histories.

1 changed files with 7 additions and 23 deletions

View File

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