From 5378d5c485f8204630ac0e7db3276d3a852b4317 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 18 Dec 1991 13:38:27 +0000 Subject: [PATCH] Initial revision --- Tools/scripts/checkpyc.py | 69 +++++++++++++++++++++++++++++++++++++++ Tools/scripts/copytime.py | 25 ++++++++++++++ 2 files changed, 94 insertions(+) create mode 100755 Tools/scripts/checkpyc.py create mode 100755 Tools/scripts/copytime.py diff --git a/Tools/scripts/checkpyc.py b/Tools/scripts/checkpyc.py new file mode 100755 index 00000000000..152fb1d2b66 --- /dev/null +++ b/Tools/scripts/checkpyc.py @@ -0,0 +1,69 @@ +# Check that all ".pyc" files exist and are up-to-date +# Uses module 'posix' + +import sys +import posix +import path +from stat import ST_MTIME + +def main(): + silent = 0 + verbose = 0 + if sys.argv[1:]: + if sys.argv[1] = '-v': + verbose = 1 + elif sys.argv[1] = '-s': + silent = 1 + MAGIC = '\0\0\0\0' + try: + if sys.version[:5] >= '0.9.4': + MAGIC = '\224\224\224\0' + except: + pass + if not silent: + print 'Using MAGIC word', `MAGIC` + for dirname in sys.path: + try: + names = posix.listdir(dirname) + except posix.error: + print 'Cannot list directory', `dirname` + continue + if not silent: + print 'Checking', `dirname`, '...' + names.sort() + for name in names: + if name[-3:] = '.py': + name = path.join(dirname, name) + try: + st = posix.stat(name) + except posix.error: + print 'Cannot stat', `name` + continue + if verbose: + print 'Check', `name`, '...' + name_c = name + 'c' + try: + f = open(name_c, 'r') + except IOError: + print 'Cannot open', `name_c` + continue + magic_str = f.read(4) + mtime_str = f.read(4) + f.close() + if magic_str <> MAGIC: + print 'Bad MAGIC word in ".pyc" file', + print `name_c` + continue + mtime = get_long(mtime_str) + if mtime = 0 or mtime = -1: + print 'Bad ".pyc" file', `name_c` + elif mtime <> st[ST_MTIME]: + print 'Out-of-date ".pyc" file', + print `name_c` + +def get_long(s): + if len(s) <> 4: + return -1 + return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24) + +main() diff --git a/Tools/scripts/copytime.py b/Tools/scripts/copytime.py new file mode 100755 index 00000000000..a288c09c3f1 --- /dev/null +++ b/Tools/scripts/copytime.py @@ -0,0 +1,25 @@ +#! /usr/local/python + +# Copy one file's atime and mtime to another + +import sys +import posix +from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8 + +def main(): + if len(sys.argv) <> 3: + sys.stderr.write('usage: copytime source destination\n') + sys.exit(2) + file1, file2 = sys.argv[1], sys.argv[2] + try: + stat1 = posix.stat(file1) + except posix.error: + sys.stderr.write(file1 + ': cannot stat\n') + sys.exit(1) + try: + posix.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME])) + except posix.error: + sys.stderr.write(file2 + ': cannot change time\n') + sys.exit(2) + +main()