Fill in build_info.
This commit is contained in:
parent
3b55038784
commit
a6b490f049
|
|
@ -10,6 +10,8 @@
|
|||
#
|
||||
from aiohttp import web
|
||||
import time
|
||||
from ament_index_python import get_package_share_directory
|
||||
import yaml
|
||||
|
||||
def main():
|
||||
facts = Facts()
|
||||
|
|
@ -32,7 +34,24 @@ class Facts:
|
|||
return time.monotonic() - self._start_time
|
||||
|
||||
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:
|
||||
return None
|
||||
# Find and read the project_state.repos file in it.
|
||||
project_state_file = build_info_getter_directory + "/project_state.repos"
|
||||
project_state_content = None
|
||||
try:
|
||||
with open(project_state_file, 'r') as file_obj:
|
||||
project_state_content = yaml.safe_load(file_obj)
|
||||
except:
|
||||
# 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
|
||||
return project_state_content
|
||||
|
||||
class Routes:
|
||||
def __init__(self, facts):
|
||||
|
|
@ -51,8 +70,12 @@ class Routes:
|
|||
return web.json_response(resp)
|
||||
|
||||
async def build_info(self, request):
|
||||
resp = self.get_buildinfo()
|
||||
return web.Response(text=text)
|
||||
project_state = self._facts.get_buildinfo()
|
||||
if not project_state:
|
||||
resp = {"status": False, "message": "project_state not found."}
|
||||
return web.json_response(resp)
|
||||
project_state["status"] = True
|
||||
return web.json_response(project_state)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue