##// 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 1 #!/usr/bin/env python
2 2 """Test the running system for features availability. Exit with zero
3 3 if all features are there, non-zero otherwise.
4 4 """
5 5 import optparse
6 6 import os
7 7 import sys
8 8 import tempfile
9 9
10 10 def has_symlink():
11 11 return hasattr(os, "symlink")
12 12
13 13 def has_fifo():
14 14 return hasattr(os, "mkfifo")
15 15
16 16 def has_executablebit():
17 17 fd, path = tempfile.mkstemp()
18 18 os.close(fd)
19 19 try:
20 20 s = os.lstat(path).st_mode
21 21 os.chmod(path, s | 0100)
22 22 return (os.lstat(path).st_mode & 0100 != 0)
23 23 finally:
24 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 35 checks = {
27 36 "symlink": (has_symlink, "symbolic links"),
28 37 "fifo": (has_fifo, "named pipes"),
29 38 "execbit": (has_executablebit, "executable bit"),
39 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
30 40 }
31 41
32 42 def list_features():
33 43 for name, feature in checks.iteritems():
34 44 desc = feature[1]
35 45 print name + ':', desc
36 46
37 47 parser = optparse.OptionParser("%prog [options] [features]")
38 48 parser.add_option("--list-features", action="store_true",
39 49 help="list available features")
40 50 parser.add_option("-q", "--quiet", action="store_true",
41 51 help="check features silently")
42 52
43 53 if __name__ == '__main__':
44 54 options, args = parser.parse_args()
45 55 if options.list_features:
46 56 list_features()
47 57 sys.exit(0)
48 58
49 59 quiet = options.quiet
50 60
51 61 failures = 0
52 62
53 63 def error(msg):
54 64 global failures
55 65 if not quiet:
56 66 sys.stderr.write(msg + '\n')
57 67 failures += 1
58 68
59 69 for feature in args:
60 70 if feature not in checks:
61 71 error('hghave: unknown feature: ' + feature)
62 72 continue
63 73
64 74 check, desc = checks[feature]
65 75 if not check():
66 76 error('hghave: missing feature: ' + desc)
67 77
68 78 if failures != 0:
69 79 sys.exit(1)
70 80
71 81
General Comments 0
You need to be logged in to leave comments. Login now