-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options for streams, files and STDIN
Grafmon now supports streaming from sockets, pipes, STDIN, log files, etc.
- Loading branch information
Showing
9 changed files
with
239 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from PyQt6.QtCore import ( | ||
QObject, | ||
QThreadPool, | ||
QRunnable, | ||
pyqtSignal as Signal | ||
) | ||
|
||
from .context import Context | ||
from .dialogs import ErrorDialog, AlertDialog | ||
|
||
class FileMonitor: | ||
def __init__(self, context: Context): | ||
self.context = context | ||
context.monitor = self | ||
self.file = context.monitor_cmd | ||
self.threadpool = QThreadPool() | ||
self.reader = None | ||
|
||
def update(self): | ||
if self.reader == None: | ||
self.reader = Reader(self.file) | ||
self.reader.signal.data.connect(self.context.mainwindow.update_data) | ||
self.reader.signal.error.connect(self.error) | ||
self.reader.signal.done.connect(self.done) | ||
self.threadpool.start(self.reader) | ||
|
||
def error(self, exc, value): | ||
print(f"Monitor error: {exc}: {value}", file=sys.stderr) | ||
err = ErrorDialog() | ||
err.setText(f"Monitor error: {exc}") | ||
err.setInformativeText(value) | ||
err.show() | ||
self.context.app.exit(1) | ||
|
||
def done(self): | ||
if self.context.fatal_error: | ||
return | ||
self.context.timer.stop() | ||
d = AlertDialog() | ||
d.setText("File closed") | ||
d.setInformativeText("The file has signaled that all data has been consumed.") | ||
d.show() | ||
|
||
def stop(self): | ||
pass | ||
|
||
class ReaderSignals(QObject): | ||
data = Signal(object) | ||
error = Signal(object, object) | ||
done = Signal() | ||
|
||
class Reader(QRunnable): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__() | ||
self.file = args[0] | ||
self.signal = ReaderSignals() | ||
|
||
def run(self): | ||
file = self.file | ||
try: | ||
while line := file.readline(): | ||
data = line.strip().split(maxsplit=1) | ||
self.signal.data.emit(data) | ||
except: | ||
exc, value = sys.exc_info()[:2] | ||
self.signal.error.emit(exc, value) | ||
finally: | ||
self.signal.done.emit() |
Oops, something went wrong.