Skip to content

Commit 30e1125

Browse files
authored
Merge pull request #124 from TomasKorbar/rhbz1577082
Fix troubleshoot
2 parents c9bca89 + eb13a50 commit 30e1125

6 files changed

Lines changed: 36 additions & 25 deletions

File tree

authconn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ def _make_binding (self, fname, fn):
233233

234234
def _authloop (self, fname, fn, *args, **kwds):
235235
self._passes = 0
236+
# remove signature if dbus is not being used and signature is provided
237+
if not self._using_polkit():
238+
kwds.pop('signature', None)
239+
236240
c = self._connection
237241
retry = False
238242
while True:

cupspk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def _get_cups_pk(self):
9999

100100
def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fallback_function, *args, **kwds):
101101
pk_function = None
102+
# take signature from kwds if is provided
103+
dbus_args_signature = kwds.pop('signature', None)
102104

103105
if not use_fallback:
104106
cups_pk = self._get_cups_pk()
@@ -116,7 +118,7 @@ def _call_with_pk_and_fallback(self, use_fallback, pk_function_name, pk_args, fa
116118
while True:
117119
try:
118120
# FIXME: async call or not?
119-
pk_retval = pk_function(*pk_args)
121+
pk_retval = pk_function(*pk_args, signature = dbus_args_signature)
120122

121123
# if the PK call has more than one return values, we pop the
122124
# first one as the error message

troubleshoot/DeviceListed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def display (self):
8686
self.authconn = answers['_authenticated_connection']
8787
try:
8888
self.op = TimedOperation (self.authconn.getDevices,
89+
kwargs={'signature': 'iiasas'},
8990
parent=parent)
9091
devices = self.op.run ()
9192
devices_list = []

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]

troubleshoot/ErrorLogFetch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def fetch_log (c):
6969
with NamedTemporaryFile (delete=False) as tmpf:
7070
success = False
7171
try:
72-
c.getFile ('/admin/log/error_log', tmpf.file)
72+
c.getFile ('/admin/log/error_log', file = tmpf)
7373
success = True
7474
except cups.HTTPError:
7575
try:
76-
os.remove (tmpf.file)
76+
os.remove (tmpf.name)
7777
except OSError:
7878
pass
7979

troubleshoot/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from gi.repository import Gtk
2424
import pprint
2525
import sys
26+
import datetime
27+
import time
2628
import traceback
2729

2830
if __name__ == "__main__":
@@ -102,7 +104,9 @@ def __init__ (self, quitfn=None, parent=None):
102104

103105
self.questions = []
104106
self.question_answers = []
105-
self.answers = {}
107+
# timestamp should be accessible through whole troubleshoot
108+
now = datetime.datetime.fromtimestamp (time.time ())
109+
self.answers = {'error_log_timestamp': now.strftime ("%F %T")}
106110
self.moving_backwards = False
107111

108112
main.show_all ()

0 commit comments

Comments
 (0)