##// END OF EJS Templates
hghave: detect cvs and cvsps availability...
Patrick Mezard -
r5302:96187683 default
parent child Browse files
Show More
@@ -1,123 +1,131 b''
1 1 #!/usr/bin/env python
2 2 """Test the running system for features availability. Exit with zero
3 3 if all features are there, non-zero otherwise. If a feature name is
4 4 prefixed with "no-", the absence of feature is tested.
5 5 """
6 6 import optparse
7 7 import os
8 8 import re
9 9 import sys
10 10 import tempfile
11 11
12 12 tempprefix = 'hg-hghave-'
13 13
14 def matchoutput(cmd, regexp):
14 def matchoutput(cmd, regexp, ignorestatus=False):
15 15 """Return True if cmd executes successfully and its output
16 16 is matched by the supplied regular expression.
17 17 """
18 18 r = re.compile(regexp)
19 19 fh = os.popen(cmd)
20 20 s = fh.read()
21 21 ret = fh.close()
22 return ret is None and r.search(s)
22 return (ignorestatus or ret is None) and r.search(s)
23 23
24 24 def has_symlink():
25 25 return hasattr(os, "symlink")
26 26
27 27 def has_fifo():
28 28 return hasattr(os, "mkfifo")
29 29
30 def has_cvs():
31 return matchoutput('cvs --version 2>&1', r'Concurrent Versions System')
32
33 def has_cvsps():
34 return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True)
35
30 36 def has_executablebit():
31 37 fd, path = tempfile.mkstemp(prefix=tempprefix)
32 38 os.close(fd)
33 39 try:
34 40 s = os.lstat(path).st_mode
35 41 os.chmod(path, s | 0100)
36 42 return (os.lstat(path).st_mode & 0100 != 0)
37 43 finally:
38 44 os.remove(path)
39 45
40 46 def has_eol_in_paths():
41 47 try:
42 48 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
43 49 os.close(fd)
44 50 os.remove(path)
45 51 return True
46 52 except:
47 53 return False
48 54
49 55 def has_hotshot():
50 56 try:
51 57 # hotshot.stats tests hotshot and many problematic dependencies
52 58 # like profile.
53 59 import hotshot.stats
54 60 return True
55 61 except ImportError:
56 62 return False
57 63
58 64 def has_lsprof():
59 65 try:
60 66 import _lsprof
61 67 return True
62 68 except ImportError:
63 69 return False
64 70
65 71 def has_git():
66 72 return matchoutput('git --version 2>&1', r'^git version')
67 73
68 74 checks = {
75 "cvs": (has_cvs, "cvs client"),
76 "cvsps": (has_cvsps, "cvsps utility"),
69 77 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
70 78 "execbit": (has_executablebit, "executable bit"),
71 79 "git": (has_git, "git command line client"),
72 80 "fifo": (has_fifo, "named pipes"),
73 81 "hotshot": (has_hotshot, "python hotshot module"),
74 82 "lsprof": (has_lsprof, "python lsprof module"),
75 83 "symlink": (has_symlink, "symbolic links"),
76 84 }
77 85
78 86 def list_features():
79 87 for name, feature in checks.iteritems():
80 88 desc = feature[1]
81 89 print name + ':', desc
82 90
83 91 parser = optparse.OptionParser("%prog [options] [features]")
84 92 parser.add_option("--list-features", action="store_true",
85 93 help="list available features")
86 94 parser.add_option("-q", "--quiet", action="store_true",
87 95 help="check features silently")
88 96
89 97 if __name__ == '__main__':
90 98 options, args = parser.parse_args()
91 99 if options.list_features:
92 100 list_features()
93 101 sys.exit(0)
94 102
95 103 quiet = options.quiet
96 104
97 105 failures = 0
98 106
99 107 def error(msg):
100 108 global failures
101 109 if not quiet:
102 110 sys.stderr.write(msg + '\n')
103 111 failures += 1
104 112
105 113 for feature in args:
106 114 negate = feature.startswith('no-')
107 115 if negate:
108 116 feature = feature[3:]
109 117
110 118 if feature not in checks:
111 119 error('hghave: unknown feature: ' + feature)
112 120 continue
113 121
114 122 check, desc = checks[feature]
115 123 if not negate and not check():
116 124 error('hghave: missing feature: ' + desc)
117 125 elif negate and check():
118 126 error('hghave: system supports %s' % desc)
119 127
120 128 if failures != 0:
121 129 sys.exit(1)
122 130
123 131
General Comments 0
You need to be logged in to leave comments. Login now