4
## Copyright (C) 2008 Red Hat, Inc.
5
## Copyright (C) 2008 Tim Waugh <twaugh@redhat.com>
7
## This program is free software; you can redistribute it and/or modify
8
## it under the terms of the GNU General Public License as published by
9
## the Free Software Foundation; either version 2 of the License, or
10
## (at your option) any later version.
12
## This program is distributed in the hope that it will be useful,
13
## but WITHOUT ANY WARRANTY; without even the implied warranty of
14
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
## GNU General Public License for more details.
17
## You should have received a copy of the GNU General Public License
18
## along with this program; if not, write to the Free Software
19
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
from cupshelpers import missingPackagesAndExecutables
27
sys.path.append ('..')
28
from cupshelpers import missingPackagesAndExecutables
30
from getopt import getopt
39
class TimedOut(Exception):
41
Exception.__init__ (self, "Timed out")
43
class MissingExecutables(Exception):
45
Exception.__init__ (self, "Missing executables")
48
def __init__ (self, driver):
49
self.exe = "/usr/lib/cups/driver/%s" % driver
52
signal.signal (signal.SIGALRM, self._alarm)
54
def _alarm (self, sig, stack):
62
p = subprocess.Popen ([self.exe, "list"],
63
stdout=subprocess.PIPE,
64
stderr=subprocess.PIPE)
66
(stdout, stderr) = p.communicate ()
69
posix.kill (p.pid, signal.SIGKILL)
73
print >> sys.stderr, stderr
76
lines = stdout.split ('\n')
78
l = shlex.split (line)
88
return self.files[name]
91
p = subprocess.Popen ([self.exe, "cat", name],
92
stdout=subprocess.PIPE,
93
stderr=subprocess.PIPE)
95
(stdout, stderr) = p.communicate ()
98
posix.kill (p.pid, signal.SIGKILL)
102
print >> sys.stderr, stderr
104
self.files[name] = stdout
107
opts, args = getopt (sys.argv[1:], "m:")
109
print "Syntax: test-cups-driver [-m REGEXP] DRIVER"
113
for opt, arg in opts:
124
exp = re.compile (match)
125
list = filter (lambda x: exp.match (x), list)
133
(fd, fname) = tempfile.mkstemp ()
134
f = os.fdopen (fd, "w")
138
PPD = cups.PPD (fname)
144
(pkgs, exes) = missingPackagesAndExecutables (PPD)
146
raise MissingExecutables
148
attr = PPD.findAttr ('1284DeviceID')
150
pieces = attr.value.split (';')
153
s = piece.split (':', 1)
158
if key in ["MFG", "MANUFACTURER"]:
160
elif key in ["MDL", "MODEL"]:
163
id = "MFG:%s;MDL:%s;" % (mfg, mdl)
165
sys.stderr.write ("%3d%%\r" % (100 * i / n))
167
except KeyboardInterrupt:
168
print "Keyboard interrupt\n"
170
except TimedOut as e:
171
bad.append ((name, e))
172
print "Timed out fetching %s" % name
173
except Exception as e:
174
bad.append ((name, e))
175
print "Exception fetching %s: %s" % (name, e)
182
print " %s (%s)" % each
186
print "IEEE 1284 Device IDs:"