##// END OF EJS Templates
test suite: saver check if bzr is installed...
Simon Heimberg -
r7773:607de5bd default
parent child Browse files
Show More
@@ -1,229 +1,229 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 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 22 return (ignorestatus or ret is None) and r.search(s)
23 23
24 24 def has_baz():
25 25 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
26 26
27 27 def has_bzr():
28 28 try:
29 29 import bzrlib
30 return True
30 return bzrlib.__doc__ != None
31 31 except ImportError:
32 32 return False
33 33
34 34 def has_cvs():
35 35 re = r'Concurrent Versions System.*?server'
36 36 return matchoutput('cvs --version 2>&1', re)
37 37
38 38 def has_cvsps():
39 39 return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True)
40 40
41 41 def has_darcs():
42 42 return matchoutput('darcs', r'darcs version', True)
43 43
44 44 def has_mtn():
45 45 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
46 46 'mtn --version', r'monotone 0\.(\d|[12]\d|3[01])[^\d]', True)
47 47
48 48 def has_eol_in_paths():
49 49 try:
50 50 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
51 51 os.close(fd)
52 52 os.remove(path)
53 53 return True
54 54 except:
55 55 return False
56 56
57 57 def has_executablebit():
58 58 fd, path = tempfile.mkstemp(prefix=tempprefix)
59 59 os.close(fd)
60 60 try:
61 61 s = os.lstat(path).st_mode
62 62 os.chmod(path, s | 0100)
63 63 return (os.lstat(path).st_mode & 0100 != 0)
64 64 finally:
65 65 os.remove(path)
66 66
67 67 def has_icasefs():
68 68 # Stolen from mercurial.util
69 69 fd, path = tempfile.mkstemp(prefix=tempprefix)
70 70 os.close(fd)
71 71 try:
72 72 s1 = os.stat(path)
73 73 d, b = os.path.split(path)
74 74 p2 = os.path.join(d, b.upper())
75 75 if path == p2:
76 76 p2 = os.path.join(d, b.lower())
77 77 try:
78 78 s2 = os.stat(p2)
79 79 return s2 == s1
80 80 except:
81 81 return False
82 82 finally:
83 83 os.remove(path)
84 84
85 85 def has_inotify():
86 86 try:
87 87 import hgext.inotify.linux.watcher
88 88 return True
89 89 except ImportError:
90 90 return False
91 91
92 92 def has_fifo():
93 93 return hasattr(os, "mkfifo")
94 94
95 95 def has_hotshot():
96 96 try:
97 97 # hotshot.stats tests hotshot and many problematic dependencies
98 98 # like profile.
99 99 import hotshot.stats
100 100 return True
101 101 except ImportError:
102 102 return False
103 103
104 104 def has_lsprof():
105 105 try:
106 106 import _lsprof
107 107 return True
108 108 except ImportError:
109 109 return False
110 110
111 111 def has_git():
112 112 return matchoutput('git --version 2>&1', r'^git version')
113 113
114 114 def has_svn():
115 115 return matchoutput('svn --version 2>&1', r'^svn, version') and \
116 116 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
117 117
118 118 def has_svn_bindings():
119 119 try:
120 120 import svn.core
121 121 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
122 122 if version < (1, 4):
123 123 return False
124 124 return True
125 125 except ImportError:
126 126 return False
127 127
128 128 def has_symlink():
129 129 return hasattr(os, "symlink")
130 130
131 131 def has_tla():
132 132 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
133 133
134 134 def has_unix_permissions():
135 135 d = tempfile.mkdtemp(prefix=tempprefix, dir=".")
136 136 try:
137 137 fname = os.path.join(d, 'foo')
138 138 for umask in (077, 007, 022):
139 139 os.umask(umask)
140 140 f = open(fname, 'w')
141 141 f.close()
142 142 mode = os.stat(fname).st_mode
143 143 os.unlink(fname)
144 144 if mode & 0777 != ~umask & 0666:
145 145 return False
146 146 return True
147 147 finally:
148 148 os.rmdir(d)
149 149
150 150 def has_pygments():
151 151 try:
152 152 import pygments
153 153 return True
154 154 except ImportError:
155 155 return False
156 156
157 157 def has_outer_repo():
158 158 return matchoutput('hg root 2>&1', r'')
159 159
160 160 checks = {
161 161 "baz": (has_baz, "GNU Arch baz client"),
162 162 "bzr": (has_bzr, "Canonical's Bazaar client"),
163 163 "cvs": (has_cvs, "cvs client/server"),
164 164 "cvsps": (has_cvsps, "cvsps utility"),
165 165 "darcs": (has_darcs, "darcs client"),
166 166 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
167 167 "execbit": (has_executablebit, "executable bit"),
168 168 "fifo": (has_fifo, "named pipes"),
169 169 "git": (has_git, "git command line client"),
170 170 "hotshot": (has_hotshot, "python hotshot module"),
171 171 "icasefs": (has_icasefs, "case insensitive file system"),
172 172 "inotify": (has_inotify, "inotify extension support"),
173 173 "lsprof": (has_lsprof, "python lsprof module"),
174 174 "mtn": (has_mtn, "monotone client (> 0.31)"),
175 175 "outer-repo": (has_outer_repo, "outer repo"),
176 176 "pygments": (has_pygments, "Pygments source highlighting library"),
177 177 "svn": (has_svn, "subversion client and admin tools"),
178 178 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
179 179 "symlink": (has_symlink, "symbolic links"),
180 180 "tla": (has_tla, "GNU Arch tla client"),
181 181 "unix-permissions": (has_unix_permissions, "unix-style permissions"),
182 182 }
183 183
184 184 def list_features():
185 185 for name, feature in checks.iteritems():
186 186 desc = feature[1]
187 187 print name + ':', desc
188 188
189 189 parser = optparse.OptionParser("%prog [options] [features]")
190 190 parser.add_option("--list-features", action="store_true",
191 191 help="list available features")
192 192 parser.add_option("-q", "--quiet", action="store_true",
193 193 help="check features silently")
194 194
195 195 if __name__ == '__main__':
196 196 options, args = parser.parse_args()
197 197 if options.list_features:
198 198 list_features()
199 199 sys.exit(0)
200 200
201 201 quiet = options.quiet
202 202
203 203 failures = 0
204 204
205 205 def error(msg):
206 206 global failures
207 207 if not quiet:
208 208 sys.stderr.write(msg + '\n')
209 209 failures += 1
210 210
211 211 for feature in args:
212 212 negate = feature.startswith('no-')
213 213 if negate:
214 214 feature = feature[3:]
215 215
216 216 if feature not in checks:
217 217 error('skipped: unknown feature: ' + feature)
218 218 continue
219 219
220 220 check, desc = checks[feature]
221 221 if not negate and not check():
222 222 error('skipped: missing feature: ' + desc)
223 223 elif negate and check():
224 224 error('skipped: system supports %s' % desc)
225 225
226 226 if failures != 0:
227 227 sys.exit(1)
228 228
229 229
General Comments 0
You need to be logged in to leave comments. Login now