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