Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
393c8232
Kaydet (Commit)
393c8232
authored
Eki 11, 2009
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Update lpwatch script.
üst
8ec30e83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
52 deletions
+44
-52
lpwatch.py
Demo/scripts/lpwatch.py
+40
-48
newslist.py
Demo/scripts/newslist.py
+1
-1
queens.py
Demo/scripts/queens.py
+3
-3
No files found.
Demo/scripts/lpwatch.py
Dosyayı görüntüle @
393c8232
...
...
@@ -3,10 +3,9 @@
# Watch line printer queue(s).
# Intended for BSD 4.3 lpq.
import
posix
import
os
import
sys
import
time
import
string
DEF_PRINTER
=
'psc'
DEF_DELAY
=
10
...
...
@@ -14,94 +13,87 @@ DEF_DELAY = 10
def
main
():
delay
=
DEF_DELAY
# XXX Use getopt() later
try
:
thisuser
=
posix
.
environ
[
'LOGNAME'
]
thisuser
=
os
.
environ
[
'LOGNAME'
]
except
:
thisuser
=
posix
.
environ
[
'USER'
]
thisuser
=
os
.
environ
[
'USER'
]
printers
=
sys
.
argv
[
1
:]
if
printers
:
# Strip '-P' from printer names just in case
# the user specified it...
for
i
in
range
(
len
(
printers
)
):
if
printers
[
i
]
[:
2
]
==
'-P'
:
printers
[
i
]
=
printers
[
i
]
[
2
:]
for
i
,
name
in
enumerate
(
printers
):
if
name
[:
2
]
==
'-P'
:
printers
[
i
]
=
name
[
2
:]
else
:
if
posix
.
environ
.
has_key
(
'PRINTER'
):
printers
=
[
posix
.
environ
[
'PRINTER'
]]
if
os
.
environ
.
has_key
(
'PRINTER'
):
printers
=
[
os
.
environ
[
'PRINTER'
]]
else
:
printers
=
[
DEF_PRINTER
]
#
clearhome
=
posix
.
popen
(
'clear'
,
'r'
)
.
read
()
#
while
1
:
clearhome
=
os
.
popen
(
'clear'
,
'r'
)
.
read
()
while
True
:
text
=
clearhome
for
name
in
printers
:
text
=
text
+
makestatus
(
name
,
thisuser
)
+
'
\n
'
text
+=
makestatus
(
name
,
thisuser
)
+
'
\n
'
print
text
time
.
sleep
(
delay
)
def
makestatus
(
name
,
thisuser
):
pipe
=
posix
.
popen
(
'lpq -P'
+
name
+
' 2>&1'
,
'r'
)
pipe
=
os
.
popen
(
'lpq -P'
+
name
+
' 2>&1'
,
'r'
)
lines
=
[]
users
=
{}
aheadbytes
=
0
aheadjobs
=
0
userseen
=
0
userseen
=
False
totalbytes
=
0
totaljobs
=
0
while
1
:
line
=
pipe
.
readline
()
if
not
line
:
break
fields
=
string
.
split
(
line
)
for
line
in
pipe
:
fields
=
line
.
split
()
n
=
len
(
fields
)
if
len
(
fields
)
>=
6
and
fields
[
n
-
1
]
==
'bytes'
:
rank
=
fields
[
0
]
user
=
fields
[
1
]
job
=
fields
[
2
]
rank
,
user
,
job
=
fields
[
0
:
3
]
files
=
fields
[
3
:
-
2
]
bytes
=
eval
(
fields
[
n
-
2
])
bytes
=
int
(
fields
[
n
-
2
])
if
user
==
thisuser
:
userseen
=
1
userseen
=
True
elif
not
userseen
:
aheadbytes
=
aheadbytes
+
bytes
aheadjobs
=
aheadjobs
+
1
totalbytes
=
totalbytes
+
bytes
totaljobs
=
totaljobs
+
1
if
users
.
has_key
(
user
):
ujobs
,
ubytes
=
users
[
user
]
else
:
ujobs
,
ubytes
=
0
,
0
ujobs
=
ujobs
+
1
ubytes
=
ubytes
+
bytes
aheadbytes
+=
bytes
aheadjobs
+=
1
totalbytes
+=
bytes
totaljobs
+=
1
ujobs
,
ubytes
=
users
.
get
(
user
,
(
0
,
0
))
ujobs
+=
1
ubytes
+=
bytes
users
[
user
]
=
ujobs
,
ubytes
else
:
if
fields
and
fields
[
0
]
<>
'Rank'
:
line
=
string
.
strip
(
line
)
if
fields
and
fields
[
0
]
!=
'Rank'
:
line
=
line
.
strip
(
)
if
line
==
'no entries'
:
line
=
name
+
': idle'
elif
line
[
-
22
:]
==
' is ready and printing'
:
line
=
name
lines
.
append
(
line
)
#
if
totaljobs
:
line
=
'
%
d K'
%
((
totalbytes
+
1023
)
//
1024
)
if
totaljobs
<>
len
(
users
):
line
=
line
+
' (
%
d jobs)'
%
totaljobs
line
=
'
%
d K'
%
((
totalbytes
+
1023
)
//
1024
)
if
totaljobs
!=
len
(
users
):
line
+=
' (
%
d jobs)'
%
totaljobs
if
len
(
users
)
==
1
:
line
=
line
+
' for
%
s'
%
(
users
.
keys
()[
0
],)
line
+=
' for
%
s'
%
(
users
.
keys
()[
0
],)
else
:
line
=
line
+
' for
%
d users'
%
len
(
users
)
line
+=
' for
%
d users'
%
len
(
users
)
if
userseen
:
if
aheadjobs
==
0
:
line
=
line
+
' (
%
s first)'
%
thisuser
line
+=
' (
%
s first)'
%
thisuser
else
:
line
=
line
+
' (
%
d K before
%
s)'
%
(
(
aheadbytes
+
1023
)
//
1024
,
thisuser
)
line
+=
' (
%
d K before
%
s)'
%
(
(
aheadbytes
+
1023
)
//
1024
,
thisuser
)
lines
.
append
(
line
)
#
sts
=
pipe
.
close
()
if
sts
:
lines
.
append
(
'lpq exit status
%
r'
%
(
sts
,))
return
string
.
joinfields
(
lines
,
': '
)
return
': '
.
join
(
lines
)
if
__name__
==
"__main__"
:
try
:
...
...
Demo/scripts/newslist.py
Dosyayı görüntüle @
393c8232
...
...
@@ -128,7 +128,7 @@ def makeleaf(tree,path):
j
=
path
[
0
]
l
=
len
(
path
)
if
not
tree
.
has_key
(
j
)
:
if
j
not
in
tree
:
tree
[
j
]
=
{}
if
l
==
1
:
tree
[
j
][
'.'
]
=
'.'
...
...
Demo/scripts/queens.py
Dosyayı görüntüle @
393c8232
...
...
@@ -19,8 +19,8 @@ class Queens:
def
reset
(
self
):
n
=
self
.
n
self
.
y
=
[
None
]
*
n
# Where is the queen in column x
self
.
row
=
[
0
]
*
n
# Is row[y] safe?
self
.
y
=
[
None
]
*
n
# Where is the queen in column x
self
.
row
=
[
0
]
*
n
# Is row[y] safe?
self
.
up
=
[
0
]
*
(
2
*
n
-
1
)
# Is upward diagonal[x-y] safe?
self
.
down
=
[
0
]
*
(
2
*
n
-
1
)
# Is downward diagonal[x+y] safe?
self
.
nfound
=
0
# Instrumentation
...
...
@@ -50,7 +50,7 @@ class Queens:
self
.
up
[
x
-
y
]
=
0
self
.
down
[
x
+
y
]
=
0
silent
=
0
# If
set
, count solutions only
silent
=
0
# If
true
, count solutions only
def
display
(
self
):
self
.
nfound
=
self
.
nfound
+
1
...
...
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