Skip to content

Commit e7b88e7

Browse files
committed
change posix to os
1 parent b2ac809 commit e7b88e7

5 files changed

Lines changed: 64 additions & 65 deletions

File tree

‎Tools/scripts/linktree.py‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# usage: mklinks oldtree newtree
1212

13-
import sys, posix, path
13+
import sys, os
1414

1515
LINK = '.LINK' # Name of special symlink at the top.
1616

@@ -27,18 +27,18 @@ def main():
2727
else:
2828
link = LINK
2929
link_may_fail = 0
30-
if not path.isdir(oldtree):
30+
if not os.path.isdir(oldtree):
3131
print oldtree + ': not a directory'
3232
return 1
3333
try:
34-
posix.mkdir(newtree, 0777)
35-
except posix.error, msg:
34+
os.mkdir(newtree, 0777)
35+
except os.error, msg:
3636
print newtree + ': cannot mkdir:', msg
3737
return 1
38-
linkname = path.cat(newtree, link)
38+
linkname = os.path.join(newtree, link)
3939
try:
40-
posix.symlink(path.cat('..', oldtree), linkname)
41-
except posix.error, msg:
40+
os.symlink(os.path.join(os.pardir, oldtree), linkname)
41+
except os.error, msg:
4242
if not link_may_fail:
4343
print linkname + ': cannot symlink:', msg
4444
return 1
@@ -50,27 +50,27 @@ def main():
5050
def linknames(old, new, link):
5151
if debug: print 'linknames', (old, new, link)
5252
try:
53-
names = posix.listdir(old)
54-
except posix.error, msg:
53+
names = os.listdir(old)
54+
except os.error, msg:
5555
print old + ': warning: cannot listdir:', msg
5656
return
5757
for name in names:
58-
if name not in ('.', '..'):
59-
oldname = path.cat(old, name)
60-
linkname = path.cat(link, name)
61-
newname = path.cat(new, name)
58+
if name not in (os.curdir, os.pardir):
59+
oldname = os.path.join(old, name)
60+
linkname = os.path.join(link, name)
61+
newname = os.path.join(new, name)
6262
if debug > 1: print oldname, newname, linkname
63-
if path.isdir(oldname) and not path.islink(oldname):
63+
if os.path.isdir(oldname) and not os.path.islink(oldname):
6464
try:
65-
posix.mkdir(newname, 0777)
65+
os.mkdir(newname, 0777)
6666
ok = 1
6767
except:
6868
print newname + ': warning: cannot mkdir:', msg
6969
ok = 0
7070
if ok:
71-
linkname = path.cat('..', linkname)
71+
linkname = os.path.join(os.pardir, linkname)
7272
linknames(oldname, newname, linkname)
7373
else:
74-
posix.symlink(linkname, newname)
74+
os.symlink(linkname, newname)
7575

7676
sys.exit(main())

‎Tools/scripts/lll.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
# No recursion.
66
# (This is a totally different program from "findsymlinks.py"!)
77

8-
import sys, posix, path
8+
import sys, os
99

1010
def lll(dirname):
11-
for name in posix.listdir(dirname):
12-
if name not in ['.', '..']:
13-
full = path.join(dirname, name)
14-
if path.islink(full):
15-
print name, '->', posix.readlink(full)
11+
for name in os.listdir(dirname):
12+
if name not in (os.curdir, os.pardir):
13+
full = os.path.join(dirname, name)
14+
if os.path.islink(full):
15+
print name, '->', os.readlink(full)
1616

1717
args = sys.argv[1:]
18-
if not args: args = ['.']
18+
if not args: args = [os.curdir]
1919
first = 1
2020
for arg in args:
2121
if len(args) > 1:

‎Tools/scripts/mkreal.py‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@
55
# turn a symlink to a directory into a real directory
66

77
import sys
8-
import posix
9-
import path
8+
import os
109
from stat import *
1110

12-
join = path.join
11+
join = os.path.join
1312

1413
error = 'mkreal error'
1514

1615
BUFSIZE = 32*1024
1716

1817
def mkrealfile(name):
19-
st = posix.stat(name) # Get the mode
18+
st = os.stat(name) # Get the mode
2019
mode = S_IMODE(st[ST_MODE])
21-
linkto = posix.readlink(name) # Make sure again it's a symlink
20+
linkto = os.readlink(name) # Make sure again it's a symlink
2221
f_in = open(name, 'r') # This ensures it's a file
23-
posix.unlink(name)
22+
os.unlink(name)
2423
f_out = open(name, 'w')
2524
while 1:
2625
buf = f_in.read(BUFSIZE)
2726
if not buf: break
2827
f_out.write(buf)
2928
del f_out # Flush data to disk before changing mode
30-
posix.chmod(name, mode)
29+
os.chmod(name, mode)
3130

