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