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