##// END OF EJS Templates
hghave: detect executable permission availability.
Patrick Mezard -
r5072:7e2385a3 default
parent child Browse files
Show More
@@ -1,59 +1,71 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.
3 if all features are there, non-zero otherwise.
4 """
4 """
5 import optparse
5 import optparse
6 import os
6 import os
7 import sys
7 import sys
8 import tempfile
8
9
9 def has_symlink():
10 def has_symlink():
10 return hasattr(os, "symlink")
11 return hasattr(os, "symlink")
11
12
12 def has_fifo():
13 def has_fifo():
13 return hasattr(os, "mkfifo")
14 return hasattr(os, "mkfifo")
14
15
16 def has_executablebit():
17 fd, path = tempfile.mkstemp()
18 os.close(fd)
19 try:
20 s = os.lstat(path).st_mode
21 os.chmod(path, s | 0100)
22 return (os.lstat(path).st_mode & 0100 != 0)
23 finally:
24 os.remove(path)
25
15 checks = {
26 checks = {
16 "symlink": (has_symlink, "symbolic links"),
27 "symlink": (has_symlink, "symbolic links"),
17 "fifo": (has_fifo, "named pipes"),
28 "fifo": (has_fifo, "named pipes"),
29 "execbit": (has_executablebit, "executable bit"),
18 }
30 }
19
31
20 def list_features():
32 def list_features():
21 for name, feature in checks.iteritems():
33 for name, feature in checks.iteritems():
22 desc = feature[1]
34 desc = feature[1]
23 print name + ':', desc
35 print name + ':', desc
24
36
25 parser = optparse.OptionParser("%prog [options] [features]")
37 parser = optparse.OptionParser("%prog [options] [features]")
26 parser.add_option("--list-features", action="store_true",
38 parser.add_option("--list-features", action="store_true",
27 help="list available features")
39 help="list available features")
28 parser.add_option("-q", "--quiet", action="store_true",
40 parser.add_option("-q", "--quiet", action="store_true",
29 help="check features silently")
41 help="check features silently")
30
42
31 if __name__ == '__main__':
43 if __name__ == '__main__':
32 options, args = parser.parse_args()
44 options, args = parser.parse_args()
33 if options.list_features:
45 if options.list_features:
34 list_features()
46 list_features()
35 sys.exit(0)
47 sys.exit(0)
36
48
37 quiet = options.quiet
49 quiet = options.quiet
38
50
39 failures = 0
51 failures = 0
40
52
41 def error(msg):
53 def error(msg):
42 global failures
54 global failures
43 if not quiet:
55 if not quiet:
44 sys.stderr.write(msg + '\n')
56 sys.stderr.write(msg + '\n')
45 failures += 1
57 failures += 1
46
58
47 for feature in args:
59 for feature in args:
48 if feature not in checks:
60 if feature not in checks:
49 error('hghave: unknown feature: ' + feature)
61 error('hghave: unknown feature: ' + feature)
50 continue
62 continue
51
63
52 check, desc = checks[feature]
64 check, desc = checks[feature]
53 if not check():
65 if not check():
54 error('hghave: missing feature: ' + desc)
66 error('hghave: missing feature: ' + desc)
55
67
56 if failures != 0:
68 if failures != 0:
57 sys.exit(1)
69 sys.exit(1)
58
70
59
71
General Comments 0
You need to be logged in to leave comments. Login now