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

Skip to content

Commit bff5bb3

Browse files
committed
Use fnmatch; read ".xxcign" for additional patterns to ignore.
1 parent dbd83aa commit bff5bb3

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

Tools/scripts/xxci.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import sys
99
import posix
10-
import stat
10+
from stat import *
1111
import path
1212
import commands
13+
import fnmatch
14+
import string
1315

1416
EXECMAGIC = '\001\140\000\010'
1517

@@ -19,34 +21,57 @@ def getargs():
1921
args = sys.argv[1:]
2022
if args:
2123
return args
22-
print 'No arguments, checking almost *'
24+
print 'No arguments, checking almost *, in "ls -t" order'
25+
list = []
2326
for file in posix.listdir('.'):
2427
if not skipfile(file):
25-
args.append(file)
26-
if not args:
28+
list.append((getmtime(file), file))
29+
list.sort()
30+
if not list:
2731
print 'Nothing to do -- exit 1'
2832
sys.exit(1)
29-
args.sort()
33+
list.sort()
34+
list.reverse()
35+
for mtime, file in list: args.append(file)
3036
return args
3137

38+
def getmtime(file):
39+
try:
40+
st = posix.stat(file)
41+
return st[ST_MTIME]
42+
except posix.error:
43+
return -1
44+
3245
badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
3346
badprefixes = ['.', ',', '@', '#', 'o.']
3447
badsuffixes = \
3548
['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
3649
'.pyc', '.elc']
37-
# XXX Should generalize even more to use fnmatch!
50+
51+
def setup():
52+
global ignore
53+
ignore = badnames[:]
54+
for p in badprefixes:
55+
ignore.append(p + '*')
56+
for p in badsuffixes:
57+
ignore.append('*' + p)
58+
try:
59+
f = open('.xxcign', 'r')
60+
except IOError:
61+
return
62+
ignore = ignore + string.split(f.read())
3863

3964
def skipfile(file):
40-
if file in badnames or \
41-
badprefix(file) or badsuffix(file) or \
42-
path.islink(file) or path.isdir(file):
43-
return 1
44-
# Skip huge files -- probably binaries.
65+
for p in ignore:
66+
if fnmatch.fnmatch(file, p): return 1
4567
try:
46-
st = posix.stat(file)
68+
st = posix.lstat(file)
4769
except posix.error:
4870
return 1 # Doesn't exist -- skip it
49-
if st[stat.ST_SIZE] >= MAXSIZE: return 1
71+
# Skip non-plain files.
72+
if not S_ISREG(st[ST_MODE]): return 1
73+
# Skip huge files -- probably binaries.
74+
if st[ST_SIZE] >= MAXSIZE: return 1
5075
# Skip executables
5176
try:
5277
data = open(file, 'r').read(len(EXECMAGIC))
@@ -86,4 +111,5 @@ def askyesno(prompt):
86111
s = raw_input(prompt)
87112
return s in ['y', 'yes']
88113

114+
setup()
89115
go(getargs())

0 commit comments

Comments
 (0)