Back to index

system-config-printer  1.3.9+20120706
CheckLocalServerPublishing.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2008 Red Hat, Inc.
00006 ## Copyright (C) 2008 Tim Waugh <twaugh@redhat.com>
00007 
00008 ## This program is free software; you can redistribute it and/or modify
00009 ## it under the terms of the GNU General Public License as published by
00010 ## the Free Software Foundation; either version 2 of the License, or
00011 ## (at your option) any later version.
00012 
00013 ## This program is distributed in the hope that it will be useful,
00014 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ## GNU General Public License for more details.
00017 
00018 ## You should have received a copy of the GNU General Public License
00019 ## along with this program; if not, write to the Free Software
00020 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 
00022 import cups
00023 from timedops import TimedOperation
00024 from base import *
00025 class CheckLocalServerPublishing(Question):
00026     def __init__ (self, troubleshooter):
00027         Question.__init__ (self, troubleshooter, "Is local server publishing?")
00028         vbox = self.initial_vbox (_("Server Not Exporting Printers"),
00029                                   _("Although one or more printers are marked "
00030                                     "as being shared, this print server is "
00031                                     "not exporting shared printers to the "
00032                                     "network.") + '\n\n' +
00033                                   _("Enable the 'Publish shared printers "
00034                                     "connected to this system' option in "
00035                                     "the server settings using the printing "
00036                                     "administration tool.") + ' ' +
00037                                   _(TEXT_start_print_admin_tool))
00038         troubleshooter.new_page (vbox, self)
00039 
00040     def display (self):
00041         self.answers = {}
00042         cups.setServer ('')
00043         parent = self.troubleshooter.get_window ()
00044         try:
00045             c = self.timedop (cups.Connection, parent=parent).run ()
00046             printers = self.timedop (c.getPrinters, parent=parent).run ()
00047             if len (printers) == 0:
00048                 return False
00049 
00050             for name, printer in printers.iteritems ():
00051                 if printer.get ('printer-is-shared', False):
00052                     break
00053 
00054             attr = self.timedop (c.getPrinterAttributes,
00055                                  args=(name,),
00056                                  parent=parent).run ()
00057         except RuntimeError:
00058             return False
00059         except cups.IPPError:
00060             return False
00061 
00062         if not printer.get ('printer-is-shared', False):
00063             return False
00064 
00065         if attr.get ('server-is-sharing-printers', True):
00066             # server-is-sharing-printers is in CUPS 1.4
00067             return False
00068 
00069         return True
00070 
00071     def collect_answer (self):
00072         if self.displayed:
00073             return { 'local_server_exporting_printers': False }
00074 
00075         return {}
00076 
00077     def cancel_operation (self):
00078         self.op.cancel ()
00079 
00080     def timedop (self, *args, **kwargs):
00081         self.op = TimedOperation (*args, **kwargs)
00082         return self.op