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, stat |
|
8 import re |
|
9 import sys |
7 import sys |
10 import tempfile |
8 import hghave |
11 |
9 |
12 tempprefix = 'hg-hghave-' |
10 checks = hghave.checks |
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 |
|
140 |
|
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 } |
|
281 |
11 |
282 def list_features(): |
12 def list_features(): |
283 for name, feature in checks.iteritems(): |
13 for name, feature in checks.iteritems(): |
284 desc = feature[1] |
14 desc = feature[1] |
285 print name + ':', desc |
15 print name + ':', desc |