Skip to content

Commit f5f6700

Browse files
committed
Fix bad use of NamedTemporaryFile
- os.stat call expects file path not file object
1 parent 2ac2d7c commit f5f6700

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

troubleshoot/ErrorLogCheckpoint.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,28 @@ def collect_answer (self):
134134
if 'error_log_checkpoint' in self.answers:
135135
return self.answers
136136

137-
with NamedTemporaryFile () as tmpf:
138-
try:
139-
self.op = TimedOperation (self.authconn.getFile,
140-
args=('/admin/log/error_log',
141-
tmpf.file),
142-
parent=parent)
143-
self.op.run ()
144-
except (RuntimeError, cups.IPPError) as e:
145-
self.answers['error_log_checkpoint_exc'] = e
146-
except cups.HTTPError as e:
147-
self.answers['error_log_checkpoint_exc'] = e
148-
149-
# Abandon the CUPS connection and make another.
150-
answers = self.troubleshooter.answers
151-
factory = answers['_authenticated_connection_factory']
152-
self.authconn = factory.get_connection ()
153-
self.answers['_authenticated_connection'] = self.authconn
137+
tmpf = NamedTemporaryFile()
138+
try:
139+
self.op = TimedOperation (self.authconn.getFile,
140+
args=["/admin/log/error_log"],
141+
kwargs={'file': tmpf},
142+
parent=parent)
143+
self.op.run ()
144+
except (RuntimeError, cups.IPPError) as e:
145+
self.answers['error_log_checkpoint_exc'] = e
146+
except cups.HTTPError as e:
147+
self.answers['error_log_checkpoint_exc'] = e
148+
149+
# Abandon the CUPS connection and make another.
150+
answers = self.troubleshooter.answers
151+
factory = answers['_authenticated_connection_factory']
152+
self.authconn = factory.get_connection ()
153+
self.answers['_authenticated_connection'] = self.authconn
154154

155-
try:
156-
statbuf = os.stat (tmpf.file)
157-
except OSError:
158-
statbuf = [0, 0, 0, 0, 0, 0, 0]
155+
try:
156+
statbuf = os.stat (tmpf.name)
157+
except OSError:
158+
statbuf = [0, 0, 0, 0, 0, 0, 0]
159159

160160
self.answers['error_log_checkpoint'] = statbuf[6]
161161
self.persistent_answers['error_log_checkpoint'] = statbuf[6]

0 commit comments

Comments
 (0)