hghave
325 lines
| 8.9 KiB
| text/plain
|
TextLexer
/ tests / hghave
|
r4881 | #!/usr/bin/env python | ||
"""Test the running system for features availability. Exit with zero | ||||
|
r5084 | if all features are there, non-zero otherwise. If a feature name is | ||
prefixed with "no-", the absence of feature is tested. | ||||
|
r4881 | """ | ||
import optparse | ||||
import os | ||||
|
r5252 | import re | ||
|
r4881 | import sys | ||
|
r5072 | import tempfile | ||
|
r4881 | |||
|
r5090 | tempprefix = 'hg-hghave-' | ||
|
r5302 | def matchoutput(cmd, regexp, ignorestatus=False): | ||
|
r5252 | """Return True if cmd executes successfully and its output | ||
is matched by the supplied regular expression. | ||||
""" | ||||
r = re.compile(regexp) | ||||
fh = os.popen(cmd) | ||||
s = fh.read() | ||||
|
r8213 | try: | ||
ret = fh.close() | ||||
except IOError: | ||||
# Happen in Windows test environment | ||||
ret = 1 | ||||
|
r5302 | return (ignorestatus or ret is None) and r.search(s) | ||
|
r5252 | |||
|
r6078 | def has_baz(): | ||
return matchoutput('baz --version 2>&1', r'baz Bazaar version') | ||||
|
r7053 | def has_bzr(): | ||
|
r7061 | try: | ||
import bzrlib | ||||
|
r7773 | return bzrlib.__doc__ != None | ||
|
r7061 | except ImportError: | ||
return False | ||||
|
r7053 | |||
|
r8126 | def has_bzr114(): | ||
try: | ||||
import bzrlib | ||||
return (bzrlib.__doc__ != None | ||||
|
r9244 | and bzrlib.version_info[:2] >= (1, 14)) | ||
|
r8126 | except ImportError: | ||
return False | ||||
|
r5302 | def has_cvs(): | ||
|
r6626 | re = r'Concurrent Versions System.*?server' | ||
return matchoutput('cvs --version 2>&1', re) | ||||
|
r5302 | |||
|
r5410 | def has_darcs(): | ||
|
r9326 | return matchoutput('darcs --version', r'2\.[2-9]', True) | ||
|
r5410 | |||
|
r6372 | def has_mtn(): | ||
|
r6384 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( | ||
|
r14550 | 'mtn --version', r'monotone 0\.', True) | ||
|
r6372 | |||
|
r5409 | def has_eol_in_paths(): | ||
try: | ||||
fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | ||||
os.close(fd) | ||||
os.remove(path) | ||||
return True | ||||
except: | ||||
return False | ||||
|
r5072 | def has_executablebit(): | ||
|
r5090 | fd, path = tempfile.mkstemp(prefix=tempprefix) | ||
|
r5072 | os.close(fd) | ||
try: | ||||
s = os.lstat(path).st_mode | ||||
os.chmod(path, s | 0100) | ||||
return (os.lstat(path).st_mode & 0100 != 0) | ||||
finally: | ||||
os.remove(path) | ||||
|
r6806 | def has_icasefs(): | ||
# Stolen from mercurial.util | ||||
|
r9395 | fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.') | ||
|
r6806 | os.close(fd) | ||
try: | ||||
s1 = os.stat(path) | ||||
d, b = os.path.split(path) | ||||
p2 = os.path.join(d, b.upper()) | ||||
if path == p2: | ||||
p2 = os.path.join(d, b.lower()) | ||||
try: | ||||
s2 = os.stat(p2) | ||||
return s2 == s1 | ||||
except: | ||||
return False | ||||
finally: | ||||
|
r6998 | os.remove(path) | ||
|
r6996 | def has_inotify(): | ||
try: | ||||
import hgext.inotify.linux.watcher | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
|
r5409 | def has_fifo(): | ||
return hasattr(os, "mkfifo") | ||||
|
r5074 | |||
|
r14927 | def has_cacheable_fs(): | ||
from mercurial import util | ||||
fd, path = tempfile.mkstemp(prefix=tempprefix) | ||||
os.close(fd) | ||||
try: | ||||
return util.cachestat(path).cacheable() | ||||
finally: | ||||
os.remove(path) | ||||
|
r5099 | def has_lsprof(): | ||
try: | ||||
import _lsprof | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
|
r13442 | def has_gettext(): | ||
return matchoutput('msgfmt --version', 'GNU gettext-tools') | ||||
|
r5218 | def has_git(): | ||
|
r5252 | return matchoutput('git --version 2>&1', r'^git version') | ||
|
r5218 | |||
|
r10971 | def has_docutils(): | ||
try: | ||||
from docutils.core import publish_cmdline | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
|
r9446 | |||
|
r14050 | def getsvnversion(): | ||
m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') | ||||
if not m: | ||||
return (0, 0) | ||||
return (int(m.group(1)), int(m.group(2))) | ||||
def has_svn15(): | ||||
return getsvnversion() >= (1, 5) | ||||
|
r15346 | def has_svn13(): | ||
return getsvnversion() >= (1, 3) | ||||
|
r5253 | def has_svn(): | ||
|
r9819 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ | ||
matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') | ||||
|
r5253 | |||
|
r5254 | def has_svn_bindings(): | ||
try: | ||||
import svn.core | ||||
|
r7315 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR | ||
if version < (1, 4): | ||||
return False | ||||
|
r5254 | return True | ||
except ImportError: | ||||
return False | ||||
|
r7823 | def has_p4(): | ||
return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/') | ||||
|
r5409 | def has_symlink(): | ||
|
r15441 | return hasattr(os, "symlink") # FIXME: should also check file system and os | ||
|
r5409 | |||
|
r6079 | def has_tla(): | ||
return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') | ||||
|
r8809 | def has_gpg(): | ||
return matchoutput('gpg --version 2>&1', r'GnuPG') | ||||
|
r6063 | def has_unix_permissions(): | ||
d = tempfile.mkdtemp(prefix=tempprefix, dir=".") | ||||
try: | ||||
fname = os.path.join(d, 'foo') | ||||
for umask in (077, 007, 022): | ||||
os.umask(umask) | ||||
f = open(fname, 'w') | ||||
f.close() | ||||
mode = os.stat(fname).st_mode | ||||
os.unlink(fname) | ||||
if mode & 0777 != ~umask & 0666: | ||||
return False | ||||
return True | ||||
finally: | ||||
os.rmdir(d) | ||||
|
r14140 | def has_pyflakes(): | ||
return matchoutput('echo "import re" 2>&1 | pyflakes', | ||||
r"<stdin>:1: 're' imported but unused", | ||||
True) | ||||
|
r6355 | def has_pygments(): | ||
try: | ||||
import pygments | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
|
r7429 | def has_outer_repo(): | ||
return matchoutput('hg root 2>&1', r'') | ||||
|
r12740 | def has_ssl(): | ||
try: | ||||
import ssl | ||||
|
r13418 | import OpenSSL | ||
OpenSSL.SSL.Context | ||||
|
r12740 | return True | ||
except ImportError: | ||||
return False | ||||
|
r15444 | def has_windows(): | ||
return os.name == 'nt' | ||||
|
r15445 | def has_system_sh(): | ||
return os.name != 'nt' | ||||
|
r15446 | def has_serve(): | ||
return os.name != 'nt' # gross approximation | ||||
|
r15539 | def has_tic(): | ||
return matchoutput('test -x "`which tic`"', '') | ||||
|
r4881 | checks = { | ||
|
r6078 | "baz": (has_baz, "GNU Arch baz client"), | ||
|
r7053 | "bzr": (has_bzr, "Canonical's Bazaar client"), | ||
|
r8126 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), | ||
|
r14927 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), | ||
|
r6626 | "cvs": (has_cvs, "cvs client/server"), | ||
|
r5410 | "darcs": (has_darcs, "darcs client"), | ||
|
r12740 | "docutils": (has_docutils, "Docutils text processing library"), | ||
|
r5099 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | ||
"execbit": (has_executablebit, "executable bit"), | ||||
|
r5409 | "fifo": (has_fifo, "named pipes"), | ||
|
r13442 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), | ||
|
r5218 | "git": (has_git, "git command line client"), | ||
|
r8809 | "gpg": (has_gpg, "gpg client"), | ||
|
r6806 | "icasefs": (has_icasefs, "case insensitive file system"), | ||
|
r6996 | "inotify": (has_inotify, "inotify extension support"), | ||
|
r5099 | "lsprof": (has_lsprof, "python lsprof module"), | ||
|
r14432 | "mtn": (has_mtn, "monotone client (>= 1.0)"), | ||
|
r7429 | "outer-repo": (has_outer_repo, "outer repo"), | ||
|
r7823 | "p4": (has_p4, "Perforce server and client"), | ||
|
r14140 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), | ||
|
r6996 | "pygments": (has_pygments, "Pygments source highlighting library"), | ||
|
r15446 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), | ||
|
r13543 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), | ||
|
r5253 | "svn": (has_svn, "subversion client and admin tools"), | ||
|
r15346 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), | ||
|
r14050 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), | ||
|
r5254 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), | ||
|
r5099 | "symlink": (has_symlink, "symbolic links"), | ||
|
r15445 | "system-sh": (has_system_sh, "system() uses sh"), | ||
|
r15539 | "tic": (has_tic, "terminfo compiler"), | ||
|
r6079 | "tla": (has_tla, "GNU Arch tla client"), | ||
|
r6063 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), | ||
|
r15444 | "windows": (has_windows, "Windows"), | ||
|
r4881 | } | ||
def list_features(): | ||||
for name, feature in checks.iteritems(): | ||||
desc = feature[1] | ||||
print name + ':', desc | ||||
|
r8059 | def test_features(): | ||
failed = 0 | ||||
for name, feature in checks.iteritems(): | ||||
check, _ = feature | ||||
try: | ||||
check() | ||||
except Exception, e: | ||||
print "feature %s failed: %s" % (name, e) | ||||
failed += 1 | ||||
return failed | ||||
|
r4881 | parser = optparse.OptionParser("%prog [options] [features]") | ||
|
r8059 | parser.add_option("--test-features", action="store_true", | ||
help="test available features") | ||||
|
r4881 | parser.add_option("--list-features", action="store_true", | ||
help="list available features") | ||||
parser.add_option("-q", "--quiet", action="store_true", | ||||
help="check features silently") | ||||
if __name__ == '__main__': | ||||
options, args = parser.parse_args() | ||||
if options.list_features: | ||||
list_features() | ||||
sys.exit(0) | ||||
|
r5081 | |||
|
r8059 | if options.test_features: | ||
sys.exit(test_features()) | ||||
|
r4881 | quiet = options.quiet | ||
failures = 0 | ||||
def error(msg): | ||||
global failures | ||||
if not quiet: | ||||
sys.stderr.write(msg + '\n') | ||||
failures += 1 | ||||
|
r5081 | |||
|
r4881 | for feature in args: | ||
|
r5084 | negate = feature.startswith('no-') | ||
if negate: | ||||
feature = feature[3:] | ||||
|
r5091 | |||
|
r4881 | if feature not in checks: | ||
|
r5685 | error('skipped: unknown feature: ' + feature) | ||
|
r4881 | continue | ||
|
r5081 | |||
check, desc = checks[feature] | ||||
|
r8060 | try: | ||
available = check() | ||||
except Exception, e: | ||||
error('hghave check failed: ' + feature) | ||||
continue | ||||
if not negate and not available: | ||||
|
r5685 | error('skipped: missing feature: ' + desc) | ||
|
r8060 | elif negate and available: | ||
|
r5685 | error('skipped: system supports %s' % desc) | ||
|
r4881 | |||
if failures != 0: | ||||
sys.exit(1) | ||||