3
# Watch line printer queue(s).
4
# Intended for BSD 4.3 lpq.
15
delay = DEF_DELAY # XXX Use getopt() later
17
thisuser = posix.environ['LOGNAME']
19
thisuser = posix.environ['USER']
20
printers = sys.argv[1:]
22
# Strip '-P' from printer names just in case
23
# the user specified it...
24
for i in range(len(printers)):
25
if printers[i][:2] == '-P':
26
printers[i] = printers[i][2:]
28
if 'PRINTER' in posix.environ:
29
printers = [posix.environ['PRINTER']]
31
printers = [DEF_PRINTER]
33
clearhome = posix.popen('clear', 'r').read()
38
text = text + makestatus(name, thisuser) + '\n'
42
def makestatus(name, thisuser):
43
pipe = posix.popen('lpq -P' + name + ' 2>&1', 'r')
52
line = pipe.readline()
54
fields = string.split(line)
56
if len(fields) >= 6 and fields[n-1] == 'bytes':
61
bytes = eval(fields[n-2])
65
aheadbytes = aheadbytes + bytes
66
aheadjobs = aheadjobs + 1
67
totalbytes = totalbytes + bytes
68
totaljobs = totaljobs + 1
70
ujobs, ubytes = users[user]
74
ubytes = ubytes + bytes
75
users[user] = ujobs, ubytes
77
if fields and fields[0] != 'Rank':
78
line = string.strip(line)
79
if line == 'no entries':
80
line = name + ': idle'
81
elif line[-22:] == ' is ready and printing':
86
line = '%d K' % ((totalbytes+1023)//1024)
87
if totaljobs != len(users):
88
line = line + ' (%d jobs)' % totaljobs
90
line = line + ' for %s' % (list(users.keys())[0],)
92
line = line + ' for %d users' % len(users)
95
line = line + ' (%s first)' % thisuser
97
line = line + ' (%d K before %s)' % (
98
(aheadbytes+1023)//1024, thisuser)
103
lines.append('lpq exit status %r' % (sts,))
104
return string.joinfields(lines, ': ')
106
if __name__ == "__main__":
109
except KeyboardInterrupt: