Debian Codegraph @

troubleshoot/NetworkCUPSPrinterShared.py

raw
1 #!/usr/bin/python3
2
3 ## Printing troubleshooter
4
5 ## Copyright (C) 2008, 2009 Red Hat, Inc.
6 ## Copyright (C) 2008, 2009 Tim Waugh <[email protected]>
7
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
12
13 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details.
17
18 ## You should have received a copy of the GNU General Public License
19 ## along with this program; if not, write to the Free Software
20 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 import cups
23 from timedops import TimedOperation
24 from .base import *
25 class NetworkCUPSPrinterShared(Question):
26 def __init__ (self, troubleshooter):
27 Question.__init__ (self, troubleshooter, "Queue not shared?")
28 page = self.initial_vbox (_("Queue Not Shared"),
29 _("The CUPS printer on the server is not "
30 "shared."))
31 troubleshooter.new_page (page, self)
32
33 def display (self):
34 self.answers = {}
35 answers = self.troubleshooter.answers
36 if ('remote_cups_queue_listed' in answers and
37 answers['remote_cups_queue_listed'] == False):
38 return False
39
40 parent = self.troubleshooter.get_window ()
41 if 'remote_cups_queue_attributes' not in answers:
42 if not ('remote_server_try_connect' in answers and
43 'remote_cups_queue' in answers):
44 return False
45
46 try:
47 host = answers['remote_server_try_connect']
48 self.op = TimedOperation (cups.Connection,
49 kwargs={"host": host},
50 parent=parent)
51 c = self.op.run ()
52 self.op = TimedOperation (c.getPrinterAttributes,
53 args=(answers['remote_cups_queue'],),
54 parent=parent)
55 attr = self.op.run ()
56 except RuntimeError:
57 return False
58 except cups.IPPError:
59 return False
60
61 self.answers['remote_cups_queue_attributes'] = attr
62 else:
63 attr = answers['remote_cups_queue_attributes']
64
65 if 'printer-is-shared' in attr:
66 # CUPS >= 1.2
67 if not attr['printer-is-shared']:
68 return True
69
70 return False
71
72 def can_click_forward (self):
73 return False
74
75 def collect_answer (self):
76 return self.answers
77
78 def cancel_operation (self):
79 self.op.cancel ()