Show More
@@ -1,275 +1,275 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, ignorestatus=False): |
|
14 | def matchoutput(cmd, regexp, ignorestatus=False): | |
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 | try: |
|
21 | try: | |
22 | ret = fh.close() |
|
22 | ret = fh.close() | |
23 | except IOError: |
|
23 | except IOError: | |
24 | # Happen in Windows test environment |
|
24 | # Happen in Windows test environment | |
25 | ret = 1 |
|
25 | ret = 1 | |
26 | return (ignorestatus or ret is None) and r.search(s) |
|
26 | return (ignorestatus or ret is None) and r.search(s) | |
27 |
|
27 | |||
28 | def has_baz(): |
|
28 | def has_baz(): | |
29 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') |
|
29 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') | |
30 |
|
30 | |||
31 | def has_bzr(): |
|
31 | def has_bzr(): | |
32 | try: |
|
32 | try: | |
33 | import bzrlib |
|
33 | import bzrlib | |
34 | return bzrlib.__doc__ != None |
|
34 | return bzrlib.__doc__ != None | |
35 | except ImportError: |
|
35 | except ImportError: | |
36 | return False |
|
36 | return False | |
37 |
|
37 | |||
38 | def has_bzr114(): |
|
38 | def has_bzr114(): | |
39 | try: |
|
39 | try: | |
40 | import bzrlib |
|
40 | import bzrlib | |
41 | return (bzrlib.__doc__ != None |
|
41 | return (bzrlib.__doc__ != None | |
42 | and bzrlib.version_info[:2] >= (1, 14)) |
|
42 | and bzrlib.version_info[:2] >= (1, 14)) | |
43 | except ImportError: |
|
43 | except ImportError: | |
44 | return False |
|
44 | return False | |
45 |
|
45 | |||
46 | def has_cvs(): |
|
46 | def has_cvs(): | |
47 | re = r'Concurrent Versions System.*?server' |
|
47 | re = r'Concurrent Versions System.*?server' | |
48 | return matchoutput('cvs --version 2>&1', re) |
|
48 | return matchoutput('cvs --version 2>&1', re) | |
49 |
|
49 | |||
50 | def has_darcs(): |
|
50 | def has_darcs(): | |
51 | return matchoutput('darcs --version', r'2\.[2-9]', True) |
|
51 | return matchoutput('darcs --version', r'2\.[2-9]', True) | |
52 |
|
52 | |||
53 | def has_mtn(): |
|
53 | def has_mtn(): | |
54 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( |
|
54 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( | |
55 | 'mtn --version', r'monotone 0\.(\d|[12]\d|3[01])[^\d]', True) |
|
55 | 'mtn --version', r'monotone 0\.(\d|[12]\d|3[01])[^\d]', True) | |
56 |
|
56 | |||
57 | def has_eol_in_paths(): |
|
57 | def has_eol_in_paths(): | |
58 | try: |
|
58 | try: | |
59 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
|
59 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | |
60 | os.close(fd) |
|
60 | os.close(fd) | |
61 | os.remove(path) |
|
61 | os.remove(path) | |
62 | return True |
|
62 | return True | |
63 | except: |
|
63 | except: | |
64 | return False |
|
64 | return False | |
65 |
|
65 | |||
66 | def has_executablebit(): |
|
66 | def has_executablebit(): | |
67 | fd, path = tempfile.mkstemp(prefix=tempprefix) |
|
67 | fd, path = tempfile.mkstemp(prefix=tempprefix) | |
68 | os.close(fd) |
|
68 | os.close(fd) | |
69 | try: |
|
69 | try: | |
70 | s = os.lstat(path).st_mode |
|
70 | s = os.lstat(path).st_mode | |
71 | os.chmod(path, s | 0100) |
|
71 | os.chmod(path, s | 0100) | |
72 | return (os.lstat(path).st_mode & 0100 != 0) |
|
72 | return (os.lstat(path).st_mode & 0100 != 0) | |
73 | finally: |
|
73 | finally: | |
74 | os.remove(path) |
|
74 | os.remove(path) | |
75 |
|
75 | |||
76 | def has_icasefs(): |
|
76 | def has_icasefs(): | |
77 | # Stolen from mercurial.util |
|
77 | # Stolen from mercurial.util | |
78 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') |
|
78 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') | |
79 | os.close(fd) |
|
79 | os.close(fd) | |
80 | try: |
|
80 | try: | |
81 | s1 = os.stat(path) |
|
81 | s1 = os.stat(path) | |
82 | d, b = os.path.split(path) |
|
82 | d, b = os.path.split(path) | |
83 | p2 = os.path.join(d, b.upper()) |
|
83 | p2 = os.path.join(d, b.upper()) | |
84 | if path == p2: |
|
84 | if path == p2: | |
85 | p2 = os.path.join(d, b.lower()) |
|
85 | p2 = os.path.join(d, b.lower()) | |
86 | try: |
|
86 | try: | |
87 | s2 = os.stat(p2) |
|
87 | s2 = os.stat(p2) | |
88 | return s2 == s1 |
|
88 | return s2 == s1 | |
89 | except: |
|
89 | except: | |
90 | return False |
|
90 | return False | |
91 | finally: |
|
91 | finally: | |
92 | os.remove(path) |
|
92 | os.remove(path) | |
93 |
|
93 | |||
94 | def has_inotify(): |
|
94 | def has_inotify(): | |
95 | try: |
|
95 | try: | |
96 | import hgext.inotify.linux.watcher |
|
96 | import hgext.inotify.linux.watcher | |
97 | return True |
|
97 | return True | |
98 | except ImportError: |
|
98 | except ImportError: | |
99 | return False |
|
99 | return False | |
100 |
|
100 | |||
101 | def has_fifo(): |
|
101 | def has_fifo(): | |
102 | return hasattr(os, "mkfifo") |
|
102 | return hasattr(os, "mkfifo") | |
103 |
|
103 | |||
104 | def has_hotshot(): |
|
104 | def has_hotshot(): | |
105 | try: |
|
105 | try: | |
106 | # hotshot.stats tests hotshot and many problematic dependencies |
|
106 | # hotshot.stats tests hotshot and many problematic dependencies | |
107 | # like profile. |
|
107 | # like profile. | |
108 | import hotshot.stats |
|
108 | import hotshot.stats | |
109 | return True |
|
109 | return True | |
110 | except ImportError: |
|
110 | except ImportError: | |
111 | return False |
|
111 | return False | |
112 |
|
112 | |||
113 | def has_lsprof(): |
|
113 | def has_lsprof(): | |
114 | try: |
|
114 | try: | |
115 | import _lsprof |
|
115 | import _lsprof | |
116 | return True |
|
116 | return True | |
117 | except ImportError: |
|
117 | except ImportError: | |
118 | return False |
|
118 | return False | |
119 |
|
119 | |||
120 | def has_git(): |
|
120 | def has_git(): | |
121 | return matchoutput('git --version 2>&1', r'^git version') |
|
121 | return matchoutput('git --version 2>&1', r'^git version') | |
122 |
|
122 | |||
123 | def has_rst2html(): |
|
123 | def has_rst2html(): | |
124 | return matchoutput('rst2html --version', r'^rst2html \(Docutils') or \ |
|
124 | return matchoutput('rst2html --version 2>&1', r'^rst2html \(Docutils') or \ | |
125 | matchoutput('rst2html.py --version', r'^rst2html.py \(Docutils') |
|
125 | matchoutput('rst2html.py --version 2>&1', r'^rst2html.py \(Docutils') | |
126 |
|
126 | |||
127 | def has_svn(): |
|
127 | def has_svn(): | |
128 | #return matchoutput('svn --version 2>&1', r'^svn, version') and \ |
|
128 | #return matchoutput('svn --version 2>&1', r'^svn, version') and \ | |
129 | #matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') |
|
129 | #matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') | |
130 | # disabled until licensing issue is resolved |
|
130 | # disabled until licensing issue is resolved | |
131 | return False |
|
131 | return False | |
132 |
|
132 | |||
133 | def has_svn_bindings(): |
|
133 | def has_svn_bindings(): | |
134 | try: |
|
134 | try: | |
135 | import svn.core |
|
135 | import svn.core | |
136 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR |
|
136 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR | |
137 | if version < (1, 4): |
|
137 | if version < (1, 4): | |
138 | return False |
|
138 | return False | |
139 | return True |
|
139 | return True | |
140 | except ImportError: |
|
140 | except ImportError: | |
141 | return False |
|
141 | return False | |
142 |
|
142 | |||
143 | def has_p4(): |
|
143 | def has_p4(): | |
144 | return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/') |
|
144 | return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/') | |
145 |
|
145 | |||
146 | def has_symlink(): |
|
146 | def has_symlink(): | |
147 | return hasattr(os, "symlink") |
|
147 | return hasattr(os, "symlink") | |
148 |
|
148 | |||
149 | def has_tla(): |
|
149 | def has_tla(): | |
150 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') |
|
150 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') | |
151 |
|
151 | |||
152 | def has_gpg(): |
|
152 | def has_gpg(): | |
153 | return matchoutput('gpg --version 2>&1', r'GnuPG') |
|
153 | return matchoutput('gpg --version 2>&1', r'GnuPG') | |
154 |
|
154 | |||
155 | def has_unix_permissions(): |
|
155 | def has_unix_permissions(): | |
156 | d = tempfile.mkdtemp(prefix=tempprefix, dir=".") |
|
156 | d = tempfile.mkdtemp(prefix=tempprefix, dir=".") | |
157 | try: |
|
157 | try: | |
158 | fname = os.path.join(d, 'foo') |
|
158 | fname = os.path.join(d, 'foo') | |
159 | for umask in (077, 007, 022): |
|
159 | for umask in (077, 007, 022): | |
160 | os.umask(umask) |
|
160 | os.umask(umask) | |
161 | f = open(fname, 'w') |
|
161 | f = open(fname, 'w') | |
162 | f.close() |
|
162 | f.close() | |
163 | mode = os.stat(fname).st_mode |
|
163 | mode = os.stat(fname).st_mode | |
164 | os.unlink(fname) |
|
164 | os.unlink(fname) | |
165 | if mode & 0777 != ~umask & 0666: |
|
165 | if mode & 0777 != ~umask & 0666: | |
166 | return False |
|
166 | return False | |
167 | return True |
|
167 | return True | |
168 | finally: |
|
168 | finally: | |
169 | os.rmdir(d) |
|
169 | os.rmdir(d) | |
170 |
|
170 | |||
171 | def has_pygments(): |
|
171 | def has_pygments(): | |
172 | try: |
|
172 | try: | |
173 | import pygments |
|
173 | import pygments | |
174 | return True |
|
174 | return True | |
175 | except ImportError: |
|
175 | except ImportError: | |
176 | return False |
|
176 | return False | |
177 |
|
177 | |||
178 | def has_outer_repo(): |
|
178 | def has_outer_repo(): | |
179 | return matchoutput('hg root 2>&1', r'') |
|
179 | return matchoutput('hg root 2>&1', r'') | |
180 |
|
180 | |||
181 | checks = { |
|
181 | checks = { | |
182 | "baz": (has_baz, "GNU Arch baz client"), |
|
182 | "baz": (has_baz, "GNU Arch baz client"), | |
183 | "bzr": (has_bzr, "Canonical's Bazaar client"), |
|
183 | "bzr": (has_bzr, "Canonical's Bazaar client"), | |
184 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), |
|
184 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), | |
185 | "cvs": (has_cvs, "cvs client/server"), |
|
185 | "cvs": (has_cvs, "cvs client/server"), | |
186 | "darcs": (has_darcs, "darcs client"), |
|
186 | "darcs": (has_darcs, "darcs client"), | |
187 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
|
187 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | |
188 | "execbit": (has_executablebit, "executable bit"), |
|
188 | "execbit": (has_executablebit, "executable bit"), | |
189 | "fifo": (has_fifo, "named pipes"), |
|
189 | "fifo": (has_fifo, "named pipes"), | |
190 | "git": (has_git, "git command line client"), |
|
190 | "git": (has_git, "git command line client"), | |
191 | "gpg": (has_gpg, "gpg client"), |
|
191 | "gpg": (has_gpg, "gpg client"), | |
192 | "hotshot": (has_hotshot, "python hotshot module"), |
|
192 | "hotshot": (has_hotshot, "python hotshot module"), | |
193 | "icasefs": (has_icasefs, "case insensitive file system"), |
|
193 | "icasefs": (has_icasefs, "case insensitive file system"), | |
194 | "inotify": (has_inotify, "inotify extension support"), |
|
194 | "inotify": (has_inotify, "inotify extension support"), | |
195 | "lsprof": (has_lsprof, "python lsprof module"), |
|
195 | "lsprof": (has_lsprof, "python lsprof module"), | |
196 | "mtn": (has_mtn, "monotone client (> 0.31)"), |
|
196 | "mtn": (has_mtn, "monotone client (> 0.31)"), | |
197 | "outer-repo": (has_outer_repo, "outer repo"), |
|
197 | "outer-repo": (has_outer_repo, "outer repo"), | |
198 | "p4": (has_p4, "Perforce server and client"), |
|
198 | "p4": (has_p4, "Perforce server and client"), | |
199 | "pygments": (has_pygments, "Pygments source highlighting library"), |
|
199 | "pygments": (has_pygments, "Pygments source highlighting library"), | |
200 | "rst2html": (has_rst2html, "Docutils rst2html tool"), |
|
200 | "rst2html": (has_rst2html, "Docutils rst2html tool"), | |
201 | "svn": (has_svn, "subversion client and admin tools"), |
|
201 | "svn": (has_svn, "subversion client and admin tools"), | |
202 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), |
|
202 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), | |
203 | "symlink": (has_symlink, "symbolic links"), |
|
203 | "symlink": (has_symlink, "symbolic links"), | |
204 | "tla": (has_tla, "GNU Arch tla client"), |
|
204 | "tla": (has_tla, "GNU Arch tla client"), | |
205 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), |
|
205 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | def list_features(): |
|
208 | def list_features(): | |
209 | for name, feature in checks.iteritems(): |
|
209 | for name, feature in checks.iteritems(): | |
210 | desc = feature[1] |
|
210 | desc = feature[1] | |
211 | print name + ':', desc |
|
211 | print name + ':', desc | |
212 |
|
212 | |||
213 | def test_features(): |
|
213 | def test_features(): | |
214 | failed = 0 |
|
214 | failed = 0 | |
215 | for name, feature in checks.iteritems(): |
|
215 | for name, feature in checks.iteritems(): | |
216 | check, _ = feature |
|
216 | check, _ = feature | |
217 | try: |
|
217 | try: | |
218 | check() |
|
218 | check() | |
219 | except Exception, e: |
|
219 | except Exception, e: | |
220 | print "feature %s failed: %s" % (name, e) |
|
220 | print "feature %s failed: %s" % (name, e) | |
221 | failed += 1 |
|
221 | failed += 1 | |
222 | return failed |
|
222 | return failed | |
223 |
|
223 | |||
224 | parser = optparse.OptionParser("%prog [options] [features]") |
|
224 | parser = optparse.OptionParser("%prog [options] [features]") | |
225 | parser.add_option("--test-features", action="store_true", |
|
225 | parser.add_option("--test-features", action="store_true", | |
226 | help="test available features") |
|
226 | help="test available features") | |
227 | parser.add_option("--list-features", action="store_true", |
|
227 | parser.add_option("--list-features", action="store_true", | |
228 | help="list available features") |
|
228 | help="list available features") | |
229 | parser.add_option("-q", "--quiet", action="store_true", |
|
229 | parser.add_option("-q", "--quiet", action="store_true", | |
230 | help="check features silently") |
|
230 | help="check features silently") | |
231 |
|
231 | |||
232 | if __name__ == '__main__': |
|
232 | if __name__ == '__main__': | |
233 | options, args = parser.parse_args() |
|
233 | options, args = parser.parse_args() | |
234 | if options.list_features: |
|
234 | if options.list_features: | |
235 | list_features() |
|
235 | list_features() | |
236 | sys.exit(0) |
|
236 | sys.exit(0) | |
237 |
|
237 | |||
238 | if options.test_features: |
|
238 | if options.test_features: | |
239 | sys.exit(test_features()) |
|
239 | sys.exit(test_features()) | |
240 |
|
240 | |||
241 | quiet = options.quiet |
|
241 | quiet = options.quiet | |
242 |
|
242 | |||
243 | failures = 0 |
|
243 | failures = 0 | |
244 |
|
244 | |||
245 | def error(msg): |
|
245 | def error(msg): | |
246 | global failures |
|
246 | global failures | |
247 | if not quiet: |
|
247 | if not quiet: | |
248 | sys.stderr.write(msg + '\n') |
|
248 | sys.stderr.write(msg + '\n') | |
249 | failures += 1 |
|
249 | failures += 1 | |
250 |
|
250 | |||
251 | for feature in args: |
|
251 | for feature in args: | |
252 | negate = feature.startswith('no-') |
|
252 | negate = feature.startswith('no-') | |
253 | if negate: |
|
253 | if negate: | |
254 | feature = feature[3:] |
|
254 | feature = feature[3:] | |
255 |
|
255 | |||
256 | if feature not in checks: |
|
256 | if feature not in checks: | |
257 | error('skipped: unknown feature: ' + feature) |
|
257 | error('skipped: unknown feature: ' + feature) | |
258 | continue |
|
258 | continue | |
259 |
|
259 | |||
260 | check, desc = checks[feature] |
|
260 | check, desc = checks[feature] | |
261 | try: |
|
261 | try: | |
262 | available = check() |
|
262 | available = check() | |
263 | except Exception, e: |
|
263 | except Exception, e: | |
264 | error('hghave check failed: ' + feature) |
|
264 | error('hghave check failed: ' + feature) | |
265 | continue |
|
265 | continue | |
266 |
|
266 | |||
267 | if not negate and not available: |
|
267 | if not negate and not available: | |
268 | error('skipped: missing feature: ' + desc) |
|
268 | error('skipped: missing feature: ' + desc) | |
269 | elif negate and available: |
|
269 | elif negate and available: | |
270 | error('skipped: system supports %s' % desc) |
|
270 | error('skipped: system supports %s' % desc) | |
271 |
|
271 | |||
272 | if failures != 0: |
|
272 | if failures != 0: | |
273 | sys.exit(1) |
|
273 | sys.exit(1) | |
274 |
|
274 | |||
275 |
|
275 |
General Comments 0
You need to be logged in to leave comments.
Login now