Back to index

system-config-printer  1.3.9+20120706
Public Member Functions | Public Attributes
troubleshoot.CheckPPDSanity.CheckPPDSanity Class Reference
Inheritance diagram for troubleshoot.CheckPPDSanity.CheckPPDSanity:
Inheritance graph
[legend]
Collaboration diagram for troubleshoot.CheckPPDSanity.CheckPPDSanity:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def display
def connect_signals
def disconnect_signals
def collect_answer
def cancel_operation
def install_clicked
def can_click_forward
def initial_vbox
 Helper functions.

Public Attributes

 label
 install_button
 answers
 op
 packagekit
 package
 button_sigid
 troubleshooter

Detailed Description

Definition at line 31 of file CheckPPDSanity.py.


Constructor & Destructor Documentation

def troubleshoot.CheckPPDSanity.CheckPPDSanity.__init__ (   self,
  troubleshooter 
)

Definition at line 32 of file CheckPPDSanity.py.

00032 
00033     def __init__ (self, troubleshooter):
00034         Question.__init__ (self, troubleshooter, "Check PPD sanity")
00035         vbox = gtk.VBox ()
00036         vbox.set_border_width (12)
00037         vbox.set_spacing (12)
00038         self.label = gtk.Label ()
00039         self.label.set_line_wrap (True)
00040         self.label.set_use_markup (True)
00041         self.label.set_alignment (0, 0)
00042         vbox.pack_start (self.label, False, False, 0)
00043 
00044         box = gtk.HButtonBox ()
00045         box.set_layout (gtk.BUTTONBOX_START)
00046         self.install_button = gtk.Button (_("Install"))
00047         box.add (self.install_button)
00048         # Although we want this hidden initially,
00049         # troubleshooter.new_page will call show_all() on the widget
00050         # we give it.  We'll need to hide this button in the display()
00051         # callback instead.
00052         vbox.pack_start (box, False, False, 0)
00053 
00054         troubleshooter.new_page (vbox, self)


Member Function Documentation

Reimplemented from troubleshoot.base.Question.

Definition at line 158 of file CheckPPDSanity.py.

00158 
00159     def cancel_operation (self):
00160         self.op.cancel ()

Reimplemented from troubleshoot.base.Question.

Definition at line 155 of file CheckPPDSanity.py.

00155 
00156     def collect_answer (self):
00157         return self.answers

Reimplemented from troubleshoot.base.Question.

Definition at line 148 of file CheckPPDSanity.py.

00148 
00149     def connect_signals (self, handle):
00150         self.button_sigid = self.install_button.connect ("clicked",
00151                                                          self.install_clicked)

Reimplemented from troubleshoot.base.Question.

Definition at line 152 of file CheckPPDSanity.py.

00152 
00153     def disconnect_signals (self):
00154         self.install_button.disconnect (self.button_sigid)

Returns True if this page should be displayed, or False
if it should be skipped.

Reimplemented from troubleshoot.base.Question.

Definition at line 55 of file CheckPPDSanity.py.

