Compare commits
2 Commits
a6b490f049
...
c8385f4b55
| Author | SHA1 | Date |
|---|---|---|
|
|
c8385f4b55 | |
|
|
4cbde2749d |
|
|
@ -22,7 +22,8 @@ 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)
|
||||||
|
|
||||||
|
|
@ -33,12 +34,27 @@ 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:
|
except Exception as e:
|
||||||
|
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"
|
||||||
|
|
@ -46,11 +62,10 @@ 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:
|
except Exception as e:
|
||||||
# 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.
|
||||||
# If we ignore the error, we'll respond with a None which is the right thing.
|
print("Can't find build info.\n{}".format(e))
|
||||||
pass
|
|
||||||
return project_state_content
|
return project_state_content
|
||||||
|
|
||||||
class Routes:
|
class Routes:
|
||||||
|
|
@ -77,5 +92,6 @@ 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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue