/usr/share/system-config-printer/troubleshoot/CheckPrinterSanity.py is in system-config-printer-gnome 1.3.8+20120201-0ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | #!/usr/bin/python
## Printing troubleshooter
## Copyright (C) 2008, 2009, 2010, 2012 Red Hat, Inc.
## Authors:
## Tim Waugh <twaugh@redhat.com>
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import cups
import gobject
import os
import smburi
import subprocess
from timedops import TimedOperation, TimedSubprocess
import urllib
from base import *
class CheckPrinterSanity(Question):
def __init__ (self, troubleshooter):
Question.__init__ (self, troubleshooter, "Check printer sanity")
troubleshooter.new_page (gtk.Label (), self)
self.troubleshooter = troubleshooter
def display (self):
# Collect information useful for the various checks.
self.answers = {}
answers = self.troubleshooter.answers
if not answers['cups_queue_listed']:
return False
name = answers['cups_queue']
parent = self.troubleshooter.get_window ()
# Find out if this is a printer or a class.
try:
cups.setServer ('')
c = TimedOperation (cups.Connection, parent=parent).run ()
printers = TimedOperation (c.getPrinters, parent=parent).run ()
if printers.has_key (name):
self.answers['is_cups_class'] = False
queue = printers[name]
self.answers['cups_printer_dict'] = queue
else:
self.answers['is_cups_class'] = True
classes = TimedOperation (c.getClasses, parent=parent).run ()
queue = classes[name]
self.answers['cups_class_dict'] = queue
attrs = TimedOperation (c.getPrinterAttributes, (name,),
parent=parent).run ()
self.answers['local_cups_queue_attributes'] = attrs
except:
pass
if self.answers.has_key ('cups_printer_dict'):
cups_printer_dict = self.answers['cups_printer_dict']
uri = cups_printer_dict['device-uri']
(scheme, rest) = urllib.splittype (uri)
self.answers['cups_device_uri_scheme'] = scheme
if scheme in ["ipp", "http", "https"]:
(hostport, rest) = urllib.splithost (rest)
(host, port) = urllib.splitnport (hostport, defport=631)
self.answers['remote_server_name'] = host
self.answers['remote_server_port'] = port
elif scheme == "smb":
u = smburi.SMBURI (uri)
(group, host, share, user, password) = u.separate ()
new_environ = os.environ.copy()
new_environ['LC_ALL'] = "C"
if group:
args = ["nmblookup", "-W", group, host]
else:
args = ["nmblookup", host]
try:
p = TimedSubprocess (parent=parent,
timeout=5000,
args=args,
env=new_environ,
close_fds=True,
stdin=file("/dev/null"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = p.run ()
self.answers['nmblookup_output'] = result
for line in result[0]:
if line.startswith ("querying"):
continue
spc = line.find (' ')
if (spc != -1 and
not line[spc:].startswith (" failed ")):
# Remember the IP address.
self.answers['remote_server_name'] = line[:spc]
break
except OSError:
# Problem executing command.
pass
elif scheme == "hp":
new_environ = os.environ.copy()
new_environ['LC_ALL'] = "C"
new_environ['DISPLAY'] = ""
try:
p = TimedSubprocess (parent=parent,
timeout=3000,
args=["hp-info", "-d" + uri],
close_fds=True,
env=new_environ,
stdin=file("/dev/null"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.answers['hplip_output'] = p.run ()
except OSError:
# Problem executing command.
pass
r = cups_printer_dict['printer-type'] & cups.CUPS_PRINTER_REMOTE
self.answers['cups_printer_remote'] = (r != 0)
return False
def collect_answer (self):
return self.answers
|