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