api: remove unused methods
Remove the functions `_prepare_output` and `_output_ready`, which both were used when stdout for the stages was handled by the api.
This commit is contained in:
parent
83fc64c565
commit
46d675b102
1 changed files with 1 additions and 32 deletions
|
|
@ -39,6 +39,7 @@ class BaseAPI(abc.ABC):
|
||||||
called; the default implementation will receive the message
|
called; the default implementation will receive the message
|
||||||
call `_message.`
|
call `_message.`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, socket_address: Optional[PathLike] = None):
|
def __init__(self, socket_address: Optional[PathLike] = None):
|
||||||
self.socket_address = socket_address
|
self.socket_address = socket_address
|
||||||
self.barrier = threading.Barrier(2)
|
self.barrier = threading.Barrier(2)
|
||||||
|
|
@ -141,43 +142,16 @@ class API(BaseAPI):
|
||||||
def __init__(self, args, monitor, *, socket_address=None):
|
def __init__(self, args, monitor, *, socket_address=None):
|
||||||
super().__init__(socket_address)
|
super().__init__(socket_address)
|
||||||
self.input = args
|
self.input = args
|
||||||
self._output_data = io.StringIO()
|
|
||||||
self._output_pipe = None
|
|
||||||
self.monitor = monitor
|
self.monitor = monitor
|
||||||
self.metadata = {}
|
self.metadata = {}
|
||||||
self.error = None
|
self.error = None
|
||||||
|
|
||||||
@property
|
|
||||||
def output(self):
|
|
||||||
# Only once the event-loop was stopped, you are guaranteed that the
|
|
||||||
# api-thread scheduled all outstanding events. Therefore, we disallow
|
|
||||||
# asking for the output-data from a running api context. If we happen
|
|
||||||
# to need live streaming access to the output in the future, we need
|
|
||||||
# to redesign the output-handling, anyway.
|
|
||||||
assert not self.running
|
|
||||||
|
|
||||||
return self._output_data.getvalue()
|
|
||||||
|
|
||||||
def _prepare_input(self):
|
def _prepare_input(self):
|
||||||
with tempfile.TemporaryFile() as fd:
|
with tempfile.TemporaryFile() as fd:
|
||||||
fd.write(json.dumps(self.input).encode('utf-8'))
|
fd.write(json.dumps(self.input).encode('utf-8'))
|
||||||
# re-open the file to get a read-only file descriptor
|
# re-open the file to get a read-only file descriptor
|
||||||
return open(f"/proc/self/fd/{fd.fileno()}", "r")
|
return open(f"/proc/self/fd/{fd.fileno()}", "r")
|
||||||
|
|
||||||
def _prepare_output(self):
|
|
||||||
r, w = os.pipe()
|
|
||||||
self._output_pipe = r
|
|
||||||
self._output_data.truncate(0)
|
|
||||||
self._output_data.seek(0)
|
|
||||||
self.event_loop.add_reader(r, self._output_ready)
|
|
||||||
return os.fdopen(w)
|
|
||||||
|
|
||||||
def _output_ready(self):
|
|
||||||
raw = os.read(self._output_pipe, 4096)
|
|
||||||
data = raw.decode("utf-8")
|
|
||||||
self._output_data.write(data)
|
|
||||||
self.monitor.log(data)
|
|
||||||
|
|
||||||
def _set_metadata(self, message, fds):
|
def _set_metadata(self, message, fds):
|
||||||
fd = message["metadata"]
|
fd = message["metadata"]
|
||||||
with os.fdopen(fds.steal(fd), encoding="utf-8") as f:
|
with os.fdopen(fds.steal(fd), encoding="utf-8") as f:
|
||||||
|
|
@ -204,11 +178,6 @@ class API(BaseAPI):
|
||||||
elif msg["method"] == 'get-arguments':
|
elif msg["method"] == 'get-arguments':
|
||||||
self._get_arguments(sock)
|
self._get_arguments(sock)
|
||||||
|
|
||||||
def _cleanup(self):
|
|
||||||
if self._output_pipe:
|
|
||||||
os.close(self._output_pipe)
|
|
||||||
self._output_pipe = None
|
|
||||||
|
|
||||||
|
|
||||||
def exception(e, path="/run/osbuild/api/osbuild"):
|
def exception(e, path="/run/osbuild/api/osbuild"):
|
||||||
"""Send exception to osbuild"""
|
"""Send exception to osbuild"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue