Back to index

system-config-printer  1.3.9+20120706
NetworkCUPSPrinterShared.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2008, 2009 Red Hat, Inc.
00006 ## Copyright (C) 2008, 2009 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 NetworkCUPSPrinterShared(Question):
00026     def __init__ (self, troubleshooter):
00027         Question.__init__ (self, troubleshooter, "Queue not shared?")
00028         page = self.initial_vbox (_("Queue Not Shared"),
00029                                   _("The CUPS printer on the server is not "
00030                                     "shared."))
00031         troubleshooter.new_page (page, self)
00032 
00033     def display (self):
00034         self.answers = {}
00035         answers = self.troubleshooter.answers
00036         if (answers.has_key ('remote_cups_queue_listed') and
00037             answers['remote_cups_queue_listed'] == False):
00038             return False
00039 
00040         parent = self.troubleshooter.get_window ()
00041         if not answers.has_key ('remote_cups_queue_attributes'):
00042             if not (answers.has_key ('remote_server_try_connect') and
00043                     answers.has_key ('remote_cups_queue')):
00044                 return False
00045 
00046             try:
00047                 host = answers['remote_server_try_connect']
00048                 self.op = TimedOperation (cups.Connection,
00049                                           kwargs={"host": host},
00050                                           parent=parent)
00051                 c = self.op.run ()
00052                 self.op = TimedOperation (c.getPrinterAttributes,
00053                                           args=(answers['remote_cups_queue'],),
00054                                           parent=parent)
00055                 attr = self.op.run ()
00056             except RuntimeError:
00057                 return False
00058             except cups.IPPError:
00059                 return False
00060 
00061             self.answers['remote_cups_queue_attributes'] = attr
00062         else:
00063             attr = answers['remote_cups_queue_attributes']
00064 
00065         if attr.has_key ('printer-is-shared'):
00066             # CUPS >= 1.2
00067             if not attr['printer-is-shared']:
00068                 return True
00069 
00070         return False
00071 
00072     def can_click_forward (self):
00073         return False
00074 
00075     def collect_answer (self):
00076         return self.answers
00077 
00078     def cancel_operation (self):
00079         self.op.cancel ()