##// END OF EJS Templates
hghave: prefix temporary files with "hg-hghave-"
Patrick Mezard -
r5090:bf60e4bd default
parent child Browse files
Show More
@@ -1,88 +1,90 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 """Test the running system for features availability. Exit with zero
2 """Test the running system for features availability. Exit with zero
3 if all features are there, non-zero otherwise. If a feature name is
3 if all features are there, non-zero otherwise. If a feature name is
4 prefixed with "no-", the absence of feature is tested.
4 prefixed with "no-", the absence of feature is tested.
5 """
5 """
6 import optparse
6 import optparse
7 import os
7 import os
8 import sys
8 import sys
9 import tempfile
9 import tempfile
10
10
11 tempprefix = 'hg-hghave-'
12
11 def has_symlink():
13 def has_symlink():
12 return hasattr(os, "symlink")
14 return hasattr(os, "symlink")
13
15
14 def has_fifo():
16 def has_fifo():
15 return hasattr(os, "mkfifo")
17 return hasattr(os, "mkfifo")
16
18
17 def has_executablebit():
19 def has_executablebit():
18 fd, path = tempfile.mkstemp()
20 fd, path = tempfile.mkstemp(prefix=tempprefix)
19 os.close(fd)
21 os.close(fd)
20 try:
22 try:
21 s = os.lstat(path).st_mode
23 s = os.lstat(path).st_mode
22 os.chmod(path, s | 0100)
24 os.chmod(path, s | 0100)
23 return (os.lstat(path).st_mode & 0100 != 0)
25 return (os.lstat(path).st_mode & 0100 != 0)
24 finally:
26 finally:
25 os.remove(path)
27 os.remove(path)
26
28
27 def has_eol_in_paths():
29 def has_eol_in_paths():
28 try:
30 try:
29 fd, path = tempfile.mkstemp(suffix='\n\r')
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
30 os.close(fd)
32 os.close(fd)
31 os.remove(path)
33 os.remove(path)
32 return True
34 return True
33 except:
35 except:
34 return False
36 return False
35
37
36 checks = {
38 checks = {
37 "symlink": (has_symlink, "symbolic links"),
39 "symlink": (has_symlink, "symbolic links"),
38 "fifo": (has_fifo, "named pipes"),
40 "fifo": (has_fifo, "named pipes"),
39 "execbit": (has_executablebit, "executable bit"),
41 "execbit": (has_executablebit, "executable bit"),
40 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
42 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
41 }
43 }
42
44
43 def list_features():
45 def list_features():
44 for name, feature in checks.iteritems():
46 for name, feature in checks.iteritems():
45 desc = feature[1]
47 desc = feature[1]
46 print name + ':', desc
48 print name + ':', desc
47
49
48 parser = optparse.OptionParser("%prog [options] [features]")
50 parser = optparse.OptionParser("%prog [options] [features]")
49 parser.add_option("--list-features", action="store_true",
51 parser.add_option("--list-features", action="store_true",
50 help="list available features")
52 help="list available features")
51 parser.add_option("-q", "--quiet", action="store_true",
53 parser.add_option("-q", "--quiet", action="store_true",
52 help="check features silently")
54 help="check features silently")
53
55
54 if __name__ == '__main__':
56 if __name__ == '__main__':
55 options, args = parser.parse_args()
57 options, args = parser.parse_args()
56 if options.list_features:
58 if options.list_features:
57 list_features()
59 list_features()
58 sys.exit(0)
60 sys.exit(0)
59
61
60 quiet = options.quiet
62 quiet = options.quiet
61
63
62 failures = 0
64 failures = 0
63
65
64 def error(msg):
66 def error(msg):
65 global failures
67 global failures
66 if not quiet:
68 if not quiet:
67 sys.stderr.write(msg + '\n')
69 sys.stderr.write(msg + '\n')
68 failures += 1
70 failures += 1
69
71
70 for feature in args:
72 for feature in args:
71 negate = feature.startswith('no-')
73 negate = feature.startswith('no-')
72 if negate:
74 if negate:
73 feature = feature[3:]
75 feature = feature[3:]
74
76
75 if feature not in checks:
77 if feature not in checks:
76 error('hghave: unknown feature: ' + feature)
78 error('hghave: unknown feature: ' + feature)
77 continue
79 continue
78
80
79 check, desc = checks[feature]
81 check, desc = checks[feature]
80 if not negate and not check():
82 if not negate and not check():
81 error('hghave: missing feature: ' + desc)
83 error('hghave: missing feature: ' + desc)
82 elif negate and check():
84 elif negate and check():
83 error('hghave: unexpected feature: ' + desc)
85 error('hghave: unexpected feature: ' + desc)
84
86
85 if failures != 0:
87 if failures != 0:
86 sys.exit(1)
88 sys.exit(1)
87
89
88
90
General Comments 0
You need to be logged in to leave comments. Login now