Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

station_server: provide history handlers #936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions openhtf/output/servers/station_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import openhtf
from openhtf.output.callbacks import mfg_inspector
from openhtf.output.proto import mfg_event_converter
from openhtf.output.proto import mfg_event_pb2
from openhtf.output.servers import pub_sub
from openhtf.output.servers import web_gui_server
from openhtf.util import conf
Expand Down Expand Up @@ -461,10 +463,25 @@ class HistoryItemHandler(BaseHistoryHandler):
"""GET endpoint for a test record from the history."""

def get(self, file_name):
# TODO(Kenadia): Implement the history item handler. The implementation
# depends on the format used to store test records on disk.
self.write('Not implemented.')
self.set_status(500)
# The "Out of the box" disk format is fixed, subclasses/alternative
# implementations need to be sure their implementation matches their
# recorder

fn = os.path.join(self.history_path, file_name)
if not os.path.isfile(fn):
self.write('Not found')
self.set_status(404)
return

with open(fn, mode='rb') as f:
me = mfg_event_pb2.MfgEvent()
me.ParseFromString(f.read())
tr = mfg_event_converter.test_record_from_mfg_event(me)
test_record_dict = data.convert_to_base_types(tr)
test_state_dict = _test_state_from_record(test_record_dict,
StationPubSub._last_execution_uid)
self.set_status(200)
self.write(test_state_dict)


class HistoryAttachmentsHandler(BaseHistoryHandler):
Expand All @@ -477,10 +494,25 @@ class HistoryAttachmentsHandler(BaseHistoryHandler):
"""

def get(self, file_name, attachment_name):
# TODO(Kenadia): Implement the history item handler. The implementation
# depends on the format used to store test records on disk.
self.write('Not implemented.')
self.set_status(500)
# The implementation depends on the format used to store
# test records on disk.
fn = os.path.join(self.history_path, file_name)
if not os.path.isfile(fn):
self.write('Not found')
self.set_status(404)
return

with open(fn, mode='rb') as f:
me = mfg_event_pb2.MfgEvent()
me.ParseFromString(f.read())
# TODO: could use sha1 here to check?
desired_real = [a for a in me.attachment if a.name == attachment_name]
if len(desired_real) > 0:
self.write(desired_real[0].value_binary)
self.set_status(200)
else:
self.write('Attachment not found in test')
self.set_status(404)


class StationMulticast(multicast.MulticastListener):
Expand Down