diff options
author | Guido van Rossum <guido@python.org> | 1992-03-30 11:13:59 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-03-30 11:13:59 (GMT) |
commit | e7b88e7402b3683afeec3ed602dd53288772991c (patch) | |
tree | 3f31c12fc6504ec423ba944312b3c7b364552ce8 /Tools | |
parent | b2ac8092a8f32de529675e14f3ba5c1f6ef06737 (diff) | |
download | cpython-e7b88e7402b3683afeec3ed602dd53288772991c.zip cpython-e7b88e7402b3683afeec3ed602dd53288772991c.tar.gz cpython-e7b88e7402b3683afeec3ed602dd53288772991c.tar.bz2 |
change posix to os
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/linktree.py | 34 | ||||
-rwxr-xr-x | Tools/scripts/lll.py | 14 | ||||
-rwxr-xr-x | Tools/scripts/mkreal.py | 37 | ||||
-rwxr-xr-x | Tools/scripts/which.py | 12 | ||||
-rwxr-xr-x | Tools/scripts/xxci.py | 32 |
5 files changed, 64 insertions, 65 deletions
diff --git a/Tools/scripts/linktree.py b/Tools/scripts/linktree.py index 5a66507..cfe7547 100755 --- a/Tools/scripts/linktree.py +++ b/Tools/scripts/linktree.py @@ -10,7 +10,7 @@ # # usage: mklinks oldtree newtree -import sys, posix, path +import sys, os LINK = '.LINK' # Name of special symlink at the top. @@ -27,18 +27,18 @@ def main(): else: link = LINK link_may_fail = 0 - if not path.isdir(oldtree): + if not os.path.isdir(oldtree): print oldtree + ': not a directory' return 1 try: - posix.mkdir(newtree, 0777) - except posix.error, msg: + os.mkdir(newtree, 0777) + except os.error, msg: print newtree + ': cannot mkdir:', msg return 1 - linkname = path.cat(newtree, link) + linkname = os.path.join(newtree, link) try: - posix.symlink(path.cat('..', oldtree), linkname) - except posix.error, msg: + os.symlink(os.path.join(os.pardir, oldtree), linkname) + except os.error, msg: if not link_may_fail: print linkname + ': cannot symlink:', msg return 1 @@ -50,27 +50,27 @@ def main(): def linknames(old, new, link): if debug: print 'linknames', (old, new, link) try: - names = posix.listdir(old) - except posix.error, msg: + names = os.listdir(old) + except os.error, msg: print old + ': warning: cannot listdir:', msg return for name in names: - if name not in ('.', '..'): - oldname = path.cat(old, name) - linkname = path.cat(link, name) - newname = path.cat(new, name) + if name not in (os.curdir, os.pardir): + oldname = os.path.join(old, name) + linkname = os.path.join(link, name) + newname = os.path.join(new, name) 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: - posix.mkdir(newname, 0777) + os.mkdir(newname, 0777) ok = 1 except: print newname + ': warning: cannot mkdir:', msg ok = 0 if ok: - linkname = path.cat('..', linkname) + linkname = os.path.join(os.pardir, linkname) linknames(oldname, newname, linkname) else: - posix.symlink(linkname, newname) + os.symlink(linkname, newname) sys.exit(main()) diff --git a/Tools/scripts/lll.py b/Tools/scripts/lll.py index 509936d..6dd68ba 100755 --- a/Tools/scripts/lll.py +++ b/Tools/scripts/lll.py @@ -5,17 +5,17 @@ # No recursion. # (This is a totally different program from "findsymlinks.py"!) -import sys, posix, path +import sys, os def lll(dirname): - for name in posix.listdir(dirname): - if name not in ['.', '..']: - full = path.join(dirname, name) - if path.islink(full): - print name, '->', posix.readlink(full) + for name in os.listdir(dirname): + if name not in (os.curdir, os.pardir): + full = os.path.join(dirname, name) + if os.path.islink(full): + print name, '->', os.readlink(full) args = sys.argv[1:] -if not args: args = ['.'] +if not args: args = [os.curdir] first = 1 for arg in args: if len(args) > 1: diff --git a/Tools/scripts/mkreal.py b/Tools/scripts/mkreal.py index b72c2e5..e01b35d 100755 --- a/Tools/scripts/mkreal.py +++ b/Tools/scripts/mkreal.py @@ -5,58 +5,57 @@ # turn a symlink to a directory into a real directory import sys -import posix -import path +import os from stat import * -join = path.join +join = os.path.join error = 'mkreal error' BUFSIZE = 32*1024 def mkrealfile(name): - st = posix.stat(name) # Get the mode + st = os.stat(name) # Get the 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 - posix.unlink(name) + os.unlink(name) f_out = open(name, 'w') while 1: buf = f_in.read(BUFSIZE) if not buf: break f_out.write(buf) del f_out # Flush data to disk before changing mode - posix.chmod(name, mode) + os.chmod(name, mode) def mkrealdir(name): - st = posix.stat(name) # Get the mode + st = os.stat(name) # Get the mode mode = S_IMODE(st[ST_MODE]) - linkto = posix.readlink(name) - files = posix.listdir(name) - posix.unlink(name) - posix.mkdir(name, mode) - posix.chmod(name, mode) - linkto = join('..', linkto) + linkto = os.readlink(name) + files = os.listdir(name) + os.unlink(name) + os.mkdir(name, mode) + os.chmod(name, mode) + linkto = join(os.pardir, linkto) # for file in files: - if file not in ('.', '..'): - posix.symlink(join(linkto, file), join(name, file)) + if file not in (os.curdir, os.pardir): + os.symlink(join(linkto, file), join(name, file)) def main(): sys.stdout = sys.stderr - progname = path.basename(sys.argv[0]) + progname = os.path.basename(sys.argv[0]) args = sys.argv[1:] if not args: print 'usage:', progname, 'path ...' sys.exit(2) status = 0 for name in args: - if not path.islink(name): + if not os.path.islink(name): print progname+':', name+':', 'not a symlink' status = 1 else: - if path.isdir(name): + if os.path.isdir(name): mkrealdir(name) else: mkrealfile(name) diff --git a/Tools/scripts/which.py b/Tools/scripts/which.py index 94c7556..d3186f4 100755 --- a/Tools/scripts/which.py +++ b/Tools/scripts/which.py @@ -4,13 +4,13 @@ # On stderr, near and total misses are reported. # '-l<flags>' argument adds ls -l<flags> of each file found. -import sys, posix, string, path +import sys, os, string from stat import * def msg(str): sys.stderr.write(str + '\n') -pathlist = string.splitfields(posix.environ['PATH'], ':') +pathlist = string.splitfields(os.environ['PATH'], ':') sts = 0 longlist = '' @@ -22,10 +22,10 @@ if sys.argv[1:] and sys.argv[1][:2] == '-l': for prog in sys.argv[1:]: ident = () for dir in pathlist: - file = path.join(dir, prog) + file = os.path.join(dir, prog) try: - st = posix.stat(file) - except posix.error: + st = os.stat(file) + except os.error: continue if not S_ISREG(st[ST_MODE]): msg(file + ': not a disk file') @@ -44,7 +44,7 @@ for prog in sys.argv[1:]: else: msg(file + ': not executable') if longlist: - sts = posix.system('ls ' + longlist + ' ' + file) + sts = os.system('ls ' + longlist + ' ' + file) if sts: msg('"ls -l" exit status: ' + `sts`) if not ident: msg(prog + ': not found') diff --git a/Tools/scripts/xxci.py b/Tools/scripts/xxci.py index 2cb1ead..aef3234 100755 --- a/Tools/scripts/xxci.py +++ b/Tools/scripts/xxci.py @@ -6,9 +6,8 @@ # check in files for which rcsdiff returns nonzero exit status import sys -import posix +import os from stat import * -import path import commands import fnmatch import string @@ -23,7 +22,7 @@ def getargs(): return args print 'No arguments, checking almost *, in "ls -t" order' list = [] - for file in posix.listdir('.'): + for file in os.listdir(os.curdir): if not skipfile(file): list.append((getmtime(file), file)) list.sort() @@ -37,9 +36,9 @@ def getargs(): def getmtime(file): try: - st = posix.stat(file) + st = os.stat(file) return st[ST_MTIME] - except posix.error: + except os.error: return -1 badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core'] @@ -65,8 +64,8 @@ def skipfile(file): for p in ignore: if fnmatch.fnmatch(file, p): return 1 try: - st = posix.lstat(file) - except posix.error: + st = os.lstat(file) + except os.error: return 1 # Doesn't exist -- skip it # Skip non-plain files. if not S_ISREG(st[ST_MODE]): return 1 @@ -94,18 +93,19 @@ def go(args): for file in args: print file + ':' if differing(file): - sts = posix.system('rcsdiff ' + file) # ignored + showdiffs(file) if askyesno('Check in ' + file + ' ? '): - sts = posix.system('rcs -l ' + file) # ignored - sts = posix.system('ci -l ' + file) + sts = os.system('rcs -l ' + file) # ignored + sts = os.system('ci -l ' + file) def differing(file): - try: - this = open(file, 'r').read() - that = posix.popen('co -p '+file+' 2>/dev/null', 'r').read() - return this <> that - except: - return 1 + cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file + sts = os.system(cmd) + return sts != 0 + +def showdiffs(file): + cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}' + sts = os.system(cmd) def askyesno(prompt): s = raw_input(prompt) |