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