3231
def mkrealdir(name):
33-
st = posix.stat(name) # Get the mode
32+
st = os.stat(name) # Get the mode
3433
mode = S_IMODE(st[ST_MODE])
35-
linkto = posix.readlink(name)
36-
files = posix.listdir(name)
37-
posix.unlink(name)
38-
posix.mkdir(name, mode)
39-
posix.chmod(name, mode)
40-
linkto = join('..', linkto)
34+
linkto = os.readlink(name)
35+
files = os.listdir(name)
36+
os.unlink(name)
37+
os.mkdir(name, mode)
38+
os.chmod(name, mode)
39+
linkto = join(os.pardir, linkto)
4140
#
4241
for file in files:
43-
if file not in ('.', '..'):
44-
posix.symlink(join(linkto, file), join(name, file))
42+
if file not in (os.curdir, os.pardir):
43+
os.symlink(join(linkto, file), join(name, file))
4544

4645
def main():
4746
sys.stdout = sys.stderr
48-
progname = path.basename(sys.argv[0])
47+
progname = os.path.basename(sys.argv[0])
4948
args = sys.argv[1:]
5049
if not args:
5150
print 'usage:', progname, 'path ...'
5251
sys.exit(2)
5352
status = 0
5453
for name in args:
55-
if not path.islink(name):
54+
if not os.path.islink(name):
5655
print progname+':', name+':', 'not a symlink'
5756
status = 1
5857
else:
59-
if path.isdir(name):
58+
if os.path.isdir(name):
6059
mkrealdir(name)
6160
else:
6261
mkrealfile(name)

‎Tools/scripts/which.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
# On stderr, near and total misses are reported.
55
# '-l<flags>' argument adds ls -l<flags> of each file found.
66

7-
import sys, posix, string, path
7+
import sys, os, string
88
from stat import *
99

1010
def msg(str):
1111
sys.stderr.write(str + '\n')
1212

13-
pathlist = string.splitfields(posix.environ['PATH'], ':')
13+
pathlist = string.splitfields(os.environ['PATH'], ':')
1414

1515
sts = 0
1616
longlist = ''
@@ -22,10 +22,10 @@ def msg(str):
2222
for prog in sys.argv[1:]:
2323
ident = ()
2424
for dir in pathlist:
25-
file = path.join(dir, prog)
25+
file = os.path.join(dir, prog)
2626
try:
27-
st = posix.stat(file)
28-
except posix.error:
27+
st = os.stat(file)
28+
except os.error:
2929
continue
3030
if not S_ISREG(st[ST_MODE]):
3131
msg(file + ': not a disk file')
@@ -44,7 +44,7 @@ def msg(str):
4444
else:
4545
msg(file + ': not executable')
4646
if longlist:
47-
sts = posix.system('ls ' + longlist + ' ' + file)
47+
sts = os.system('ls ' + longlist + ' ' + file)
4848
if sts: msg('"ls -l" exit status: ' + `sts`)
4949
if not ident:
5050
msg(prog + ': not found')

‎Tools/scripts/xxci.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
# check in files for which rcsdiff returns nonzero exit status
77

88
import sys
9-
import posix
9+
import os
1010
from stat import *
11-
import path
1211
import commands
1312
import fnmatch
1413
import string
@@ -23,7 +22,7 @@ def getargs():
2322
return args
2423
print 'No arguments, checking almost *, in "ls -t" order'
2524
list = []
26-
for file in posix.listdir('.'):
25+
for file in os.listdir(os.curdir):
2726
if not skipfile(file):
2827
list.append((getmtime(file), file))
2928
list.sort()
@@ -37,9 +36,9 @@ def getargs():
3736

3837
def getmtime(file):
3938
try:
40-
st = posix.stat(file)
39+
st = os.stat(file)
4140
return st[ST_MTIME]
42-
except posix.error:
41+
except os.error:
4342
return -1
4443

4544
badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
@@ -65,8 +64,8 @@ def skipfile(file):
6564
for p in ignore:
6665
if fnmatch.fnmatch(file, p): return 1
6766
try:
68-
st = posix.lstat(file)
69-
except posix.error:
67+
st = os.lstat(file)
68+
except os.error:
7069
return 1 # Doesn't exist -- skip it
7170
# Skip non-plain files.
7271
if not S_ISREG(st[ST_MODE]): return 1
@@ -94,18 +93,19 @@ def go(args):
9493
for file in args:
9594
print file + ':'
9695
if differing(file):
97-
sts = posix.system('rcsdiff ' + file) # ignored
96+
showdiffs(file)
9897
if askyesno('Check in ' + file + ' ? '):
99-
sts = posix.system('rcs -l ' + file) # ignored
100-
sts = posix.system('ci -l ' + file)
98+
sts = os.system('rcs -l ' + file) # ignored
99+
sts = os.system('ci -l ' + file)
101100

102101
def differing(file):
103-
try:
104-
this = open(file, 'r').read()
105-
that = posix.popen('co -p '+file+' 2>/dev/null', 'r').read()
106-
return this <> that
107-
except:
108-
return 1
102+
cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
103+
sts = os.system(cmd)
104+
return sts != 0
105+
106+
def showdiffs(file):
107+
cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
108+
sts = os.system(cmd)
109109

110110
def askyesno(prompt):
111111
s = raw_input(prompt)

0 commit comments

Comments
 (0)