mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Move LogPipe directly into process.py, we don't need to split that stuff on different files
This commit is contained in:
parent
e85b9f71d5
commit
cafe68f30e
2 changed files with 33 additions and 38 deletions
|
@ -9,8 +9,6 @@ import queue
|
|||
# process.quote syntax to access this module !
|
||||
from shlex import quote
|
||||
|
||||
from .stream import LogPipe
|
||||
|
||||
quote # This line is here to avoid W0611 PEP8 error (see comments above)
|
||||
|
||||
# Prevent to import subprocess only for common classes
|
||||
|
@ -94,6 +92,39 @@ def call_async_output(args, callback, **kwargs):
|
|||
return p.poll()
|
||||
|
||||
|
||||
class LogPipe(threading.Thread):
|
||||
# Adapted from https://codereview.stackexchange.com/a/17959
|
||||
def __init__(self, log_callback, queue):
|
||||
"""Setup the object with a logger and a loglevel
|
||||
and start the thread
|
||||
"""
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = False
|
||||
self.log_callback = log_callback
|
||||
|
||||
self.fdRead, self.fdWrite = os.pipe()
|
||||
self.pipeReader = os.fdopen(self.fdRead)
|
||||
|
||||
self.queue = queue
|
||||
|
||||
self.start()
|
||||
|
||||
def fileno(self):
|
||||
"""Return the write file descriptor of the pipe"""
|
||||
return self.fdWrite
|
||||
|
||||
def run(self):
|
||||
"""Run the thread, logging everything."""
|
||||
for line in iter(self.pipeReader.readline, ""):
|
||||
self.queue.put((self.log_callback, line.strip("\n")))
|
||||
|
||||
self.pipeReader.close()
|
||||
|
||||
def close(self):
|
||||
"""Close the write end of the pipe."""
|
||||
os.close(self.fdWrite)
|
||||
|
||||
|
||||
# Call multiple commands -----------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
import os
|
||||
import threading
|
||||
|
||||
class LogPipe(threading.Thread):
|
||||
# Adapted from https://codereview.stackexchange.com/a/17959
|
||||
def __init__(self, log_callback, queue):
|
||||
"""Setup the object with a logger and a loglevel
|
||||
and start the thread
|
||||
"""
|
||||
threading.Thread.__init__(self)
|
||||
self.daemon = False
|
||||
self.log_callback = log_callback
|
||||
|
||||
self.fdRead, self.fdWrite = os.pipe()
|
||||
self.pipeReader = os.fdopen(self.fdRead)
|
||||
|
||||
self.queue = queue
|
||||
|
||||
self.start()
|
||||
|
||||
def fileno(self):
|
||||
"""Return the write file descriptor of the pipe"""
|
||||
return self.fdWrite
|
||||
|
||||
def run(self):
|
||||
"""Run the thread, logging everything."""
|
||||
for line in iter(self.pipeReader.readline, ""):
|
||||
self.queue.put((self.log_callback, line.strip("\n")))
|
||||
|
||||
self.pipeReader.close()
|
||||
|
||||
def close(self):
|
||||
"""Close the write end of the pipe."""
|
||||
os.close(self.fdWrite)
|
||||
|
||||
|
Loading…
Reference in a new issue