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