hghave
108 lines
| 2.7 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 | ||||
import sys | ||||
|
r5072 | import tempfile | ||
|
r4881 | |||
|
r5090 | tempprefix = 'hg-hghave-' | ||
|
r4881 | def has_symlink(): | ||
return hasattr(os, "symlink") | ||||
|
r5070 | def has_fifo(): | ||
return hasattr(os, "mkfifo") | ||||
|
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) | ||||
|
r5074 | def has_eol_in_paths(): | ||
try: | ||||
|
r5090 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') | ||
|
r5074 | os.close(fd) | ||
os.remove(path) | ||||
return True | ||||
except: | ||||
return False | ||||
|
r5102 | def has_hotshot(): | ||
try: | ||||
|
r5103 | # hotshot.stats tests hotshot and many problematic dependencies | ||
# like profile. | ||||
import hotshot.stats | ||||
|
r5102 | return True | ||
except ImportError: | ||||
return False | ||||
|
r5099 | def has_lsprof(): | ||
try: | ||||
import _lsprof | ||||
return True | ||||
except ImportError: | ||||
return False | ||||
|
r4881 | checks = { | ||
|
r5099 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | ||
"execbit": (has_executablebit, "executable bit"), | ||||
|
r5070 | "fifo": (has_fifo, "named pipes"), | ||
|
r5102 | "hotshot": (has_hotshot, "python hotshot module"), | ||
|
r5099 | "lsprof": (has_lsprof, "python lsprof module"), | ||
"symlink": (has_symlink, "symbolic links"), | ||||
|
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) | ||||
|
r5081 | |||
|
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: | ||
error('hghave: unknown feature: ' + feature) | ||||
continue | ||||
|
r5081 | |||
check, desc = checks[feature] | ||||
|
r5084 | if not negate and not check(): | ||
|
r4881 | error('hghave: missing feature: ' + desc) | ||
|
r5084 | elif negate and check(): | ||
|
r5092 | error('hghave: system supports %s' % desc) | ||
|
r4881 | |||
if failures != 0: | ||||
sys.exit(1) | ||||
|
r5081 | |||