hghave
144 lines
| 3.8 KiB
| text/plain
|
TextLexer
/ tests / hghave
Patrick Mezard
|
r4881 | #!/usr/bin/env python | ||
"""Test the running system for features availability. Exit with zero | ||||
Patrick Mezard
|
r5084 | if all features are there, non-zero otherwise. If a feature name is | ||
prefixed with "no-", the absence of feature is tested. | ||||
Patrick Mezard
|
r4881 | """ | ||
import optparse | ||||
import os | ||||
Patrick Mezard
|
r5252 | import re | ||
Patrick Mezard
|
r4881 | import sys | ||
Patrick Mezard
|
r5072 | import tempfile | ||
Patrick Mezard
|
r4881 | |||
Patrick Mezard
|
r5090 | tempprefix = 'hg-hghave-' | ||
Patrick Mezard
|
r5302 | def matchoutput(cmd, regexp, ignorestatus=False): | ||
Patrick Mezard
|
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() | ||||
ret = fh.close() | ||||
Patrick Mezard
|
r5302 | return (ignorestatus or ret is None) and r.search(s) | ||
Patrick Mezard
|
r5252 | |||
Patrick Mezard
|
r4881 | def has_symlink(): | ||
return hasattr(os, "symlink") | ||||
Patrick Mezard
|
r5070 | def has_fifo(): | ||
return hasattr(os, "mkfifo") | ||||
Patrick Mezard
|
r5302 | def has_cvs(): | ||
return matchoutput('cvs --version 2>&1', r'Concurrent Versions System') | ||||
def has_cvsps(): | ||||
return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True) | ||||
Patrick Mezard
|
r5072 | def has_executablebit(): | ||
Patrick Mezard
|
r5090 | fd, path = tempfile.mkstemp(prefix=tempprefix) | ||
Patrick Mezard
|
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) | ||||
Patrick Mezard
|
r5074 | def has_eol_in_paths(): | ||
try: | ||||
Patrick Mezard
|
r5090 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | ||
Patrick Mezard
|
r5074 | os.close(fd) | ||
os.remove(path) | ||||
return True | ||||
except: | ||||
return False | ||||
Patrick Mezard
|
r5102 | def has_hotshot(): | ||
try: | ||||
Patrick Mezard
|
r5103 | # hotshot.stats tests hotshot and many problematic dependencies | ||
# like profile. | ||||
import hotshot.stats | ||||
Patrick Mezard
|
r5102 | return True | ||
except ImportError: | ||||
return False | ||||
Patrick Mezard
|
r5099 | def has_lsprof(): | ||
try: | ||||
import _lsprof | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
Patrick Mezard
|
r5218 | def has_git(): | ||
Patrick Mezard
|
r5252 | return matchoutput('git --version 2>&1', r'^git version') | ||
Patrick Mezard
|
r5218 | |||
Patrick Mezard
|
r5253 | def has_svn(): | ||
return matchoutput('svn --version 2>&1', r'^svn, version') and \ | ||||
matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') | ||||
Patrick Mezard
|
r5254 | def has_svn_bindings(): | ||
try: | ||||
import svn.core | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
Patrick Mezard
|
r4881 | checks = { | ||
Patrick Mezard
|
r5302 | "cvs": (has_cvs, "cvs client"), | ||
"cvsps": (has_cvsps, "cvsps utility"), | ||||
Patrick Mezard
|
r5099 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | ||
"execbit": (has_executablebit, "executable bit"), | ||||
Patrick Mezard
|
r5218 | "git": (has_git, "git command line client"), | ||
Patrick Mezard
|
r5070 | "fifo": (has_fifo, "named pipes"), | ||
Patrick Mezard
|
r5102 | "hotshot": (has_hotshot, "python hotshot module"), | ||
Patrick Mezard
|
r5099 | "lsprof": (has_lsprof, "python lsprof module"), | ||
Patrick Mezard
|
r5253 | "svn": (has_svn, "subversion client and admin tools"), | ||
Patrick Mezard
|
r5254 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), | ||
Patrick Mezard
|
r5099 | "symlink": (has_symlink, "symbolic links"), | ||
Patrick Mezard
|
r4881 | } | ||
def list_features(): | ||||
for name, feature in checks.iteritems(): | ||||
desc = feature[1] | ||||
print name + ':', desc | ||||
parser = optparse.OptionParser("%prog [options] [features]") | ||||
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) | ||||
Thomas Arendsen Hein
|
r5081 | |||
Patrick Mezard
|
r4881 | quiet = options.quiet | ||
failures = 0 | ||||
def error(msg): | ||||
global failures | ||||
if not quiet: | ||||
sys.stderr.write(msg + '\n') | ||||
failures += 1 | ||||
Thomas Arendsen Hein
|
r5081 | |||
Patrick Mezard
|
r4881 | for feature in args: | ||
Patrick Mezard
|
r5084 | negate = feature.startswith('no-') | ||
if negate: | ||||
feature = feature[3:] | ||||
Thomas Arendsen Hein
|
r5091 | |||
Patrick Mezard
|
r4881 | if feature not in checks: | ||
error('hghave: unknown feature: ' + feature) | ||||
continue | ||||
Thomas Arendsen Hein
|
r5081 | |||
check, desc = checks[feature] | ||||
Patrick Mezard
|
r5084 | if not negate and not check(): | ||
Patrick Mezard
|
r4881 | error('hghave: missing feature: ' + desc) | ||
Patrick Mezard
|
r5084 | elif negate and check(): | ||
Thomas Arendsen Hein
|
r5092 | error('hghave: system supports %s' % desc) | ||
Patrick Mezard
|
r4881 | |||
if failures != 0: | ||||
sys.exit(1) | ||||
Thomas Arendsen Hein
|
r5081 | |||