Back to index

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

List of all members.

Public Member Functions

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

Public Attributes

 answers
 op
 troubleshooter

Detailed Description

Definition at line 29 of file CheckUSBPermissions.py.


Constructor & Destructor Documentation

Definition at line 30 of file CheckUSBPermissions.py.

00030 
00031     def __init__ (self, troubleshooter):
00032         Question.__init__ (self, troubleshooter, "Check USB permissions")
00033         troubleshooter.new_page (gtk.Label (), self)


Member Function Documentation

Reimplemented from troubleshoot.base.Question.

Definition at line 170 of file CheckUSBPermissions.py.

00170 
00171     def cancel_operation (self):
00172         self.op.cancel ()

Reimplemented from troubleshoot.base.Question.

Definition at line 167 of file CheckUSBPermissions.py.

00167 
00168     def collect_answer (self):
00169         return self.answers

def troubleshoot.base.Question.connect_signals (   self,
  handler 
) [inherited]
Returns True if this page should be displayed, or False
if it should be skipped.

Reimplemented from troubleshoot.base.Question.

Definition at line 34 of file CheckUSBPermissions.py.

00034 
00035     def display (self):
00036         self.answers = {}
00037         answers = self.troubleshooter.answers
00038         if answers['cups_queue_listed']:
00039             if answers['is_cups_class']:
00040                 return False
00041 
00042             cups_printer_dict = answers['cups_printer_dict']
00043             device_uri = cups_printer_dict['device-uri']
00044         elif answers.get ('cups_device_listed', False):
00045             device_uri = answers['cups_device_uri']
00046         else:
00047             return False
00048 
00049         (scheme, rest) = urllib.splittype (device_uri)
00050         if scheme not in ['hp', 'hpfax', 'usb', 'hal']:
00051             return False
00052 
00053         LSUSB = "/sbin/lsusb"
00054         if not os.access (LSUSB, os.X_OK):
00055             return False
00056 
00057         GETFACL = "/usr/bin/getfacl"
00058         if not os.access (GETFACL, os.X_OK):
00059             return False
00060 
00061         new_environ = os.environ.copy()
00062         new_environ['LC_ALL'] = "C"
00063 
00064         # Run lsusb
00065         parent = self.troubleshooter.get_window ()
00066         try:
00067             self.op = TimedSubprocess (parent=parent,
00068                                        args=[LSUSB, "-v"],
00069                                        close_fds=True,
00070                                        env=new_environ,
00071                                        stdin=file("/dev/null"),
00072                                        stdout=subprocess.PIPE,
00073                                        stderr=subprocess.PIPE)
00074             (lsusb_stdout, lsusb_stderr, result) = self.op.run ()
00075         except:
00076             # Problem executing command.
00077             return False
00078 
00079         # Now parse it.
00080         dev_by_id = {}
00081         this_dev = None
00082         for line in lsusb_stdout:
00083             if (this_dev != None and
00084                 ((line.find ("bInterfaceClass") != -1 and
00085                   line.find ("7 Printer") != -1) or
00086                  (line.find ("bInterfaceSubClass") != -1 and
00087                   line.find ("1 Printer") != -1))):
00088                 mfr = dev_by_id.get (this_mfr_id, {})
00089                 mdl = mfr.get (this_mdl_id, [])
00090                 mdl.append (this_dev)
00091                 mfr[this_mdl_id] = mdl
00092                 dev_by_id[this_mfr_id] = mfr
00093                 this_dev = None
00094                 continue
00095 
00096             separators = [ ('Bus ', 3),
00097                            (' Device ', 3),
00098                            (': ID ', 4),
00099                            (':', 4),
00100                            (' ', -1)]
00101             fields = []
00102             i = 0
00103             p = line
00104             while i < len (separators):
00105                 (sep, length) = separators[i]
00106                 if not p.startswith (sep):
00107                     break
00108                 start = len (sep)
00109                 if length == -1:
00110                     end = len (p)
00111                     fields.append (p[start:])
00112                 else:
00113                     end = start + length
00114                     fields.append (p[start:end])
00115 
00116                 p = p[end:]
00117                 i += 1
00118 
00119             if i < len (separators):
00120                 continue
00121 
00122             if not scheme.startswith ('hp') and fields[2] != '03f0':
00123                 # Skip non-HP printers if we know we're using HPLIP.
00124                 continue
00125 
00126             this_dev = { 'bus': fields[0],
00127                          'dev': fields[1],
00128                          'name': fields[4],
00129                          'full': line }
00130             this_mfr_id = fields[2]
00131             this_mdl_id = fields[3]
00132 
00133         infos = {}
00134         paths = []
00135         if not scheme.startswith ('hp'):
00136             paths.extend (glob.glob ("/dev/usb/lp?"))
00137         for mfr_id, mdls in dev_by_id.iteritems ():
00138             for mdl_id, devs in mdls.iteritems ():
00139                 for dev in devs:
00140                     path = "/dev/bus/usb/%s/%s" % (dev['bus'], dev['dev'])
00141                     paths.append (path)
00142                     infos[path] = dev['full']
00143 
00144         perms = []
00145         for path in paths:
00146             try:
00147                 self.op = TimedSubprocess (parent=parent,
00148                                            args=[GETFACL, path],
00149                                            close_fds=True,
00150                                            env=new_environ,
00151                                            stdin=file("/dev/null"),
00152                                            stdout=subprocess.PIPE,
00153                                            stderr=subprocess.PIPE)
00154                 (getfacl_stdout, getfacl_stderr, result) = self.op.run ()
00155                 output = filter (lambda x: len (x) > 0, getfacl_stdout)
00156             except:
00157                 # Problem executing command.
00158                 output = []
00159 
00160             info = infos.get (path, path)
00161             perms.append ((info, output))
00162 
00163         self.answers['getfacl_output'] = perms
00164 
00165         # Don't actually display anything, just collect information.
00166         return False

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:


Member Data Documentation

Definition at line 35 of file CheckUSBPermissions.py.

Definition at line 66 of file CheckUSBPermissions.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: