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