Show More
@@ -1,347 +1,77 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 | import os, stat | |
|
8 | import re | |
|
9 | 7 | import sys |
|
10 | import tempfile | |
|
11 | ||
|
12 | tempprefix = 'hg-hghave-' | |
|
13 | ||
|
14 | def matchoutput(cmd, regexp, ignorestatus=False): | |
|
15 | """Return True if cmd executes successfully and its output | |
|
16 | is matched by the supplied regular expression. | |
|
17 | """ | |
|
18 | r = re.compile(regexp) | |
|
19 | fh = os.popen(cmd) | |
|
20 | s = fh.read() | |
|
21 | try: | |
|
22 | ret = fh.close() | |
|
23 | except IOError: | |
|
24 | # Happen in Windows test environment | |
|
25 | ret = 1 | |
|
26 | return (ignorestatus or ret is None) and r.search(s) | |
|
27 | ||
|
28 | def has_baz(): | |
|
29 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') | |
|
30 | ||
|
31 | def has_bzr(): | |
|
32 | try: | |
|
33 | import bzrlib | |
|
34 | return bzrlib.__doc__ is not None | |
|
35 | except ImportError: | |
|
36 | return False | |
|
37 | ||
|
38 | def has_bzr114(): | |
|
39 | try: | |
|
40 | import bzrlib | |
|
41 | return (bzrlib.__doc__ is not None | |
|
42 | and bzrlib.version_info[:2] >= (1, 14)) | |
|
43 | except ImportError: | |
|
44 | return False | |
|
45 | ||
|
46 | def has_cvs(): | |
|
47 | re = r'Concurrent Versions System.*?server' | |
|
48 | return matchoutput('cvs --version 2>&1', re) and not has_msys() | |
|
49 | ||
|
50 | def has_darcs(): | |
|
51 | return matchoutput('darcs --version', r'2\.[2-9]', True) | |
|
52 | ||
|
53 | def has_mtn(): | |
|
54 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( | |
|
55 | 'mtn --version', r'monotone 0\.', True) | |
|
56 | ||
|
57 | def has_eol_in_paths(): | |
|
58 | try: | |
|
59 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | |
|
60 | os.close(fd) | |
|
61 | os.remove(path) | |
|
62 | return True | |
|
63 | except (IOError, OSError): | |
|
64 | return False | |
|
65 | ||
|
66 | def has_executablebit(): | |
|
67 | try: | |
|
68 | EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | |
|
69 | fh, fn = tempfile.mkstemp(dir=".", prefix='hg-checkexec-') | |
|
70 | try: | |
|
71 | os.close(fh) | |
|
72 | m = os.stat(fn).st_mode & 0777 | |
|
73 | new_file_has_exec = m & EXECFLAGS | |
|
74 | os.chmod(fn, m ^ EXECFLAGS) | |
|
75 | exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m) | |
|
76 | finally: | |
|
77 | os.unlink(fn) | |
|
78 | except (IOError, OSError): | |
|
79 | # we don't care, the user probably won't be able to commit anyway | |
|
80 | return False | |
|
81 | return not (new_file_has_exec or exec_flags_cannot_flip) | |
|
82 | ||
|
83 | def has_icasefs(): | |
|
84 | # Stolen from mercurial.util | |
|
85 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') | |
|
86 | os.close(fd) | |
|
87 | try: | |
|
88 | s1 = os.stat(path) | |
|
89 | d, b = os.path.split(path) | |
|
90 | p2 = os.path.join(d, b.upper()) | |
|
91 | if path == p2: | |
|
92 | p2 = os.path.join(d, b.lower()) | |
|
93 | try: | |
|
94 | s2 = os.stat(p2) | |
|
95 | return s2 == s1 | |
|
96 | except OSError: | |
|
97 | return False | |
|
98 | finally: | |
|
99 | os.remove(path) | |
|
100 | ||
|
101 | def has_inotify(): | |
|
102 | try: | |
|
103 | import hgext.inotify.linux.watcher | |
|
104 | return True | |
|
105 | except ImportError: | |
|
106 | return False | |
|
107 | ||
|
108 | def has_fifo(): | |
|
109 | return getattr(os, "mkfifo", None) is not None | |
|
110 | ||
|
111 | def has_cacheable_fs(): | |
|
112 | from mercurial import util | |
|
113 | ||
|
114 | fd, path = tempfile.mkstemp(prefix=tempprefix) | |
|
115 | os.close(fd) | |
|
116 | try: | |
|
117 | return util.cachestat(path).cacheable() | |
|
118 | finally: | |
|
119 | os.remove(path) | |
|
120 | ||
|
121 | def has_lsprof(): | |
|
122 | try: | |
|
123 | import _lsprof | |
|
124 | return True | |
|
125 | except ImportError: | |
|
126 | return False | |
|
127 | ||
|
128 | def has_gettext(): | |
|
129 | return matchoutput('msgfmt --version', 'GNU gettext-tools') | |
|
130 | ||
|
131 | def has_git(): | |
|
132 | return matchoutput('git --version 2>&1', r'^git version') | |
|
133 | ||
|
134 | def has_docutils(): | |
|
135 | try: | |
|
136 | from docutils.core import publish_cmdline | |
|
137 | return True | |
|
138 | except ImportError: | |
|
139 | return False | |
|
8 | import hghave | |
|
140 | 9 | |
|
141 | def getsvnversion(): | |
|
142 | m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') | |
|
143 | if not m: | |
|
144 | return (0, 0) | |
|
145 | return (int(m.group(1)), int(m.group(2))) | |
|
146 | ||
|
147 | def has_svn15(): | |
|
148 | return getsvnversion() >= (1, 5) | |
|
149 | ||
|
150 | def has_svn13(): | |
|
151 | return getsvnversion() >= (1, 3) | |
|
152 | ||
|
153 | def has_svn(): | |
|
154 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ | |
|
155 | matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') | |
|
156 | ||
|
157 | def has_svn_bindings(): | |
|
158 | try: | |
|
159 | import svn.core | |
|
160 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR | |
|
161 | if version < (1, 4): | |
|
162 | return False | |
|
163 | return True | |
|
164 | except ImportError: | |
|
165 | return False | |
|
166 | ||
|
167 | def has_p4(): | |
|
168 | return (matchoutput('p4 -V', r'Rev\. P4/') and | |
|
169 | matchoutput('p4d -V', r'Rev\. P4D/')) | |
|
170 | ||
|
171 | def has_symlink(): | |
|
172 | if getattr(os, "symlink", None) is None: | |
|
173 | return False | |
|
174 | name = tempfile.mktemp(dir=".", prefix='hg-checklink-') | |
|
175 | try: | |
|
176 | os.symlink(".", name) | |
|
177 | os.unlink(name) | |
|
178 | return True | |
|
179 | except (OSError, AttributeError): | |
|
180 | return False | |
|
181 | ||
|
182 | def has_tla(): | |
|
183 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') | |
|
184 | ||
|
185 | def has_gpg(): | |
|
186 | return matchoutput('gpg --version 2>&1', r'GnuPG') | |
|
187 | ||
|
188 | def has_unix_permissions(): | |
|
189 | d = tempfile.mkdtemp(prefix=tempprefix, dir=".") | |
|
190 | try: | |
|
191 | fname = os.path.join(d, 'foo') | |
|
192 | for umask in (077, 007, 022): | |
|
193 | os.umask(umask) | |
|
194 | f = open(fname, 'w') | |
|
195 | f.close() | |
|
196 | mode = os.stat(fname).st_mode | |
|
197 | os.unlink(fname) | |
|
198 | if mode & 0777 != ~umask & 0666: | |
|
199 | return False | |
|
200 | return True | |
|
201 | finally: | |
|
202 | os.rmdir(d) | |
|
203 | ||
|
204 | def has_pyflakes(): | |
|
205 | return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"", | |
|
206 | r"<stdin>:1: 're' imported but unused", | |
|
207 | True) | |
|
208 | ||
|
209 | def has_pygments(): | |
|
210 | try: | |
|
211 | import pygments | |
|
212 | return True | |
|
213 | except ImportError: | |
|
214 | return False | |
|
215 | ||
|
216 | def has_outer_repo(): | |
|
217 | return matchoutput('hg root 2>&1', r'') | |
|
218 | ||
|
219 | def has_ssl(): | |
|
220 | try: | |
|
221 | import ssl | |
|
222 | import OpenSSL | |
|
223 | OpenSSL.SSL.Context | |
|
224 | return True | |
|
225 | except ImportError: | |
|
226 | return False | |
|
227 | ||
|
228 | def has_windows(): | |
|
229 | return os.name == 'nt' | |
|
230 | ||
|
231 | def has_system_sh(): | |
|
232 | return os.name != 'nt' | |
|
233 | ||
|
234 | def has_serve(): | |
|
235 | return os.name != 'nt' # gross approximation | |
|
236 | ||
|
237 | def has_tic(): | |
|
238 | return matchoutput('test -x "`which tic`"', '') | |
|
239 | ||
|
240 | def has_msys(): | |
|
241 | return os.getenv('MSYSTEM') | |
|
242 | ||
|
243 | checks = { | |
|
244 | "true": (lambda: True, "yak shaving"), | |
|
245 | "false": (lambda: False, "nail clipper"), | |
|
246 | "baz": (has_baz, "GNU Arch baz client"), | |
|
247 | "bzr": (has_bzr, "Canonical's Bazaar client"), | |
|
248 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), | |
|
249 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), | |
|
250 | "cvs": (has_cvs, "cvs client/server"), | |
|
251 | "darcs": (has_darcs, "darcs client"), | |
|
252 | "docutils": (has_docutils, "Docutils text processing library"), | |
|
253 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | |
|
254 | "execbit": (has_executablebit, "executable bit"), | |
|
255 | "fifo": (has_fifo, "named pipes"), | |
|
256 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), | |
|
257 | "git": (has_git, "git command line client"), | |
|
258 | "gpg": (has_gpg, "gpg client"), | |
|
259 | "icasefs": (has_icasefs, "case insensitive file system"), | |
|
260 | "inotify": (has_inotify, "inotify extension support"), | |
|
261 | "lsprof": (has_lsprof, "python lsprof module"), | |
|
262 | "mtn": (has_mtn, "monotone client (>= 1.0)"), | |
|
263 | "outer-repo": (has_outer_repo, "outer repo"), | |
|
264 | "p4": (has_p4, "Perforce server and client"), | |
|
265 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), | |
|
266 | "pygments": (has_pygments, "Pygments source highlighting library"), | |
|
267 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), | |
|
268 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), | |
|
269 | "svn": (has_svn, "subversion client and admin tools"), | |
|
270 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), | |
|
271 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), | |
|
272 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), | |
|
273 | "symlink": (has_symlink, "symbolic links"), | |
|
274 | "system-sh": (has_system_sh, "system() uses sh"), | |
|
275 | "tic": (has_tic, "terminfo compiler"), | |
|
276 | "tla": (has_tla, "GNU Arch tla client"), | |
|
277 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), | |
|
278 | "windows": (has_windows, "Windows"), | |
|
279 | "msys": (has_msys, "Windows with MSYS"), | |
|
280 | } | |
|
10 | checks = hghave.checks | |
|
281 | 11 | |
|
282 | 12 | def list_features(): |
|
283 | 13 | for name, feature in checks.iteritems(): |
|
284 | 14 | desc = feature[1] |
|
285 | 15 | print name + ':', desc |
|
286 | 16 | |
|
287 | 17 | def test_features(): |
|
288 | 18 | failed = 0 |
|
289 | 19 | for name, feature in checks.iteritems(): |
|
290 | 20 | check, _ = feature |
|
291 | 21 | try: |
|
292 | 22 | check() |
|
293 | 23 | except Exception, e: |
|
294 | 24 | print "feature %s failed: %s" % (name, e) |
|
295 | 25 | failed += 1 |
|
296 | 26 | return failed |
|
297 | 27 | |
|
298 | 28 | parser = optparse.OptionParser("%prog [options] [features]") |
|
299 | 29 | parser.add_option("--test-features", action="store_true", |
|
300 | 30 | help="test available features") |
|
301 | 31 | parser.add_option("--list-features", action="store_true", |
|
302 | 32 | help="list available features") |
|
303 | 33 | parser.add_option("-q", "--quiet", action="store_true", |
|
304 | 34 | help="check features silently") |
|
305 | 35 | |
|
306 | 36 | if __name__ == '__main__': |
|
307 | 37 | options, args = parser.parse_args() |
|
308 | 38 | if options.list_features: |
|
309 | 39 | list_features() |
|
310 | 40 | sys.exit(0) |
|
311 | 41 | |
|
312 | 42 | if options.test_features: |
|
313 | 43 | sys.exit(test_features()) |
|
314 | 44 | |
|
315 | 45 | quiet = options.quiet |
|
316 | 46 | |
|
317 | 47 | failures = 0 |
|
318 | 48 | |
|
319 | 49 | def error(msg): |
|
320 | 50 | global failures |
|
321 | 51 | if not quiet: |
|
322 | 52 | sys.stderr.write(msg + '\n') |
|
323 | 53 | failures += 1 |
|
324 | 54 | |
|
325 | 55 | for feature in args: |
|
326 | 56 | negate = feature.startswith('no-') |
|
327 | 57 | if negate: |
|
328 | 58 | feature = feature[3:] |
|
329 | 59 | |
|
330 | 60 | if feature not in checks: |
|
331 | 61 | error('skipped: unknown feature: ' + feature) |
|
332 | 62 | continue |
|
333 | 63 | |
|
334 | 64 | check, desc = checks[feature] |
|
335 | 65 | try: |
|
336 | 66 | available = check() |
|
337 | 67 | except Exception, e: |
|
338 | 68 | error('hghave check failed: ' + feature) |
|
339 | 69 | continue |
|
340 | 70 | |
|
341 | 71 | if not negate and not available: |
|
342 | 72 | error('skipped: missing feature: ' + desc) |
|
343 | 73 | elif negate and available: |
|
344 | 74 | error('skipped: system supports %s' % desc) |
|
345 | 75 | |
|
346 | 76 | if failures != 0: |
|
347 | 77 | sys.exit(1) |
@@ -1,347 +1,274 b'' | |||
|
1 | #!/usr/bin/env python | |
|
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 | |
|
4 | prefixed with "no-", the absence of feature is tested. | |
|
5 | """ | |
|
6 | import optparse | |
|
7 | 1 | import os, stat |
|
8 | 2 | import re |
|
9 | 3 | import sys |
|
10 | 4 | import tempfile |
|
11 | 5 | |
|
12 | 6 | tempprefix = 'hg-hghave-' |
|
13 | 7 | |
|
14 | 8 | def matchoutput(cmd, regexp, ignorestatus=False): |
|
15 | 9 | """Return True if cmd executes successfully and its output |
|
16 | 10 | is matched by the supplied regular expression. |
|
17 | 11 | """ |
|
18 | 12 | r = re.compile(regexp) |
|
19 | 13 | fh = os.popen(cmd) |
|
20 | 14 | s = fh.read() |
|
21 | 15 | try: |
|
22 | 16 | ret = fh.close() |
|
23 | 17 | except IOError: |
|
24 | 18 | # Happen in Windows test environment |
|
25 | 19 | ret = 1 |
|
26 | 20 | return (ignorestatus or ret is None) and r.search(s) |
|
27 | 21 | |
|
28 | 22 | def has_baz(): |
|
29 | 23 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') |
|
30 | 24 | |
|
31 | 25 | def has_bzr(): |
|
32 | 26 | try: |
|
33 | 27 | import bzrlib |
|
34 | 28 | return bzrlib.__doc__ is not None |
|
35 | 29 | except ImportError: |
|
36 | 30 | return False |
|
37 | 31 | |
|
38 | 32 | def has_bzr114(): |
|
39 | 33 | try: |
|
40 | 34 | import bzrlib |
|
41 | 35 | return (bzrlib.__doc__ is not None |
|
42 | 36 | and bzrlib.version_info[:2] >= (1, 14)) |
|
43 | 37 | except ImportError: |
|
44 | 38 | return False |
|
45 | 39 | |
|
46 | 40 | def has_cvs(): |
|
47 | 41 | re = r'Concurrent Versions System.*?server' |
|
48 | 42 | return matchoutput('cvs --version 2>&1', re) and not has_msys() |
|
49 | 43 | |
|
50 | 44 | def has_darcs(): |
|
51 | 45 | return matchoutput('darcs --version', r'2\.[2-9]', True) |
|
52 | 46 | |
|
53 | 47 | def has_mtn(): |
|
54 | 48 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( |
|
55 | 49 | 'mtn --version', r'monotone 0\.', True) |
|
56 | 50 | |
|
57 | 51 | def has_eol_in_paths(): |
|
58 | 52 | try: |
|
59 | 53 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
|
60 | 54 | os.close(fd) |
|
61 | 55 | os.remove(path) |
|
62 | 56 | return True |
|
63 | 57 | except (IOError, OSError): |
|
64 | 58 | return False |
|
65 | 59 | |
|
66 | 60 | def has_executablebit(): |
|
67 | 61 | try: |
|
68 | 62 | EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH |
|
69 | 63 | fh, fn = tempfile.mkstemp(dir=".", prefix='hg-checkexec-') |
|
70 | 64 | try: |
|
71 | 65 | os.close(fh) |
|
72 | 66 | m = os.stat(fn).st_mode & 0777 |
|
73 | 67 | new_file_has_exec = m & EXECFLAGS |
|
74 | 68 | os.chmod(fn, m ^ EXECFLAGS) |
|
75 | 69 | exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m) |
|
76 | 70 | finally: |
|
77 | 71 | os.unlink(fn) |
|
78 | 72 | except (IOError, OSError): |
|
79 | 73 | # we don't care, the user probably won't be able to commit anyway |
|
80 | 74 | return False |
|
81 | 75 | return not (new_file_has_exec or exec_flags_cannot_flip) |
|
82 | 76 | |
|
83 | 77 | def has_icasefs(): |
|
84 | 78 | # Stolen from mercurial.util |
|
85 | 79 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') |
|
86 | 80 | os.close(fd) |
|
87 | 81 | try: |
|
88 | 82 | s1 = os.stat(path) |
|
89 | 83 | d, b = os.path.split(path) |
|
90 | 84 | p2 = os.path.join(d, b.upper()) |
|
91 | 85 | if path == p2: |
|
92 | 86 | p2 = os.path.join(d, b.lower()) |
|
93 | 87 | try: |
|
94 | 88 | s2 = os.stat(p2) |
|
95 | 89 | return s2 == s1 |
|
96 | 90 | except OSError: |
|
97 | 91 | return False |
|
98 | 92 | finally: |
|
99 | 93 | os.remove(path) |
|
100 | 94 | |
|
101 | 95 | def has_inotify(): |
|
102 | 96 | try: |
|
103 | 97 | import hgext.inotify.linux.watcher |
|
104 | 98 | return True |
|
105 | 99 | except ImportError: |
|
106 | 100 | return False |
|
107 | 101 | |
|
108 | 102 | def has_fifo(): |
|
109 | 103 | return getattr(os, "mkfifo", None) is not None |
|
110 | 104 | |
|
111 | 105 | def has_cacheable_fs(): |
|
112 | 106 | from mercurial import util |
|
113 | 107 | |
|
114 | 108 | fd, path = tempfile.mkstemp(prefix=tempprefix) |
|
115 | 109 | os.close(fd) |
|
116 | 110 | try: |
|
117 | 111 | return util.cachestat(path).cacheable() |
|
118 | 112 | finally: |
|
119 | 113 | os.remove(path) |
|
120 | 114 | |
|
121 | 115 | def has_lsprof(): |
|
122 | 116 | try: |
|
123 | 117 | import _lsprof |
|
124 | 118 | return True |
|
125 | 119 | except ImportError: |
|
126 | 120 | return False |
|
127 | 121 | |
|
128 | 122 | def has_gettext(): |
|
129 | 123 | return matchoutput('msgfmt --version', 'GNU gettext-tools') |
|
130 | 124 | |
|
131 | 125 | def has_git(): |
|
132 | 126 | return matchoutput('git --version 2>&1', r'^git version') |
|
133 | 127 | |
|
134 | 128 | def has_docutils(): |
|
135 | 129 | try: |
|
136 | 130 | from docutils.core import publish_cmdline |
|
137 | 131 | return True |
|
138 | 132 | except ImportError: |
|
139 | 133 | return False |
|
140 | 134 | |
|
141 | 135 | def getsvnversion(): |
|
142 | 136 | m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') |
|
143 | 137 | if not m: |
|
144 | 138 | return (0, 0) |
|
145 | 139 | return (int(m.group(1)), int(m.group(2))) |
|
146 | 140 | |
|
147 | 141 | def has_svn15(): |
|
148 | 142 | return getsvnversion() >= (1, 5) |
|
149 | 143 | |
|
150 | 144 | def has_svn13(): |
|
151 | 145 | return getsvnversion() >= (1, 3) |
|
152 | 146 | |
|
153 | 147 | def has_svn(): |
|
154 | 148 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ |
|
155 | 149 | matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') |
|
156 | 150 | |
|
157 | 151 | def has_svn_bindings(): |
|
158 | 152 | try: |
|
159 | 153 | import svn.core |
|
160 | 154 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR |
|
161 | 155 | if version < (1, 4): |
|
162 | 156 | return False |
|
163 | 157 | return True |
|
164 | 158 | except ImportError: |
|
165 | 159 | return False |
|
166 | 160 | |
|
167 | 161 | def has_p4(): |
|
168 | 162 | return (matchoutput('p4 -V', r'Rev\. P4/') and |
|
169 | 163 | matchoutput('p4d -V', r'Rev\. P4D/')) |
|
170 | 164 | |
|
171 | 165 | def has_symlink(): |
|
172 | 166 | if getattr(os, "symlink", None) is None: |
|
173 | 167 | return False |
|
174 | 168 | name = tempfile.mktemp(dir=".", prefix='hg-checklink-') |
|
175 | 169 | try: |
|
176 | 170 | os.symlink(".", name) |
|
177 | 171 | os.unlink(name) |
|
178 | 172 | return True |
|
179 | 173 | except (OSError, AttributeError): |
|
180 | 174 | return False |
|
181 | 175 | |
|
182 | 176 | def has_tla(): |
|
183 | 177 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') |
|
184 | 178 | |
|
185 | 179 | def has_gpg(): |
|
186 | 180 | return matchoutput('gpg --version 2>&1', r'GnuPG') |
|
187 | 181 | |
|
188 | 182 | def has_unix_permissions(): |
|
189 | 183 | d = tempfile.mkdtemp(prefix=tempprefix, dir=".") |
|
190 | 184 | try: |
|
191 | 185 | fname = os.path.join(d, 'foo') |
|
192 | 186 | for umask in (077, 007, 022): |
|
193 | 187 | os.umask(umask) |
|
194 | 188 | f = open(fname, 'w') |
|
195 | 189 | f.close() |
|
196 | 190 | mode = os.stat(fname).st_mode |
|
197 | 191 | os.unlink(fname) |
|
198 | 192 | if mode & 0777 != ~umask & 0666: |
|
199 | 193 | return False |
|
200 | 194 | return True |
|
201 | 195 | finally: |
|
202 | 196 | os.rmdir(d) |
|
203 | 197 | |
|
204 | 198 | def has_pyflakes(): |
|
205 | 199 | return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"", |
|
206 | 200 | r"<stdin>:1: 're' imported but unused", |
|
207 | 201 | True) |
|
208 | 202 | |
|
209 | 203 | def has_pygments(): |
|
210 | 204 | try: |
|
211 | 205 | import pygments |
|
212 | 206 | return True |
|
213 | 207 | except ImportError: |
|
214 | 208 | return False |
|
215 | 209 | |
|
216 | 210 | def has_outer_repo(): |
|
217 | 211 | return matchoutput('hg root 2>&1', r'') |
|
218 | 212 | |
|
219 | 213 | def has_ssl(): |
|
220 | 214 | try: |
|
221 | 215 | import ssl |
|
222 | 216 | import OpenSSL |
|
223 | 217 | OpenSSL.SSL.Context |
|
224 | 218 | return True |
|
225 | 219 | except ImportError: |
|
226 | 220 | return False |
|
227 | 221 | |
|
228 | 222 | def has_windows(): |
|
229 | 223 | return os.name == 'nt' |
|
230 | 224 | |
|
231 | 225 | def has_system_sh(): |
|
232 | 226 | return os.name != 'nt' |
|
233 | 227 | |
|
234 | 228 | def has_serve(): |
|
235 | 229 | return os.name != 'nt' # gross approximation |
|
236 | 230 | |
|
237 | 231 | def has_tic(): |
|
238 | 232 | return matchoutput('test -x "`which tic`"', '') |
|
239 | 233 | |
|
240 | 234 | def has_msys(): |
|
241 | 235 | return os.getenv('MSYSTEM') |
|
242 | 236 | |
|
243 | 237 | checks = { |
|
244 | 238 | "true": (lambda: True, "yak shaving"), |
|
245 | 239 | "false": (lambda: False, "nail clipper"), |
|
246 | 240 | "baz": (has_baz, "GNU Arch baz client"), |
|
247 | 241 | "bzr": (has_bzr, "Canonical's Bazaar client"), |
|
248 | 242 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), |
|
249 | 243 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), |
|
250 | 244 | "cvs": (has_cvs, "cvs client/server"), |
|
251 | 245 | "darcs": (has_darcs, "darcs client"), |
|
252 | 246 | "docutils": (has_docutils, "Docutils text processing library"), |
|
253 | 247 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
|
254 | 248 | "execbit": (has_executablebit, "executable bit"), |
|
255 | 249 | "fifo": (has_fifo, "named pipes"), |
|
256 | 250 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), |
|
257 | 251 | "git": (has_git, "git command line client"), |
|
258 | 252 | "gpg": (has_gpg, "gpg client"), |
|
259 | 253 | "icasefs": (has_icasefs, "case insensitive file system"), |
|
260 | 254 | "inotify": (has_inotify, "inotify extension support"), |
|
261 | 255 | "lsprof": (has_lsprof, "python lsprof module"), |
|
262 | 256 | "mtn": (has_mtn, "monotone client (>= 1.0)"), |
|
263 | 257 | "outer-repo": (has_outer_repo, "outer repo"), |
|
264 | 258 | "p4": (has_p4, "Perforce server and client"), |
|
265 | 259 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), |
|
266 | 260 | "pygments": (has_pygments, "Pygments source highlighting library"), |
|
267 | 261 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), |
|
268 | 262 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), |
|
269 | 263 | "svn": (has_svn, "subversion client and admin tools"), |
|
270 | 264 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), |
|
271 | 265 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), |
|
272 | 266 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), |
|
273 | 267 | "symlink": (has_symlink, "symbolic links"), |
|
274 | 268 | "system-sh": (has_system_sh, "system() uses sh"), |
|
275 | 269 | "tic": (has_tic, "terminfo compiler"), |
|
276 | 270 | "tla": (has_tla, "GNU Arch tla client"), |
|
277 | 271 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), |
|
278 | 272 | "windows": (has_windows, "Windows"), |
|
279 | 273 | "msys": (has_msys, "Windows with MSYS"), |
|
280 | 274 | } |
|
281 | ||
|
282 | def list_features(): | |
|
283 | for name, feature in checks.iteritems(): | |
|
284 | desc = feature[1] | |
|
285 | print name + ':', desc | |
|
286 | ||
|
287 | def test_features(): | |
|
288 | failed = 0 | |
|
289 | for name, feature in checks.iteritems(): | |
|
290 | check, _ = feature | |
|
291 | try: | |
|
292 | check() | |
|
293 | except Exception, e: | |
|
294 | print "feature %s failed: %s" % (name, e) | |
|
295 | failed += 1 | |
|
296 | return failed | |
|
297 | ||
|
298 | parser = optparse.OptionParser("%prog [options] [features]") | |
|
299 | parser.add_option("--test-features", action="store_true", | |
|
300 | help="test available features") | |
|
301 | parser.add_option("--list-features", action="store_true", | |
|
302 | help="list available features") | |
|
303 | parser.add_option("-q", "--quiet", action="store_true", | |
|
304 | help="check features silently") | |
|
305 | ||
|
306 | if __name__ == '__main__': | |
|
307 | options, args = parser.parse_args() | |
|
308 | if options.list_features: | |
|
309 | list_features() | |
|
310 | sys.exit(0) | |
|
311 | ||
|
312 | if options.test_features: | |
|
313 | sys.exit(test_features()) | |
|
314 | ||
|
315 | quiet = options.quiet | |
|
316 | ||
|
317 | failures = 0 | |
|
318 | ||
|
319 | def error(msg): | |
|
320 | global failures | |
|
321 | if not quiet: | |
|
322 | sys.stderr.write(msg + '\n') | |
|
323 | failures += 1 | |
|
324 | ||
|
325 | for feature in args: | |
|
326 | negate = feature.startswith('no-') | |
|
327 | if negate: | |
|
328 | feature = feature[3:] | |
|
329 | ||
|
330 | if feature not in checks: | |
|
331 | error('skipped: unknown feature: ' + feature) | |
|
332 | continue | |
|
333 | ||
|
334 | check, desc = checks[feature] | |
|
335 | try: | |
|
336 | available = check() | |
|
337 | except Exception, e: | |
|
338 | error('hghave check failed: ' + feature) | |
|
339 | continue | |
|
340 | ||
|
341 | if not negate and not available: | |
|
342 | error('skipped: missing feature: ' + desc) | |
|
343 | elif negate and available: | |
|
344 | error('skipped: system supports %s' % desc) | |
|
345 | ||
|
346 | if failures != 0: | |
|
347 | sys.exit(1) |
General Comments 0
You need to be logged in to leave comments.
Login now