00055 
00056     def display (self):
00057         self.answers = {}
00058 
00059         answers = self.troubleshooter.answers
00060         if not answers['cups_queue_listed']:
00061             return False
00062 
00063         parent = self.troubleshooter.get_window ()
00064         name = answers['cups_queue']
00065         tmpf = None
00066         try:
00067             cups.setServer ('')
00068             self.op = TimedOperation (cups.Connection, parent=parent)
00069             c = self.op.run ()
00070             self.op = TimedOperation (c.getPPD, args=(name,), parent=parent)
00071             tmpf = self.op.run ()
00072         except RuntimeError:
00073             return False
00074         except cups.IPPError:
00075             return False
00076 
00077         self.install_button.hide ()
00078         title = None
00079         text = None
00080         try:
00081             ppd = cups.PPD (tmpf)
00082             self.answers['cups_printer_ppd_valid'] = True
00083 
00084             def options (options_list):
00085                 o = {}
00086                 for option in options_list:
00087                     o[option.keyword] = option.defchoice
00088                 return o
00089 
00090             defaults = {}
00091             for group in ppd.optionGroups:
00092                 g = options (group.options)
00093                 for subgroup in group.subgroups:
00094                     g[subgroup.name] = options (subgroup.options)
00095                 defaults[group.name] = g
00096             self.answers['cups_printer_ppd_defaults'] = defaults
00097         except RuntimeError:
00098             title = _("Invalid PPD File")
00099             self.answers['cups_printer_ppd_valid'] = False
00100             try:
00101                 self.op = TimedSubprocess (parent=parent,
00102                                            args=['cupstestppd', '-rvv', tmpf],
00103                                            close_fds=True,
00104                                            stdin=file("/dev/null"),
00105                                            stdout=subprocess.PIPE,
00106                                            stderr=subprocess.PIPE)
00107                 result = self.op.run ()
00108                 self.answers['cupstestppd_output'] = result
00109                 text = _("The PPD file for printer '%s' does not conform "
00110                          "to the specification.  "
00111                          "Possible reason follows:") % name
00112                 text += '\n' + reduce (lambda x, y: x + '\n' + y, result[0])
00113             except OSError:
00114                 # Perhaps cupstestppd is not in the path.
00115                 text = _("There is a problem with the PPD file for "
00116                          "printer '%s'.") % name
00117 
00118         if tmpf:
00119             os.unlink (tmpf)
00120 
00121         if title == None and not answers['cups_printer_remote']:
00122             (pkgs, exes) = cupshelpers.missingPackagesAndExecutables (ppd)
00123             self.answers['missing_pkgs_and_exes'] = (pkgs, exes)
00124             if len (pkgs) > 0 or len (exes) > 0:
00125                 title = _("Missing Printer Driver")
00126                 if len (pkgs) > 0:
00127                     try:
00128                         self.packagekit = installpackage.PackageKit ()
00129                     except:
00130                         pkgs = []
00131 
00132                 if len (pkgs) > 0:
00133                     self.package = pkgs[0]
00134                     text = _("Printer '%s' requires the %s package but it "
00135                              "is not currently installed.") % (name,
00136                                                                self.package)
00137                     self.install_button.show ()
00138                 else:
00139                     text = _("Printer '%s' requires the '%s' program but it "
00140                              "is not currently installed.") % (name,
00141                                                                (exes + pkgs)[0])
00142 
00143         if title != None:
00144             self.label.set_markup ('<span weight="bold" size="larger">' +
00145                                    title + '</span>\n\n' + text)
00146 
00147         return title != None

def troubleshoot.base.Question.initial_vbox (   self,
  title = '',
  text = '' 
) [inherited]

Helper functions.

Definition at line 66 of file base.py.

00066 
00067     def initial_vbox (self, title='', text=''):
00068         vbox = gtk.VBox ()
00069         vbox.set_border_width (12)
00070         vbox.set_spacing (12)
00071         if title:
00072             s = '<span weight="bold" size="larger">' + title + '</span>\n\n'
00073         else:
00074             s = ''
00075         s += text
00076         label = gtk.Label (s)
00077         label.set_alignment (0, 0)
00078         label.set_line_wrap (True)
00079         label.set_use_markup (True)
00080         vbox.pack_start (label, False, False, 0)
00081         return vbox

Here is the caller graph for this function:

Definition at line 161 of file CheckPPDSanity.py.

00161 
00162     def install_clicked (self, button):
00163         pkgs = self.answers.get('packages_installed', [])
00164         pkgs.append (self.package)
00165         self.answers['packages_installed'] = pkgs
00166         try:
00167             self.packagekit.InstallPackageName (0, 0, self.package)
00168         except:
00169             pass

Member Data Documentation

Definition at line 56 of file CheckPPDSanity.py.

Definition at line 149 of file CheckPPDSanity.py.

Definition at line 45 of file CheckPPDSanity.py.

Definition at line 37 of file CheckPPDSanity.py.

Definition at line 67 of file CheckPPDSanity.py.

Definition at line 132 of file CheckPPDSanity.py.

Definition at line 127 of file CheckPPDSanity.py.

Reimplemented in troubleshoot.CheckPrinterSanity.CheckPrinterSanity.

Definition at line 41 of file base.py.


The documentation for this class was generated from the following file: