posix -> os

This commit is contained in:
Guido van Rossum 1992-03-30 11:15:26 +00:00
parent 391b8b7dee
commit 9a6757dade
3 changed files with 17 additions and 18 deletions

View File

@ -6,15 +6,15 @@
# #
# Options -[amc] select atime, mtime (default) or ctime as age. # Options -[amc] select atime, mtime (default) or ctime as age.
import sys, posix, time import sys, os, time
import string import string
from stat import * from stat import *
# Use lstat() to stat files if it exists, else stat() # Use lstat() to stat files if it exists, else stat()
try: try:
statfunc = posix.lstat statfunc = os.lstat
except NameError: except AttributeError:
statfunc = posix.stat statfunc = os.stat
# Parse options # Parse options
if sys.argv[1] == '-m': if sys.argv[1] == '-m':
@ -42,7 +42,7 @@ for file in sys.argv[1:]:
for file in sys.argv[1:]: for file in sys.argv[1:]:
try: try:
st = statfunc(file) st = statfunc(file)
except posix.error, msg: except os.error, msg:
sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n') sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n')
status = 1 status = 1
st = () st = ()

View File

@ -1,9 +1,8 @@
# Check that all ".pyc" files exist and are up-to-date # Check that all ".pyc" files exist and are up-to-date
# Uses module 'posix' # Uses module 'os'
import sys import sys
import posix import os
import path
from stat import ST_MTIME from stat import ST_MTIME
def main(): def main():
@ -24,8 +23,8 @@ def main():
print 'Using MAGIC word', `MAGIC` print 'Using MAGIC word', `MAGIC`
for dirname in sys.path: for dirname in sys.path:
try: try:
names = posix.listdir(dirname) names = os.listdir(dirname)
except posix.error: except os.error:
print 'Cannot list directory', `dirname` print 'Cannot list directory', `dirname`
continue continue
if not silent: if not silent:
@ -33,10 +32,10 @@ def main():
names.sort() names.sort()
for name in names: for name in names:
if name[-3:] == '.py': if name[-3:] == '.py':
name = path.join(dirname, name) name = os.path.join(dirname, name)
try: try:
st = posix.stat(name) st = os.stat(name)
except posix.error: except os.error:
print 'Cannot stat', `name` print 'Cannot stat', `name`
continue continue
if verbose: if verbose:

View File

@ -3,7 +3,7 @@
# Copy one file's atime and mtime to another # Copy one file's atime and mtime to another
import sys import sys
import posix import os
from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8 from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8
def main(): def main():
@ -12,13 +12,13 @@ def main():
sys.exit(2) sys.exit(2)
file1, file2 = sys.argv[1], sys.argv[2] file1, file2 = sys.argv[1], sys.argv[2]
try: try:
stat1 = posix.stat(file1) stat1 = os.stat(file1)
except posix.error: except os.error:
sys.stderr.write(file1 + ': cannot stat\n') sys.stderr.write(file1 + ': cannot stat\n')
sys.exit(1) sys.exit(1)
try: try:
posix.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME])) os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
except posix.error: except os.error:
sys.stderr.write(file2 + ': cannot change time\n') sys.stderr.write(file2 + ': cannot change time\n')
sys.exit(2) sys.exit(2)