| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
## Printing troubleshooter |
| 4 |
|
| 5 |
## Copyright (C) 2008 Red Hat, Inc. |
| 6 |
## Copyright (C) 2008 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 CheckLocalServerPublishing(Question): |
| 26 |
def __init__ (self, troubleshooter): |
| 27 |
Question.__init__ (self, troubleshooter, "Is local server publishing?") |
| 28 |
vbox = self.initial_vbox (_("Server Not Exporting Printers"), |
| 29 |
_("Although one or more printers are marked " |
| 30 |
"as being shared, this print server is " |
| 31 |
"not exporting shared printers to the " |
| 32 |
"network.") + '\n\n' + |
| 33 |
_("Enable the 'Publish shared printers " |
| 34 |
"connected to this system' option in " |
| 35 |
"the server settings using the printing " |
| 36 |
"administration tool.") + ' ' + |
| 37 |
_(TEXT_start_print_admin_tool)) |
| 38 |
troubleshooter.new_page (vbox, self) |
| 39 |
|
| 40 |
def display (self): |
| 41 |
self.answers = {} |
| 42 |
cups.setServer ('') |
| 43 |
parent = self.troubleshooter.get_window () |
| 44 |
try: |
| 45 |
c = self.timedop (cups.Connection, parent=parent).run () |
| 46 |
printers = self.timedop (c.getPrinters, parent=parent).run () |
| 47 |
if len (printers) == 0: |
| 48 |
return False |
| 49 |
|
| 50 |
for name, printer in printers.items (): |
| 51 |
if printer.get ('printer-is-shared', False): |
| 52 |
break |
| 53 |
|
| 54 |
attr = self.timedop (c.getPrinterAttributes, |
| 55 |
args=(name,), |
| 56 |
parent=parent).run () |
| 57 |
except RuntimeError: |
| 58 |
return False |
| 59 |
except cups.IPPError: |
| 60 |
return False |
| 61 |
|
| 62 |
if not printer.get ('printer-is-shared', False): |
| 63 |
return False |
| 64 |
|
| 65 |
if attr.get ('server-is-sharing-printers', True): |
| 66 |
# server-is-sharing-printers is in CUPS 1.4 |
| 67 |
return False |
| 68 |
|
| 69 |
return True |
| 70 |
|
| 71 |
def collect_answer (self): |
| 72 |
if self.displayed: |
| 73 |
return { 'local_server_exporting_printers': False } |
| 74 |
|
| 75 |
return {} |
| 76 |
|
| 77 |
def cancel_operation (self): |
| 78 |
self.op.cancel () |
| 79 |
|
| 80 |
def timedop (self, *args, **kwargs): |
| 81 |
self.op = TimedOperation (*args, **kwargs) |
| 82 |
return self.op |