Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5714a46d
Commit
5714a46d
authored
Dec 18, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modularized the code.
parent
011e9db8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
33 deletions
+26
-33
Demo/scripts/lpwatch.py
Demo/scripts/lpwatch.py
+26
-33
No files found.
Demo/scripts/lpwatch.py
View file @
5714a46d
...
@@ -34,22 +34,15 @@ def main():
...
@@ -34,22 +34,15 @@ def main():
clearhome
=
posix
.
popen
(
'clear'
,
'r'
).
read
()
clearhome
=
posix
.
popen
(
'clear'
,
'r'
).
read
()
#
#
while
1
:
while
1
:
# Pipe output through cat for extra buffering,
text
=
clearhome
# so the output (which overwrites the previous)
# appears instantaneous.
sys
.
stdout
=
posix
.
popen
(
'exec cat'
,
'w'
)
sys
.
stdout
.
write
(
clearhome
)
for
name
in
printers
:
for
name
in
printers
:
pipe
=
posix
.
popen
(
'lpq -P'
+
name
+
' 2>&1'
,
'r'
)
text
=
text
+
makestatus
(
name
,
thisuser
)
+
'
\
n
'
showstatus
(
name
,
pipe
,
thisuser
)
print
text
sts
=
pipe
.
close
()
if
sts
:
print
name
+
': *** lpq exit status'
,
sts
sts
=
sys
.
stdout
.
close
()
time
.
sleep
(
delay
)
time
.
sleep
(
delay
)
def
showstatus
(
name
,
pipe
,
thisuser
):
def
makestatus
(
name
,
thisuser
):
lines
=
0
pipe
=
posix
.
popen
(
'lpq -P'
+
name
+
' 2>&1'
,
'r'
)
lines
=
[]
users
=
{}
users
=
{}
aheadbytes
=
0
aheadbytes
=
0
aheadjobs
=
0
aheadjobs
=
0
...
@@ -83,33 +76,33 @@ def showstatus(name, pipe, thisuser):
...
@@ -83,33 +76,33 @@ def showstatus(name, pipe, thisuser):
users
[
user
]
=
ujobs
,
ubytes
users
[
user
]
=
ujobs
,
ubytes
else
:
else
:
if
fields
and
fields
[
0
]
<>
'Rank'
:
if
fields
and
fields
[
0
]
<>
'Rank'
:
if
line
[
-
1
:]
=
'
\
n
'
:
line
=
string
.
strip
(
line
)
line
=
line
[:
-
1
]
if
line
=
'no entries'
:
if
not
lines
:
line
=
name
+
': idle'
print
name
+
':'
,
elif
line
[
-
22
:]
=
' is ready and printing'
:
else
:
line
=
name
print
lines
.
append
(
line
)
print
line
,
#
lines
=
lines
+
1
if
totaljobs
:
if
totaljobs
:
if
lines
>
1
:
line
=
`(totalbytes+1023)/1024`
+
' K'
print
lines
=
lines
+
1
print
(
totalbytes
+
1023
)
/
1024
,
'K'
,
if
totaljobs
<>
len
(
users
):
if
totaljobs
<>
len
(
users
):
print
'('
+
`totaljobs`
+
' jobs)'
,
line
=
line
+
' ('
+
`totaljobs`
+
' jobs)'
if
len
(
users
)
=
1
:
if
len
(
users
)
=
1
:
print
'for'
,
users
.
keys
()[
0
],
line
=
line
+
' for '
+
users
.
keys
()[
0
]
else
:
else
:
print
'for'
,
len
(
users
),
'users'
,
line
=
line
+
' for '
+
`len(users)`
+
' users'
if
userseen
:
if
userseen
:
if
aheadjobs
=
0
:
if
aheadjobs
=
0
:
print
'('
+
thisuser
+
' first)'
,
line
=
line
+
' ('
+
thisuser
+
' first)'
else
:
else
:
print
'('
+
`(aheadbytes+1023)/1024`
,
line
=
line
+
' ('
+
`(aheadbytes+1023)/1024`
print
'K before'
,
thisuser
+
')'
line
=
line
+
' K before '
+
thisuser
+
')'
if
lines
:
lines
.
append
(
line
)
print
#
sts
=
pipe
.
close
()
if
sts
:
lines
.
append
(
'lpq exit status '
+
`sts`
)
return
string
.
joinfields
(
lines
,
': '
)
try
:
try
:
main
()
main
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment