Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5378d5c

Browse files
committed
Initial revision
1 parent bbf9434 commit 5378d5c

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Tools/scripts/checkpyc.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Check that all ".pyc" files exist and are up-to-date
2+
# Uses module 'posix'
3+
4+
import sys
5+
import posix
6+
import path
7+
from stat import ST_MTIME
8+
9+
def main():
10+
silent = 0
11+
verbose = 0
12+
if sys.argv[1:]:
13+
if sys.argv[1] = '-v':
14+
verbose = 1
15+
elif sys.argv[1] = '-s':
16+
silent = 1
17+
MAGIC = '\0\0\0\0'
18+
try:
19+
if sys.version[:5] >= '0.9.4':
20+
MAGIC = '\224\224\224\0'
21+
except:
22+
pass
23+
if not silent:
24+
print 'Using MAGIC word', `MAGIC`
25+
for dirname in sys.path:
26+
try:
27+
names = posix.listdir(dirname)
28+
except posix.error:
29+
print 'Cannot list directory', `dirname`
30+
continue
31+
if not silent:
32+
print 'Checking', `dirname`, '...'
33+
names.sort()
34+
for name in names:
35+
if name[-3:] = '.py':
36+
name = path.join(dirname, name)
37+
try:
38+
st = posix.stat(name)
39+
except posix.error:
40+
print 'Cannot stat', `name`
41+
continue
42+
if verbose:
43+
print 'Check', `name`, '...'
44+
name_c = name + 'c'
45+
try:
46+
f = open(name_c, 'r')
47+
except IOError:
48+
print 'Cannot open', `name_c`
49+
continue
50+
magic_str = f.read(4)
51+
mtime_str = f.read(4)
52+
f.close()
53+
if magic_str <> MAGIC:
54+
print 'Bad MAGIC word in ".pyc" file',
55+
print `name_c`
56+
continue
57+
mtime = get_long(mtime_str)
58+
if mtime = 0 or mtime = -1:
59+
print 'Bad ".pyc" file', `name_c`
60+
elif mtime <> st[ST_MTIME]:
61+
print 'Out-of-date ".pyc" file',
62+
print `name_c`
63+
64+
def get_long(s):
65+
if len(s) <> 4:
66+
return -1
67+
return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
68+
69+
main()

Tools/scripts/copytime.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/local/python
2+
3+
# Copy one file's atime and mtime to another
4+
5+
import sys
6+
import posix
7+
from stat import ST_ATIME, ST_MTIME # Really constants 7 and 8
8+
9+
def main():
10+
if len(sys.argv) <> 3:
11+
sys.stderr.write('usage: copytime source destination\n')
12+
sys.exit(2)
13+
file1, file2 = sys.argv[1], sys.argv[2]
14+
try:
15+
stat1 = posix.stat(file1)
16+
except posix.error:
17+
sys.stderr.write(file1 + ': cannot stat\n')
18+
sys.exit(1)
19+
try:
20+
posix.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
21+
except posix.error:
22+
sys.stderr.write(file2 + ': cannot change time\n')
23+
sys.exit(2)
24+
25+
main()

0 commit comments

Comments
 (0)