From 0d930bf8718c316ec0f40440d102ffd4fa66b91e Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 4 Aug 2020 15:47:25 -0400 Subject: [PATCH] gcode: Pass the pseudo-tty fd via the start_args system Signed-off-by: Kevin O'Connor --- klippy/gcode.py | 4 ++-- klippy/klippy.py | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index 1ef2f37f..2b9c8cc2 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -70,9 +70,9 @@ class GCodeCommand: class GCodeParser: error = homing.CommandError RETRY_TIME = 0.100 - def __init__(self, printer, fd): + def __init__(self, printer): self.printer = printer - self.fd = fd + self.fd = printer.get_start_args().get("gcode_fd") printer.register_event_handler("klippy:ready", self._handle_ready) printer.register_event_handler("klippy:shutdown", self._handle_shutdown) printer.register_event_handler("klippy:disconnect", diff --git a/klippy/klippy.py b/klippy/klippy.py index cd22ace9..5fc013fa 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -48,7 +48,7 @@ Printer is shutdown class Printer: config_error = configfile.error command_error = homing.CommandError - def __init__(self, input_fd, bglogger, start_args): + def __init__(self, bglogger, start_args): self.bglogger = bglogger self.start_args = start_args self.reactor = reactor.Reactor() @@ -59,7 +59,7 @@ class Printer: self.event_handlers = {} self.objects = collections.OrderedDict() self.objects['webhooks'] = webhooks.WebHooks(self) - self.objects['gcode'] = gcode.GCodeParser(self, input_fd) + self.objects['gcode'] = gcode.GCodeParser(self) def get_start_args(self): return self.start_args def get_reactor(self): @@ -260,20 +260,19 @@ def main(): opts.error("Incorrect number of arguments") start_args = {'config_file': args[0], 'start_reason': 'startup'} - input_fd = bglogger = None - debuglevel = logging.INFO if options.verbose: debuglevel = logging.DEBUG if options.debuginput: start_args['debuginput'] = options.debuginput debuginput = open(options.debuginput, 'rb') - input_fd = debuginput.fileno() + start_args['gcode_fd'] = debuginput.fileno() else: - input_fd = util.create_pty(options.inputtty) + start_args['gcode_fd'] = util.create_pty(options.inputtty) if options.debugoutput: start_args['debugoutput'] = options.debugoutput start_args.update(options.dictionary) + bglogger = None if options.logfile: start_args['log_file'] = options.logfile bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel) @@ -298,7 +297,7 @@ def main(): if bglogger is not None: bglogger.clear_rollover_info() bglogger.set_rollover_info('versions', versions) - printer = Printer(input_fd, bglogger, start_args) + printer = Printer(bglogger, start_args) res = printer.run() if res in ['exit', 'error_exit']: break