mirror of
https://github.com/python/cpython.git
synced 2025-07-22 02:35:22 +00:00
change posix to os
This commit is contained in:
parent
b2ac8092a8
commit
e7b88e7402
5 changed files with 64 additions and 65 deletions
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# usage: mklinks oldtree newtree
|
# usage: mklinks oldtree newtree
|
||||||
|
|
||||||
import sys, posix, path
|
import sys, os
|
||||||
|
|
||||||
LINK = '.LINK' # Name of special symlink at the top.
|
LINK = '.LINK' # Name of special symlink at the top.
|
||||||
|
|
||||||
|
@ -27,18 +27,18 @@ def main():
|
||||||
else:
|
else:
|
||||||
link = LINK
|
link = LINK
|
||||||
link_may_fail = 0
|
link_may_fail = 0
|
||||||
if not path.isdir(oldtree):
|
if not os.path.isdir(oldtree):
|
||||||
print oldtree + ': not a directory'
|
print oldtree + ': not a directory'
|
||||||
return 1
|
return 1
|
||||||
try:
|
try:
|
||||||
posix.mkdir(newtree, 0777)
|
os.mkdir(newtree, 0777)
|
||||||
except posix.error, msg:
|
except os.error, msg:
|
||||||
print newtree + ': cannot mkdir:', msg
|
print newtree + ': cannot mkdir:', msg
|
||||||
return 1
|
return 1
|
||||||
linkname = path.cat(newtree, link)
|
linkname = os.path.join(newtree, link)
|
||||||
try:
|
try:
|
||||||
posix.symlink(path.cat('..', oldtree), linkname)
|
os.symlink(os.path.join(os.pardir, oldtree), linkname)
|
||||||
except posix.error, msg:
|
except os.error, msg:
|
||||||
if not link_may_fail:
|
if not link_may_fail:
|
||||||
print linkname + ': cannot symlink:', msg
|
print linkname + ': cannot symlink:', msg
|
||||||
return 1
|
return 1
|
||||||
|
@ -50,27 +50,27 @@ def main():
|
||||||
def linknames(old, new, link):
|
def linknames(old, new, link):
|
||||||
if debug: print 'linknames', (old, new, link)
|
if debug: print 'linknames', (old, new, link)
|
||||||
try:
|
try:
|
||||||
names = posix.listdir(old)
|
names = os.listdir(old)
|
||||||
except posix.error, msg:
|
except os.error, msg:
|
||||||
print old + ': warning: cannot listdir:', msg
|
print old + ': warning: cannot listdir:', msg
|
||||||
return
|
return
|
||||||
for name in names:
|
for name in names:
|
||||||
if name not in ('.', '..'):
|
if name not in (os.curdir, os.pardir):
|
||||||
oldname = path.cat(old, name)
|
oldname = os.path.join(old, name)
|
||||||
linkname = path.cat(link, name)
|
linkname = os.path.join(link, name)
|
||||||
newname = path.cat(new, name)
|
newname = os.path.join(new, name)
|
||||||
if debug > 1: print oldname, newname, linkname
|
if debug > 1: print oldname, newname, linkname
|
||||||
if path.isdir(oldname) and not path.islink(oldname):
|
if os.path.isdir(oldname) and not os.path.islink(oldname):
|
||||||
try:
|
try:
|
||||||
posix.mkdir(newname, 0777)
|
os.mkdir(newname, 0777)
|
||||||
ok = 1
|
ok = 1
|
||||||
except:
|
except:
|
||||||
print newname + ': warning: cannot mkdir:', msg
|
print newname + ': warning: cannot mkdir:', msg
|
||||||
ok = 0
|
ok = 0
|
||||||
if ok:
|
if ok:
|
||||||
linkname = path.cat('..', linkname)
|
linkname = os.path.join(os.pardir, linkname)
|
||||||
linknames(oldname, newname, linkname)
|
linknames(oldname, newname, linkname)
|
||||||
else:
|
else:
|
||||||
posix.symlink(linkname, newname)
|
os.symlink(linkname, newname)
|
||||||
|
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
|
@ -5,17 +5,17 @@
|
||||||
# No recursion.
|
# No recursion.
|
||||||
# (This is a totally different program from "findsymlinks.py"!)
|
# (This is a totally different program from "findsymlinks.py"!)
|
||||||
|
|
||||||
import sys, posix, path
|
import sys, os
|
||||||
|
|
||||||
def lll(dirname):
|
def lll(dirname):
|
||||||
for name in posix.listdir(dirname):
|
for name in os.listdir(dirname):
|
||||||
if name not in ['.', '..']:
|
if name not in (os.curdir, os.pardir):
|
||||||
full = path.join(dirname, name)
|
full = os.path.join(dirname, name)
|
||||||
if path.islink(full):
|
if os.path.islink(full):
|
||||||
print name, '->', posix.readlink(full)
|
print name, '->', os.readlink(full)
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if not args: args = ['.']
|
if not args: args = [os.curdir]
|
||||||
first = 1
|
first = 1
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
|
|
|
@ -5,58 +5,57 @@
|
||||||
# turn a symlink to a directory into a real directory
|
# turn a symlink to a directory into a real directory
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import posix
|
import os
|
||||||
import path
|
|
||||||
from stat import *
|
from stat import *
|
||||||
|
|
||||||
join = path.join
|
join = os.path.join
|
||||||
|
|
||||||
error = 'mkreal error'
|
error = 'mkreal error'
|
||||||
|
|
||||||
BUFSIZE = 32*1024
|
BUFSIZE = 32*1024
|
||||||
|
|
||||||
def mkrealfile(name):
|
def mkrealfile(name):
|
||||||
st = posix.stat(name) # Get the mode
|
st = os.stat(name) # Get the mode
|
||||||
mode = S_IMODE(st[ST_MODE])
|
mode = S_IMODE(st[ST_MODE])
|
||||||
linkto = posix.readlink(name) # Make sure again it's a symlink
|
linkto = os.readlink(name) # Make sure again it's a symlink
|
||||||
f_in = open(name, 'r') # This ensures it's a file
|
f_in = open(name, 'r') # This ensures it's a file
|
||||||
posix.unlink(name)
|
os.unlink(name)
|
||||||
f_out = open(name, 'w')
|
f_out = open(name, 'w')
|
||||||
while 1:
|
while 1:
|
||||||
buf = f_in.read(BUFSIZE)
|
buf = f_in.read(BUFSIZE)
|
||||||
if not buf: break
|
if not buf: break
|
||||||
f_out.write(buf)
|
f_out.write(buf)
|
||||||
del f_out # Flush data to disk before changing mode
|
del f_out # Flush data to disk before changing mode
|
||||||
posix.chmod(name, mode)
|
os.chmod(name, mode)
|
||||||
|
|
||||||
def mkrealdir(name):
|
def mkrealdir(name):
|
||||||
st = posix.stat(name) # Get the mode
|
st = os.stat(name) # Get the mode
|
||||||
mode = S_IMODE(st[ST_MODE])
|
mode = S_IMODE(st[ST_MODE])
|
||||||
linkto = posix.readlink(name)
|
linkto = os.readlink(name)
|
||||||
files = posix.listdir(name)
|
files = os.listdir(name)
|
||||||
posix.unlink(name)
|
os.unlink(name)
|
||||||
posix.mkdir(name, mode)
|
os.mkdir(name, mode)
|
||||||
posix.chmod(name, mode)
|
os.chmod(name, mode)
|
||||||
linkto = join('..', linkto)
|
linkto = join(os.pardir, linkto)
|
||||||
#
|
#
|
||||||
for file in files:
|
for file in files:
|
||||||
if file not in ('.', '..'):
|
if file not in (os.curdir, os.pardir):
|
||||||
posix.symlink(join(linkto, file), join(name, file))
|
os.symlink(join(linkto, file), join(name, file))
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
sys.stdout = sys.stderr
|
sys.stdout = sys.stderr
|
||||||
progname = path.basename(sys.argv[0])
|
progname = os.path.basename(sys.argv[0])
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if not args:
|
if not args:
|
||||||
print 'usage:', progname, 'path ...'
|
print 'usage:', progname, 'path ...'
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
status = 0
|
status = 0
|
||||||
for name in args:
|
for name in args:
|
||||||
if not path.islink(name):
|
if not os.path.islink(name):
|
||||||
print progname+':', name+':', 'not a symlink'
|
print progname+':', name+':', 'not a symlink'
|
||||||
status = 1
|
status = 1
|
||||||
else:
|
else:
|
||||||
if path.isdir(name):
|
if os.path.isdir(name):
|
||||||
mkrealdir(name)
|
mkrealdir(name)
|
||||||
else:
|
else:
|
||||||
mkrealfile(name)
|
mkrealfile(name)
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
# On stderr, near and total misses are reported.
|
# On stderr, near and total misses are reported.
|
||||||
# '-l<flags>' argument adds ls -l<flags> of each file found.
|
# '-l<flags>' argument adds ls -l<flags> of each file found.
|
||||||
|
|
||||||
import sys, posix, string, path
|
import sys, os, string
|
||||||
from stat import *
|
from stat import *
|
||||||
|
|
||||||
def msg(str):
|
def msg(str):
|
||||||
sys.stderr.write(str + '\n')
|
sys.stderr.write(str + '\n')
|
||||||
|
|
||||||
pathlist = string.splitfields(posix.environ['PATH'], ':')
|
pathlist = string.splitfields(os.environ['PATH'], ':')
|
||||||
|
|
||||||
sts = 0
|
sts = 0
|
||||||
longlist = ''
|
longlist = ''
|
||||||
|
@ -22,10 +22,10 @@ if sys.argv[1:] and sys.argv[1][:2] == '-l':
|
||||||
for prog in sys.argv[1:]:
|
for prog in sys.argv[1:]:
|
||||||
ident = ()
|
ident = ()
|
||||||
for dir in pathlist:
|
for dir in pathlist:
|
||||||
file = path.join(dir, prog)
|
file = os.path.join(dir, prog)
|
||||||
try:
|
try:
|
||||||
st = posix.stat(file)
|
st = os.stat(file)
|
||||||
except posix.error:
|
except os.error:
|
||||||
continue
|
continue
|
||||||
if not S_ISREG(st[ST_MODE]):
|
if not S_ISREG(st[ST_MODE]):
|
||||||
msg(file + ': not a disk file')
|
msg(file + ': not a disk file')
|
||||||
|
@ -44,7 +44,7 @@ for prog in sys.argv[1:]:
|
||||||
else:
|
else:
|
||||||
msg(file + ': not executable')
|
msg(file + ': not executable')
|
||||||
if longlist:
|
if longlist:
|
||||||
sts = posix.system('ls ' + longlist + ' ' + file)
|
sts = os.system('ls ' + longlist + ' ' + file)
|
||||||
if sts: msg('"ls -l" exit status: ' + `sts`)
|
if sts: msg('"ls -l" exit status: ' + `sts`)
|
||||||
if not ident:
|
if not ident:
|
||||||
msg(prog + ': not found')
|
msg(prog + ': not found')
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
# check in files for which rcsdiff returns nonzero exit status
|
# check in files for which rcsdiff returns nonzero exit status
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import posix
|
import os
|
||||||
from stat import *
|
from stat import *
|
||||||
import path
|
|
||||||
import commands
|
import commands
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import string
|
import string
|
||||||
|
@ -23,7 +22,7 @@ def getargs():
|
||||||
return args
|
return args
|
||||||
print 'No arguments, checking almost *, in "ls -t" order'
|
print 'No arguments, checking almost *, in "ls -t" order'
|
||||||
list = []
|
list = []
|
||||||
for file in posix.listdir('.'):
|
for file in os.listdir(os.curdir):
|
||||||
if not skipfile(file):
|
if not skipfile(file):
|
||||||
list.append((getmtime(file), file))
|
list.append((getmtime(file), file))
|
||||||
list.sort()
|
list.sort()
|
||||||
|
@ -37,9 +36,9 @@ def getargs():
|
||||||
|
|
||||||
def getmtime(file):
|
def getmtime(file):
|
||||||
try:
|
try:
|
||||||
st = posix.stat(file)
|
st = os.stat(file)
|
||||||
return st[ST_MTIME]
|
return st[ST_MTIME]
|
||||||
except posix.error:
|
except os.error:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
|
badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
|
||||||
|
@ -65,8 +64,8 @@ def skipfile(file):
|
||||||
for p in ignore:
|
for p in ignore:
|
||||||
if fnmatch.fnmatch(file, p): return 1
|
if fnmatch.fnmatch(file, p): return 1
|
||||||
try:
|
try:
|
||||||
st = posix.lstat(file)
|
st = os.lstat(file)
|
||||||
except posix.error:
|
except os.error:
|
||||||
return 1 # Doesn't exist -- skip it
|
return 1 # Doesn't exist -- skip it
|
||||||
# Skip non-plain files.
|
# Skip non-plain files.
|
||||||
if not S_ISREG(st[ST_MODE]): return 1
|
if not S_ISREG(st[ST_MODE]): return 1
|
||||||
|
@ -94,18 +93,19 @@ def go(args):
|
||||||
for file in args:
|
for file in args:
|
||||||
print file + ':'
|
print file + ':'
|
||||||
if differing(file):
|
if differing(file):
|
||||||
sts = posix.system('rcsdiff ' + file) # ignored
|
showdiffs(file)
|
||||||
if askyesno('Check in ' + file + ' ? '):
|
if askyesno('Check in ' + file + ' ? '):
|
||||||
sts = posix.system('rcs -l ' + file) # ignored
|
sts = os.system('rcs -l ' + file) # ignored
|
||||||
sts = posix.system('ci -l ' + file)
|
sts = os.system('ci -l ' + file)
|
||||||
|
|
||||||
def differing(file):
|
def differing(file):
|
||||||
try:
|
cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
|
||||||
this = open(file, 'r').read()
|
sts = os.system(cmd)
|
||||||
that = posix.popen('co -p '+file+' 2>/dev/null', 'r').read()
|
return sts != 0
|
||||||
return this <> that
|
|
||||||
except:
|
def showdiffs(file):
|
||||||
return 1
|
cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
|
||||||
|
sts = os.system(cmd)
|
||||||
|
|
||||||
def askyesno(prompt):
|
def askyesno(prompt):
|
||||||
s = raw_input(prompt)
|
s = raw_input(prompt)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue