From f5f670069d6aef364b2245b5b3068e4c4a1c1148 Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Mon, 19 Nov 2018 13:34:48 +0100 Subject: [PATCH] Fix bad use of NamedTemporaryFile - os.stat call expects file path not file object --- troubleshoot/ErrorLogCheckpoint.py | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/troubleshoot/ErrorLogCheckpoint.py b/troubleshoot/ErrorLogCheckpoint.py index 7394c581..7ba7396e 100644 --- a/troubleshoot/ErrorLogCheckpoint.py +++ b/troubleshoot/ErrorLogCheckpoint.py @@ -134,28 +134,28 @@ class ErrorLogCheckpoint(Question): if 'error_log_checkpoint' in self.answers: return self.answers - with NamedTemporaryFile () as tmpf: - try: - self.op = TimedOperation (self.authconn.getFile, - args=('/admin/log/error_log', - tmpf.file), - parent=parent) - self.op.run () - except (RuntimeError, cups.IPPError) as e: - self.answers['error_log_checkpoint_exc'] = e - except cups.HTTPError as e: - self.answers['error_log_checkpoint_exc'] = e - - # Abandon the CUPS connection and make another. - answers = self.troubleshooter.answers - factory = answers['_authenticated_connection_factory'] - self.authconn = factory.get_connection () - self.answers['_authenticated_connection'] = self.authconn + tmpf = NamedTemporaryFile() + try: + self.op = TimedOperation (self.authconn.getFile, + args=["/admin/log/error_log"], + kwargs={'file': tmpf}, + parent=parent) + self.op.run () + except (RuntimeError, cups.IPPError) as e: + self.answers['error_log_checkpoint_exc'] = e + except cups.HTTPError as e: + self.answers['error_log_checkpoint_exc'] = e + + # Abandon the CUPS connection and make another. + answers = self.troubleshooter.answers + factory = answers['_authenticated_connection_factory'] + self.authconn = factory.get_connection () + self.answers['_authenticated_connection'] = self.authconn - try: - statbuf = os.stat (tmpf.file) - except OSError: - statbuf = [0, 0, 0, 0, 0, 0, 0] + try: + statbuf = os.stat (tmpf.name) + except OSError: + statbuf = [0, 0, 0, 0, 0, 0, 0] self.answers['error_log_checkpoint'] = statbuf[6] self.persistent_answers['error_log_checkpoint'] = statbuf[6] -- 2.33.0