##// END OF EJS Templates
hghave: remove quiet option...
Gregory Szorc -
r26068:05e7f57c default
parent child Browse files
Show More
@@ -1,67 +1,64 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, sys
7 import os, sys
8 import hghave
8 import hghave
9
9
10 checks = hghave.checks
10 checks = hghave.checks
11
11
12 def list_features():
12 def list_features():
13 for name, feature in sorted(checks.iteritems()):
13 for name, feature in sorted(checks.iteritems()):
14 desc = feature[1]
14 desc = feature[1]
15 print name + ':', desc
15 print name + ':', desc
16
16
17 def test_features():
17 def test_features():
18 failed = 0
18 failed = 0
19 for name, feature in checks.iteritems():
19 for name, feature in checks.iteritems():
20 check, _ = feature
20 check, _ = feature
21 try:
21 try:
22 check()
22 check()
23 except Exception, e:
23 except Exception, e:
24 print "feature %s failed: %s" % (name, e)
24 print "feature %s failed: %s" % (name, e)
25 failed += 1
25 failed += 1
26 return failed
26 return failed
27
27
28 parser = optparse.OptionParser("%prog [options] [features]")
28 parser = optparse.OptionParser("%prog [options] [features]")
29 parser.add_option("--test-features", action="store_true",
29 parser.add_option("--test-features", action="store_true",
30 help="test available features")
30 help="test available features")
31 parser.add_option("--list-features", action="store_true",
31 parser.add_option("--list-features", action="store_true",
32 help="list available features")
32 help="list available features")
33 parser.add_option("-q", "--quiet", action="store_true",
34 help="check features silently")
35
33
36 def _loadaddon(quiet):
34 def _loadaddon():
37 if 'TESTDIR' in os.environ:
35 if 'TESTDIR' in os.environ:
38 # loading from '.' isn't needed, because `hghave` should be
36 # loading from '.' isn't needed, because `hghave` should be
39 # running at TESTTMP in this case
37 # running at TESTTMP in this case
40 path = os.environ['TESTDIR']
38 path = os.environ['TESTDIR']
41 else:
39 else:
42 path = '.'
40 path = '.'
43
41
44 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
42 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
45 return
43 return
46
44
47 sys.path.insert(0, path)
45 sys.path.insert(0, path)
48 try:
46 try:
49 import hghaveaddon
47 import hghaveaddon
50 except BaseException, inst:
48 except BaseException, inst:
51 if not quiet:
49 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
52 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
50 % (path, inst))
53 % (path, inst))
54 sys.exit(2)
51 sys.exit(2)
55 sys.path.pop(0)
52 sys.path.pop(0)
56
53
57 if __name__ == '__main__':
54 if __name__ == '__main__':
58 options, args = parser.parse_args()
55 options, args = parser.parse_args()
59 _loadaddon(options.quiet)
56 _loadaddon()
60 if options.list_features:
57 if options.list_features:
61 list_features()
58 list_features()
62 sys.exit(0)
59 sys.exit(0)
63
60
64 if options.test_features:
61 if options.test_features:
65 sys.exit(test_features())
62 sys.exit(test_features())
66
63
67 hghave.require(args, options.quiet)
64 hghave.require(args)
@@ -1,430 +1,429 b''
1 import os, stat
1 import os, stat
2 import re
2 import re
3 import socket
3 import socket
4 import sys
4 import sys
5 import tempfile
5 import tempfile
6
6
7 tempprefix = 'hg-hghave-'
7 tempprefix = 'hg-hghave-'
8
8
9 checks = {
9 checks = {
10 "true": (lambda: True, "yak shaving"),
10 "true": (lambda: True, "yak shaving"),
11 "false": (lambda: False, "nail clipper"),
11 "false": (lambda: False, "nail clipper"),
12 }
12 }
13
13
14 def check(name, desc):
14 def check(name, desc):
15 def decorator(func):
15 def decorator(func):
16 checks[name] = (func, desc)
16 checks[name] = (func, desc)
17 return func
17 return func
18 return decorator
18 return decorator
19
19
20 def checkfeatures(features):
20 def checkfeatures(features):
21 result = {
21 result = {
22 'error': [],
22 'error': [],
23 'missing': [],
23 'missing': [],
24 'skipped': [],
24 'skipped': [],
25 }
25 }
26
26
27 for feature in features:
27 for feature in features:
28 negate = feature.startswith('no-')
28 negate = feature.startswith('no-')
29 if negate:
29 if negate:
30 feature = feature[3:]
30 feature = feature[3:]
31
31
32 if feature not in checks:
32 if feature not in checks:
33 result['missing'].append(feature)
33 result['missing'].append(feature)
34 continue
34 continue
35
35
36 check, desc = checks[feature]
36 check, desc = checks[feature]
37 try:
37 try:
38 available = check()
38 available = check()
39 except Exception:
39 except Exception:
40 result['error'].append('hghave check failed: %s' % feature)
40 result['error'].append('hghave check failed: %s' % feature)
41 continue
41 continue
42
42
43 if not negate and not available:
43 if not negate and not available:
44 result['skipped'].append('missing feature: %s' % desc)
44 result['skipped'].append('missing feature: %s' % desc)
45 elif negate and available:
45 elif negate and available:
46 result['skipped'].append('system supports %s' % desc)
46 result['skipped'].append('system supports %s' % desc)
47
47
48 return result
48 return result
49
49
50 def require(features, quiet=False):
50 def require(features):
51 """Require that features are available, exiting if not."""
51 """Require that features are available, exiting if not."""
52 result = checkfeatures(features)
52 result = checkfeatures(features)
53
53
54 if not quiet:
54 for missing in result['missing']:
55 for missing in result['missing']:
55 sys.stderr.write('skipped: unknown feature: %s\n' % missing)
56 sys.stderr.write('skipped: unknown feature: %s\n' % missing)
56 for msg in result['skipped']:
57 for msg in result['skipped']:
57 sys.stderr.write('skipped: %s\n' % msg)
58 sys.stderr.write('skipped: %s\n' % msg)
58 for msg in result['error']:
59 for msg in result['error']:
59 sys.stderr.write('%s\n' % msg)
60 sys.stderr.write('%s\n' % msg)
61
60
62 if result['missing']:
61 if result['missing']:
63 sys.exit(2)
62 sys.exit(2)
64
63
65 if result['skipped'] or result['error']:
64 if result['skipped'] or result['error']:
66 sys.exit(1)
65 sys.exit(1)
67
66
68 def matchoutput(cmd, regexp, ignorestatus=False):
67 def matchoutput(cmd, regexp, ignorestatus=False):
69 """Return True if cmd executes successfully and its output
68 """Return True if cmd executes successfully and its output
70 is matched by the supplied regular expression.
69 is matched by the supplied regular expression.
71 """
70 """
72 r = re.compile(regexp)
71 r = re.compile(regexp)
73 fh = os.popen(cmd)
72 fh = os.popen(cmd)
74 s = fh.read()
73 s = fh.read()
75 try:
74 try:
76 ret = fh.close()
75 ret = fh.close()
77 except IOError:
76 except IOError:
78 # Happen in Windows test environment
77 # Happen in Windows test environment
79 ret = 1
78 ret = 1
80 return (ignorestatus or ret is None) and r.search(s)
79 return (ignorestatus or ret is None) and r.search(s)
81
80
82 @check("baz", "GNU Arch baz client")
81 @check("baz", "GNU Arch baz client")
83 def has_baz():
82 def has_baz():
84 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
83 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
85
84
86 @check("bzr", "Canonical's Bazaar client")
85 @check("bzr", "Canonical's Bazaar client")
87 def has_bzr():
86 def has_bzr():
88 try:
87 try:
89 import bzrlib
88 import bzrlib
90 return bzrlib.__doc__ is not None
89 return bzrlib.__doc__ is not None
91 except ImportError:
90 except ImportError:
92 return False
91 return False
93
92
94 @check("bzr114", "Canonical's Bazaar client >= 1.14")
93 @check("bzr114", "Canonical's Bazaar client >= 1.14")
95 def has_bzr114():
94 def has_bzr114():
96 try:
95 try:
97 import bzrlib
96 import bzrlib
98 return (bzrlib.__doc__ is not None
97 return (bzrlib.__doc__ is not None
99 and bzrlib.version_info[:2] >= (1, 14))
98 and bzrlib.version_info[:2] >= (1, 14))
100 except ImportError:
99 except ImportError:
101 return False
100 return False
102
101
103 @check("cvs", "cvs client/server")
102 @check("cvs", "cvs client/server")
104 def has_cvs():
103 def has_cvs():
105 re = r'Concurrent Versions System.*?server'
104 re = r'Concurrent Versions System.*?server'
106 return matchoutput('cvs --version 2>&1', re) and not has_msys()
105 return matchoutput('cvs --version 2>&1', re) and not has_msys()
107
106
108 @check("cvs112", "cvs client/server >= 1.12")
107 @check("cvs112", "cvs client/server >= 1.12")
109 def has_cvs112():
108 def has_cvs112():
110 re = r'Concurrent Versions System \(CVS\) 1.12.*?server'
109 re = r'Concurrent Versions System \(CVS\) 1.12.*?server'
111 return matchoutput('cvs --version 2>&1', re) and not has_msys()
110 return matchoutput('cvs --version 2>&1', re) and not has_msys()
112
111
113 @check("darcs", "darcs client")
112 @check("darcs", "darcs client")
114 def has_darcs():
113 def has_darcs():
115 return matchoutput('darcs --version', r'2\.[2-9]', True)
114 return matchoutput('darcs --version', r'2\.[2-9]', True)
116
115
117 @check("mtn", "monotone client (>= 1.0)")
116 @check("mtn", "monotone client (>= 1.0)")
118 def has_mtn():
117 def has_mtn():
119 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
118 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
120 'mtn --version', r'monotone 0\.', True)
119 'mtn --version', r'monotone 0\.', True)
121
120
122 @check("eol-in-paths", "end-of-lines in paths")
121 @check("eol-in-paths", "end-of-lines in paths")
123 def has_eol_in_paths():
122 def has_eol_in_paths():
124 try:
123 try:
125 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
124 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
126 os.close(fd)
125 os.close(fd)
127 os.remove(path)
126 os.remove(path)
128 return True
127 return True
129 except (IOError, OSError):
128 except (IOError, OSError):
130 return False
129 return False
131
130
132 @check("execbit", "executable bit")
131 @check("execbit", "executable bit")
133 def has_executablebit():
132 def has_executablebit():
134 try:
133 try:
135 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
134 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
136 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
135 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
137 try:
136 try:
138 os.close(fh)
137 os.close(fh)
139 m = os.stat(fn).st_mode & 0o777
138 m = os.stat(fn).st_mode & 0o777
140 new_file_has_exec = m & EXECFLAGS
139 new_file_has_exec = m & EXECFLAGS
141 os.chmod(fn, m ^ EXECFLAGS)
140 os.chmod(fn, m ^ EXECFLAGS)
142 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
141 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m)
143 finally:
142 finally:
144 os.unlink(fn)
143 os.unlink(fn)
145 except (IOError, OSError):
144 except (IOError, OSError):
146 # we don't care, the user probably won't be able to commit anyway
145 # we don't care, the user probably won't be able to commit anyway
147 return False
146 return False
148 return not (new_file_has_exec or exec_flags_cannot_flip)
147 return not (new_file_has_exec or exec_flags_cannot_flip)
149
148
150 @check("icasefs", "case insensitive file system")
149 @check("icasefs", "case insensitive file system")
151 def has_icasefs():
150 def has_icasefs():
152 # Stolen from mercurial.util
151 # Stolen from mercurial.util
153 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
152 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
154 os.close(fd)
153 os.close(fd)
155 try:
154 try:
156 s1 = os.stat(path)
155 s1 = os.stat(path)
157 d, b = os.path.split(path)
156 d, b = os.path.split(path)
158 p2 = os.path.join(d, b.upper())
157 p2 = os.path.join(d, b.upper())
159 if path == p2:
158 if path == p2:
160 p2 = os.path.join(d, b.lower())
159 p2 = os.path.join(d, b.lower())
161 try:
160 try:
162 s2 = os.stat(p2)
161 s2 = os.stat(p2)
163 return s2 == s1
162 return s2 == s1
164 except OSError:
163 except OSError:
165 return False
164 return False
166 finally:
165 finally:
167 os.remove(path)
166 os.remove(path)
168
167
169 @check("fifo", "named pipes")
168 @check("fifo", "named pipes")
170 def has_fifo():
169 def has_fifo():
171 if getattr(os, "mkfifo", None) is None:
170 if getattr(os, "mkfifo", None) is None:
172 return False
171 return False
173 name = tempfile.mktemp(dir='.', prefix=tempprefix)
172 name = tempfile.mktemp(dir='.', prefix=tempprefix)
174 try:
173 try:
175 os.mkfifo(name)
174 os.mkfifo(name)
176 os.unlink(name)
175 os.unlink(name)
177 return True
176 return True
178 except OSError:
177 except OSError:
179 return False
178 return False
180
179
181 @check("killdaemons", 'killdaemons.py support')
180 @check("killdaemons", 'killdaemons.py support')
182 def has_killdaemons():
181 def has_killdaemons():
183 return True
182 return True
184
183
185 @check("cacheable", "cacheable filesystem")
184 @check("cacheable", "cacheable filesystem")
186 def has_cacheable_fs():
185 def has_cacheable_fs():
187 from mercurial import util
186 from mercurial import util
188
187
189 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
188 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
190 os.close(fd)
189 os.close(fd)
191 try:
190 try:
192 return util.cachestat(path).cacheable()
191 return util.cachestat(path).cacheable()
193 finally:
192 finally:
194 os.remove(path)
193 os.remove(path)
195
194
196 @check("lsprof", "python lsprof module")
195 @check("lsprof", "python lsprof module")
197 def has_lsprof():
196 def has_lsprof():
198 try:
197 try:
199 import _lsprof
198 import _lsprof
200 _lsprof.Profiler # silence unused import warning
199 _lsprof.Profiler # silence unused import warning
201 return True
200 return True
202 except ImportError:
201 except ImportError:
203 return False
202 return False
204
203
205 @check("gettext", "GNU Gettext (msgfmt)")
204 @check("gettext", "GNU Gettext (msgfmt)")
206 def has_gettext():
205 def has_gettext():
207 return matchoutput('msgfmt --version', 'GNU gettext-tools')
206 return matchoutput('msgfmt --version', 'GNU gettext-tools')
208
207
209 @check("git", "git command line client")
208 @check("git", "git command line client")
210 def has_git():
209 def has_git():
211 return matchoutput('git --version 2>&1', r'^git version')
210 return matchoutput('git --version 2>&1', r'^git version')
212
211
213 @check("docutils", "Docutils text processing library")
212 @check("docutils", "Docutils text processing library")
214 def has_docutils():
213 def has_docutils():
215 try:
214 try:
216 from docutils.core import publish_cmdline
215 from docutils.core import publish_cmdline
217 publish_cmdline # silence unused import
216 publish_cmdline # silence unused import
218 return True
217 return True
219 except ImportError:
218 except ImportError:
220 return False
219 return False
221
220
222 def getsvnversion():
221 def getsvnversion():
223 m = matchoutput('svn --version --quiet 2>&1', r'^(\d+)\.(\d+)')
222 m = matchoutput('svn --version --quiet 2>&1', r'^(\d+)\.(\d+)')
224 if not m:
223 if not m:
225 return (0, 0)
224 return (0, 0)
226 return (int(m.group(1)), int(m.group(2)))
225 return (int(m.group(1)), int(m.group(2)))
227
226
228 @check("svn15", "subversion client and admin tools >= 1.5")
227 @check("svn15", "subversion client and admin tools >= 1.5")
229 def has_svn15():
228 def has_svn15():
230 return getsvnversion() >= (1, 5)
229 return getsvnversion() >= (1, 5)
231
230
232 @check("svn13", "subversion client and admin tools >= 1.3")
231 @check("svn13", "subversion client and admin tools >= 1.3")
233 def has_svn13():
232 def has_svn13():
234 return getsvnversion() >= (1, 3)
233 return getsvnversion() >= (1, 3)
235
234
236 @check("svn", "subversion client and admin tools")
235 @check("svn", "subversion client and admin tools")
237 def has_svn():
236 def has_svn():
238 return matchoutput('svn --version 2>&1', r'^svn, version') and \
237 return matchoutput('svn --version 2>&1', r'^svn, version') and \
239 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
238 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
240
239
241 @check("svn-bindings", "subversion python bindings")
240 @check("svn-bindings", "subversion python bindings")
242 def has_svn_bindings():
241 def has_svn_bindings():
243 try:
242 try:
244 import svn.core
243 import svn.core
245 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
244 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
246 if version < (1, 4):
245 if version < (1, 4):
247 return False
246 return False
248 return True
247 return True
249 except ImportError:
248 except ImportError:
250 return False
249 return False
251
250
252 @check("p4", "Perforce server and client")
251 @check("p4", "Perforce server and client")
253 def has_p4():
252 def has_p4():
254 return (matchoutput('p4 -V', r'Rev\. P4/') and
253 return (matchoutput('p4 -V', r'Rev\. P4/') and
255 matchoutput('p4d -V', r'Rev\. P4D/'))
254 matchoutput('p4d -V', r'Rev\. P4D/'))
256
255
257 @check("symlink", "symbolic links")
256 @check("symlink", "symbolic links")
258 def has_symlink():
257 def has_symlink():
259 if getattr(os, "symlink", None) is None:
258 if getattr(os, "symlink", None) is None:
260 return False
259 return False
261 name = tempfile.mktemp(dir='.', prefix=tempprefix)
260 name = tempfile.mktemp(dir='.', prefix=tempprefix)
262 try:
261 try:
263 os.symlink(".", name)
262 os.symlink(".", name)
264 os.unlink(name)
263 os.unlink(name)
265 return True
264 return True
266 except (OSError, AttributeError):
265 except (OSError, AttributeError):
267 return False
266 return False
268
267
269 @check("hardlink", "hardlinks")
268 @check("hardlink", "hardlinks")
270 def has_hardlink():
269 def has_hardlink():
271 from mercurial import util
270 from mercurial import util
272 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
271 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
273 os.close(fh)
272 os.close(fh)
274 name = tempfile.mktemp(dir='.', prefix=tempprefix)
273 name = tempfile.mktemp(dir='.', prefix=tempprefix)
275 try:
274 try:
276 util.oslink(fn, name)
275 util.oslink(fn, name)
277 os.unlink(name)
276 os.unlink(name)
278 return True
277 return True
279 except OSError:
278 except OSError:
280 return False
279 return False
281 finally:
280 finally:
282 os.unlink(fn)
281 os.unlink(fn)
283
282
284 @check("tla", "GNU Arch tla client")
283 @check("tla", "GNU Arch tla client")
285 def has_tla():
284 def has_tla():
286 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
285 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
287
286
288 @check("gpg", "gpg client")
287 @check("gpg", "gpg client")
289 def has_gpg():
288 def has_gpg():
290 return matchoutput('gpg --version 2>&1', r'GnuPG')
289 return matchoutput('gpg --version 2>&1', r'GnuPG')
291
290
292 @check("unix-permissions", "unix-style permissions")
291 @check("unix-permissions", "unix-style permissions")
293 def has_unix_permissions():
292 def has_unix_permissions():
294 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
293 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
295 try:
294 try:
296 fname = os.path.join(d, 'foo')
295 fname = os.path.join(d, 'foo')
297 for umask in (0o77, 0o07, 0o22):
296 for umask in (0o77, 0o07, 0o22):
298 os.umask(umask)
297 os.umask(umask)
299 f = open(fname, 'w')
298 f = open(fname, 'w')
300 f.close()
299 f.close()
301 mode = os.stat(fname).st_mode
300 mode = os.stat(fname).st_mode
302 os.unlink(fname)
301 os.unlink(fname)
303 if mode & 0o777 != ~umask & 0o666:
302 if mode & 0o777 != ~umask & 0o666:
304 return False
303 return False
305 return True
304 return True
306 finally:
305 finally:
307 os.rmdir(d)
306 os.rmdir(d)
308
307
309 @check("unix-socket", "AF_UNIX socket family")
308 @check("unix-socket", "AF_UNIX socket family")
310 def has_unix_socket():
309 def has_unix_socket():
311 return getattr(socket, 'AF_UNIX', None) is not None
310 return getattr(socket, 'AF_UNIX', None) is not None
312
311
313 @check("root", "root permissions")
312 @check("root", "root permissions")
314 def has_root():
313 def has_root():
315 return getattr(os, 'geteuid', None) and os.geteuid() == 0
314 return getattr(os, 'geteuid', None) and os.geteuid() == 0
316
315
317 @check("pyflakes", "Pyflakes python linter")
316 @check("pyflakes", "Pyflakes python linter")
318 def has_pyflakes():
317 def has_pyflakes():
319 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
318 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
320 r"<stdin>:1: 're' imported but unused",
319 r"<stdin>:1: 're' imported but unused",
321 True)
320 True)
322
321
323 @check("pygments", "Pygments source highlighting library")
322 @check("pygments", "Pygments source highlighting library")
324 def has_pygments():
323 def has_pygments():
325 try:
324 try:
326 import pygments
325 import pygments
327 pygments.highlight # silence unused import warning
326 pygments.highlight # silence unused import warning
328 return True
327 return True
329 except ImportError:
328 except ImportError:
330 return False
329 return False
331
330
332 @check("json", "some json module available")
331 @check("json", "some json module available")
333 def has_json():
332 def has_json():
334 try:
333 try:
335 import json
334 import json
336 json.dumps
335 json.dumps
337 return True
336 return True
338 except ImportError:
337 except ImportError:
339 try:
338 try:
340 import simplejson as json
339 import simplejson as json
341 json.dumps
340 json.dumps
342 return True
341 return True
343 except ImportError:
342 except ImportError:
344 pass
343 pass
345 return False
344 return False
346
345
347 @check("outer-repo", "outer repo")
346 @check("outer-repo", "outer repo")
348 def has_outer_repo():
347 def has_outer_repo():
349 # failing for other reasons than 'no repo' imply that there is a repo
348 # failing for other reasons than 'no repo' imply that there is a repo
350 return not matchoutput('hg root 2>&1',
349 return not matchoutput('hg root 2>&1',
351 r'abort: no repository found', True)
350 r'abort: no repository found', True)
352
351
353 @check("ssl", ("(python >= 2.6 ssl module and python OpenSSL) "
352 @check("ssl", ("(python >= 2.6 ssl module and python OpenSSL) "
354 "OR python >= 2.7.9 ssl"))
353 "OR python >= 2.7.9 ssl"))
355 def has_ssl():
354 def has_ssl():
356 try:
355 try:
357 import ssl
356 import ssl
358 if getattr(ssl, 'create_default_context', False):
357 if getattr(ssl, 'create_default_context', False):
359 return True
358 return True
360 import OpenSSL
359 import OpenSSL
361 OpenSSL.SSL.Context
360 OpenSSL.SSL.Context
362 return True
361 return True
363 except ImportError:
362 except ImportError:
364 return False
363 return False
365
364
366 @check("sslcontext", "python >= 2.7.9 ssl")
365 @check("sslcontext", "python >= 2.7.9 ssl")
367 def has_sslcontext():
366 def has_sslcontext():
368 try:
367 try:
369 import ssl
368 import ssl
370 ssl.SSLContext
369 ssl.SSLContext
371 return True
370 return True
372 except (ImportError, AttributeError):
371 except (ImportError, AttributeError):
373 return False
372 return False
374
373
375 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
374 @check("defaultcacerts", "can verify SSL certs by system's CA certs store")
376 def has_defaultcacerts():
375 def has_defaultcacerts():
377 from mercurial import sslutil
376 from mercurial import sslutil
378 return sslutil._defaultcacerts() != '!'
377 return sslutil._defaultcacerts() != '!'
379
378
380 @check("windows", "Windows")
379 @check("windows", "Windows")
381 def has_windows():
380 def has_windows():
382 return os.name == 'nt'
381 return os.name == 'nt'
383
382
384 @check("system-sh", "system() uses sh")
383 @check("system-sh", "system() uses sh")
385 def has_system_sh():
384 def has_system_sh():
386 return os.name != 'nt'
385 return os.name != 'nt'
387
386
388 @check("serve", "platform and python can manage 'hg serve -d'")
387 @check("serve", "platform and python can manage 'hg serve -d'")
389 def has_serve():
388 def has_serve():
390 return os.name != 'nt' # gross approximation
389 return os.name != 'nt' # gross approximation
391
390
392 @check("test-repo", "running tests from repository")
391 @check("test-repo", "running tests from repository")
393 def has_test_repo():
392 def has_test_repo():
394 t = os.environ["TESTDIR"]
393 t = os.environ["TESTDIR"]
395 return os.path.isdir(os.path.join(t, "..", ".hg"))
394 return os.path.isdir(os.path.join(t, "..", ".hg"))
396
395
397 @check("tic", "terminfo compiler and curses module")
396 @check("tic", "terminfo compiler and curses module")
398 def has_tic():
397 def has_tic():
399 try:
398 try:
400 import curses
399 import curses
401 curses.COLOR_BLUE
400 curses.COLOR_BLUE
402 return matchoutput('test -x "`which tic`"', '')
401 return matchoutput('test -x "`which tic`"', '')
403 except ImportError:
402 except ImportError:
404 return False
403 return False
405
404
406 @check("msys", "Windows with MSYS")
405 @check("msys", "Windows with MSYS")
407 def has_msys():
406 def has_msys():
408 return os.getenv('MSYSTEM')
407 return os.getenv('MSYSTEM')
409
408
410 @check("aix", "AIX")
409 @check("aix", "AIX")
411 def has_aix():
410 def has_aix():
412 return sys.platform.startswith("aix")
411 return sys.platform.startswith("aix")
413
412
414 @check("osx", "OS X")
413 @check("osx", "OS X")
415 def has_osx():
414 def has_osx():
416 return sys.platform == 'darwin'
415 return sys.platform == 'darwin'
417
416
418 @check("absimport", "absolute_import in __future__")
417 @check("absimport", "absolute_import in __future__")
419 def has_absimport():
418 def has_absimport():
420 import __future__
419 import __future__
421 from mercurial import util
420 from mercurial import util
422 return util.safehasattr(__future__, "absolute_import")
421 return util.safehasattr(__future__, "absolute_import")
423
422
424 @check("py3k", "running with Python 3.x")
423 @check("py3k", "running with Python 3.x")
425 def has_py3k():
424 def has_py3k():
426 return 3 == sys.version_info[0]
425 return 3 == sys.version_info[0]
427
426
428 @check("pure", "running with pure Python code")
427 @check("pure", "running with pure Python code")
429 def has_pure():
428 def has_pure():
430 return os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure"
429 return os.environ.get("HGTEST_RUN_TESTS_PURE") == "--pure"
General Comments 0
You need to be logged in to leave comments. Login now