Show More
@@ -1,274 +1,274 b'' | |||||
1 | import os, stat |
|
1 | import os, stat | |
2 | import re |
|
2 | import re | |
3 | import sys |
|
3 | import sys | |
4 | import tempfile |
|
4 | import tempfile | |
5 |
|
5 | |||
6 | tempprefix = 'hg-hghave-' |
|
6 | tempprefix = 'hg-hghave-' | |
7 |
|
7 | |||
8 | def matchoutput(cmd, regexp, ignorestatus=False): |
|
8 | def matchoutput(cmd, regexp, ignorestatus=False): | |
9 | """Return True if cmd executes successfully and its output |
|
9 | """Return True if cmd executes successfully and its output | |
10 | is matched by the supplied regular expression. |
|
10 | is matched by the supplied regular expression. | |
11 | """ |
|
11 | """ | |
12 | r = re.compile(regexp) |
|
12 | r = re.compile(regexp) | |
13 | fh = os.popen(cmd) |
|
13 | fh = os.popen(cmd) | |
14 | s = fh.read() |
|
14 | s = fh.read() | |
15 | try: |
|
15 | try: | |
16 | ret = fh.close() |
|
16 | ret = fh.close() | |
17 | except IOError: |
|
17 | except IOError: | |
18 | # Happen in Windows test environment |
|
18 | # Happen in Windows test environment | |
19 | ret = 1 |
|
19 | ret = 1 | |
20 | return (ignorestatus or ret is None) and r.search(s) |
|
20 | return (ignorestatus or ret is None) and r.search(s) | |
21 |
|
21 | |||
22 | def has_baz(): |
|
22 | def has_baz(): | |
23 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') |
|
23 | return matchoutput('baz --version 2>&1', r'baz Bazaar version') | |
24 |
|
24 | |||
25 | def has_bzr(): |
|
25 | def has_bzr(): | |
26 | try: |
|
26 | try: | |
27 | import bzrlib |
|
27 | import bzrlib | |
28 | return bzrlib.__doc__ is not None |
|
28 | return bzrlib.__doc__ is not None | |
29 | except ImportError: |
|
29 | except ImportError: | |
30 | return False |
|
30 | return False | |
31 |
|
31 | |||
32 | def has_bzr114(): |
|
32 | def has_bzr114(): | |
33 | try: |
|
33 | try: | |
34 | import bzrlib |
|
34 | import bzrlib | |
35 | return (bzrlib.__doc__ is not None |
|
35 | return (bzrlib.__doc__ is not None | |
36 | and bzrlib.version_info[:2] >= (1, 14)) |
|
36 | and bzrlib.version_info[:2] >= (1, 14)) | |
37 | except ImportError: |
|
37 | except ImportError: | |
38 | return False |
|
38 | return False | |
39 |
|
39 | |||
40 | def has_cvs(): |
|
40 | def has_cvs(): | |
41 | re = r'Concurrent Versions System.*?server' |
|
41 | re = r'Concurrent Versions System.*?server' | |
42 | return matchoutput('cvs --version 2>&1', re) and not has_msys() |
|
42 | return matchoutput('cvs --version 2>&1', re) and not has_msys() | |
43 |
|
43 | |||
44 | def has_darcs(): |
|
44 | def has_darcs(): | |
45 | return matchoutput('darcs --version', r'2\.[2-9]', True) |
|
45 | return matchoutput('darcs --version', r'2\.[2-9]', True) | |
46 |
|
46 | |||
47 | def has_mtn(): |
|
47 | def has_mtn(): | |
48 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( |
|
48 | return matchoutput('mtn --version', r'monotone', True) and not matchoutput( | |
49 | 'mtn --version', r'monotone 0\.', True) |
|
49 | 'mtn --version', r'monotone 0\.', True) | |
50 |
|
50 | |||
51 | def has_eol_in_paths(): |
|
51 | def has_eol_in_paths(): | |
52 | try: |
|
52 | try: | |
53 | fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r') |
|
53 | fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r') | |
54 | os.close(fd) |
|
54 | os.close(fd) | |
55 | os.remove(path) |
|
55 | os.remove(path) | |
56 | return True |
|
56 | return True | |
57 | except (IOError, OSError): |
|
57 | except (IOError, OSError): | |
58 | return False |
|
58 | return False | |
59 |
|
59 | |||
60 | def has_executablebit(): |
|
60 | def has_executablebit(): | |
61 | try: |
|
61 | try: | |
62 | EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH |
|
62 | EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | |
63 |
fh, fn = tempfile.mkstemp(dir= |
|
63 | fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix) | |
64 | try: |
|
64 | try: | |
65 | os.close(fh) |
|
65 | os.close(fh) | |
66 | m = os.stat(fn).st_mode & 0777 |
|
66 | m = os.stat(fn).st_mode & 0777 | |
67 | new_file_has_exec = m & EXECFLAGS |
|
67 | new_file_has_exec = m & EXECFLAGS | |
68 | os.chmod(fn, m ^ EXECFLAGS) |
|
68 | os.chmod(fn, m ^ EXECFLAGS) | |
69 | exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m) |
|
69 | exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m) | |
70 | finally: |
|
70 | finally: | |
71 | os.unlink(fn) |
|
71 | os.unlink(fn) | |
72 | except (IOError, OSError): |
|
72 | except (IOError, OSError): | |
73 | # we don't care, the user probably won't be able to commit anyway |
|
73 | # we don't care, the user probably won't be able to commit anyway | |
74 | return False |
|
74 | return False | |
75 | return not (new_file_has_exec or exec_flags_cannot_flip) |
|
75 | return not (new_file_has_exec or exec_flags_cannot_flip) | |
76 |
|
76 | |||
77 | def has_icasefs(): |
|
77 | def has_icasefs(): | |
78 | # Stolen from mercurial.util |
|
78 | # Stolen from mercurial.util | |
79 |
fd, path = tempfile.mkstemp( |
|
79 | fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix) | |
80 | os.close(fd) |
|
80 | os.close(fd) | |
81 | try: |
|
81 | try: | |
82 | s1 = os.stat(path) |
|
82 | s1 = os.stat(path) | |
83 | d, b = os.path.split(path) |
|
83 | d, b = os.path.split(path) | |
84 | p2 = os.path.join(d, b.upper()) |
|
84 | p2 = os.path.join(d, b.upper()) | |
85 | if path == p2: |
|
85 | if path == p2: | |
86 | p2 = os.path.join(d, b.lower()) |
|
86 | p2 = os.path.join(d, b.lower()) | |
87 | try: |
|
87 | try: | |
88 | s2 = os.stat(p2) |
|
88 | s2 = os.stat(p2) | |
89 | return s2 == s1 |
|
89 | return s2 == s1 | |
90 | except OSError: |
|
90 | except OSError: | |
91 | return False |
|
91 | return False | |
92 | finally: |
|
92 | finally: | |
93 | os.remove(path) |
|
93 | os.remove(path) | |
94 |
|
94 | |||
95 | def has_inotify(): |
|
95 | def has_inotify(): | |
96 | try: |
|
96 | try: | |
97 | import hgext.inotify.linux.watcher |
|
97 | import hgext.inotify.linux.watcher | |
98 | return True |
|
98 | return True | |
99 | except ImportError: |
|
99 | except ImportError: | |
100 | return False |
|
100 | return False | |
101 |
|
101 | |||
102 | def has_fifo(): |
|
102 | def has_fifo(): | |
103 | return getattr(os, "mkfifo", None) is not None |
|
103 | return getattr(os, "mkfifo", None) is not None | |
104 |
|
104 | |||
105 | def has_cacheable_fs(): |
|
105 | def has_cacheable_fs(): | |
106 | from mercurial import util |
|
106 | from mercurial import util | |
107 |
|
107 | |||
108 | fd, path = tempfile.mkstemp(prefix=tempprefix) |
|
108 | fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix) | |
109 | os.close(fd) |
|
109 | os.close(fd) | |
110 | try: |
|
110 | try: | |
111 | return util.cachestat(path).cacheable() |
|
111 | return util.cachestat(path).cacheable() | |
112 | finally: |
|
112 | finally: | |
113 | os.remove(path) |
|
113 | os.remove(path) | |
114 |
|
114 | |||
115 | def has_lsprof(): |
|
115 | def has_lsprof(): | |
116 | try: |
|
116 | try: | |
117 | import _lsprof |
|
117 | import _lsprof | |
118 | return True |
|
118 | return True | |
119 | except ImportError: |
|
119 | except ImportError: | |
120 | return False |
|
120 | return False | |
121 |
|
121 | |||
122 | def has_gettext(): |
|
122 | def has_gettext(): | |
123 | return matchoutput('msgfmt --version', 'GNU gettext-tools') |
|
123 | return matchoutput('msgfmt --version', 'GNU gettext-tools') | |
124 |
|
124 | |||
125 | def has_git(): |
|
125 | def has_git(): | |
126 | return matchoutput('git --version 2>&1', r'^git version') |
|
126 | return matchoutput('git --version 2>&1', r'^git version') | |
127 |
|
127 | |||
128 | def has_docutils(): |
|
128 | def has_docutils(): | |
129 | try: |
|
129 | try: | |
130 | from docutils.core import publish_cmdline |
|
130 | from docutils.core import publish_cmdline | |
131 | return True |
|
131 | return True | |
132 | except ImportError: |
|
132 | except ImportError: | |
133 | return False |
|
133 | return False | |
134 |
|
134 | |||
135 | def getsvnversion(): |
|
135 | def getsvnversion(): | |
136 | m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') |
|
136 | m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)') | |
137 | if not m: |
|
137 | if not m: | |
138 | return (0, 0) |
|
138 | return (0, 0) | |
139 | return (int(m.group(1)), int(m.group(2))) |
|
139 | return (int(m.group(1)), int(m.group(2))) | |
140 |
|
140 | |||
141 | def has_svn15(): |
|
141 | def has_svn15(): | |
142 | return getsvnversion() >= (1, 5) |
|
142 | return getsvnversion() >= (1, 5) | |
143 |
|
143 | |||
144 | def has_svn13(): |
|
144 | def has_svn13(): | |
145 | return getsvnversion() >= (1, 3) |
|
145 | return getsvnversion() >= (1, 3) | |
146 |
|
146 | |||
147 | def has_svn(): |
|
147 | def has_svn(): | |
148 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ |
|
148 | return matchoutput('svn --version 2>&1', r'^svn, version') and \ | |
149 | matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') |
|
149 | matchoutput('svnadmin --version 2>&1', r'^svnadmin, version') | |
150 |
|
150 | |||
151 | def has_svn_bindings(): |
|
151 | def has_svn_bindings(): | |
152 | try: |
|
152 | try: | |
153 | import svn.core |
|
153 | import svn.core | |
154 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR |
|
154 | version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR | |
155 | if version < (1, 4): |
|
155 | if version < (1, 4): | |
156 | return False |
|
156 | return False | |
157 | return True |
|
157 | return True | |
158 | except ImportError: |
|
158 | except ImportError: | |
159 | return False |
|
159 | return False | |
160 |
|
160 | |||
161 | def has_p4(): |
|
161 | def has_p4(): | |
162 | return (matchoutput('p4 -V', r'Rev\. P4/') and |
|
162 | return (matchoutput('p4 -V', r'Rev\. P4/') and | |
163 | matchoutput('p4d -V', r'Rev\. P4D/')) |
|
163 | matchoutput('p4d -V', r'Rev\. P4D/')) | |
164 |
|
164 | |||
165 | def has_symlink(): |
|
165 | def has_symlink(): | |
166 | if getattr(os, "symlink", None) is None: |
|
166 | if getattr(os, "symlink", None) is None: | |
167 | return False |
|
167 | return False | |
168 |
name = tempfile.mktemp(dir= |
|
168 | name = tempfile.mktemp(dir='.', prefix=tempprefix) | |
169 | try: |
|
169 | try: | |
170 | os.symlink(".", name) |
|
170 | os.symlink(".", name) | |
171 | os.unlink(name) |
|
171 | os.unlink(name) | |
172 | return True |
|
172 | return True | |
173 | except (OSError, AttributeError): |
|
173 | except (OSError, AttributeError): | |
174 | return False |
|
174 | return False | |
175 |
|
175 | |||
176 | def has_tla(): |
|
176 | def has_tla(): | |
177 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') |
|
177 | return matchoutput('tla --version 2>&1', r'The GNU Arch Revision') | |
178 |
|
178 | |||
179 | def has_gpg(): |
|
179 | def has_gpg(): | |
180 | return matchoutput('gpg --version 2>&1', r'GnuPG') |
|
180 | return matchoutput('gpg --version 2>&1', r'GnuPG') | |
181 |
|
181 | |||
182 | def has_unix_permissions(): |
|
182 | def has_unix_permissions(): | |
183 |
d = tempfile.mkdtemp(prefix=tempprefix |
|
183 | d = tempfile.mkdtemp(dir='.', prefix=tempprefix) | |
184 | try: |
|
184 | try: | |
185 | fname = os.path.join(d, 'foo') |
|
185 | fname = os.path.join(d, 'foo') | |
186 | for umask in (077, 007, 022): |
|
186 | for umask in (077, 007, 022): | |
187 | os.umask(umask) |
|
187 | os.umask(umask) | |
188 | f = open(fname, 'w') |
|
188 | f = open(fname, 'w') | |
189 | f.close() |
|
189 | f.close() | |
190 | mode = os.stat(fname).st_mode |
|
190 | mode = os.stat(fname).st_mode | |
191 | os.unlink(fname) |
|
191 | os.unlink(fname) | |
192 | if mode & 0777 != ~umask & 0666: |
|
192 | if mode & 0777 != ~umask & 0666: | |
193 | return False |
|
193 | return False | |
194 | return True |
|
194 | return True | |
195 | finally: |
|
195 | finally: | |
196 | os.rmdir(d) |
|
196 | os.rmdir(d) | |
197 |
|
197 | |||
198 | def has_pyflakes(): |
|
198 | def has_pyflakes(): | |
199 | return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"", |
|
199 | return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"", | |
200 | r"<stdin>:1: 're' imported but unused", |
|
200 | r"<stdin>:1: 're' imported but unused", | |
201 | True) |
|
201 | True) | |
202 |
|
202 | |||
203 | def has_pygments(): |
|
203 | def has_pygments(): | |
204 | try: |
|
204 | try: | |
205 | import pygments |
|
205 | import pygments | |
206 | return True |
|
206 | return True | |
207 | except ImportError: |
|
207 | except ImportError: | |
208 | return False |
|
208 | return False | |
209 |
|
209 | |||
210 | def has_outer_repo(): |
|
210 | def has_outer_repo(): | |
211 | return matchoutput('hg root 2>&1', r'') |
|
211 | return matchoutput('hg root 2>&1', r'') | |
212 |
|
212 | |||
213 | def has_ssl(): |
|
213 | def has_ssl(): | |
214 | try: |
|
214 | try: | |
215 | import ssl |
|
215 | import ssl | |
216 | import OpenSSL |
|
216 | import OpenSSL | |
217 | OpenSSL.SSL.Context |
|
217 | OpenSSL.SSL.Context | |
218 | return True |
|
218 | return True | |
219 | except ImportError: |
|
219 | except ImportError: | |
220 | return False |
|
220 | return False | |
221 |
|
221 | |||
222 | def has_windows(): |
|
222 | def has_windows(): | |
223 | return os.name == 'nt' |
|
223 | return os.name == 'nt' | |
224 |
|
224 | |||
225 | def has_system_sh(): |
|
225 | def has_system_sh(): | |
226 | return os.name != 'nt' |
|
226 | return os.name != 'nt' | |
227 |
|
227 | |||
228 | def has_serve(): |
|
228 | def has_serve(): | |
229 | return os.name != 'nt' # gross approximation |
|
229 | return os.name != 'nt' # gross approximation | |
230 |
|
230 | |||
231 | def has_tic(): |
|
231 | def has_tic(): | |
232 | return matchoutput('test -x "`which tic`"', '') |
|
232 | return matchoutput('test -x "`which tic`"', '') | |
233 |
|
233 | |||
234 | def has_msys(): |
|
234 | def has_msys(): | |
235 | return os.getenv('MSYSTEM') |
|
235 | return os.getenv('MSYSTEM') | |
236 |
|
236 | |||
237 | checks = { |
|
237 | checks = { | |
238 | "true": (lambda: True, "yak shaving"), |
|
238 | "true": (lambda: True, "yak shaving"), | |
239 | "false": (lambda: False, "nail clipper"), |
|
239 | "false": (lambda: False, "nail clipper"), | |
240 | "baz": (has_baz, "GNU Arch baz client"), |
|
240 | "baz": (has_baz, "GNU Arch baz client"), | |
241 | "bzr": (has_bzr, "Canonical's Bazaar client"), |
|
241 | "bzr": (has_bzr, "Canonical's Bazaar client"), | |
242 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), |
|
242 | "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"), | |
243 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), |
|
243 | "cacheable": (has_cacheable_fs, "cacheable filesystem"), | |
244 | "cvs": (has_cvs, "cvs client/server"), |
|
244 | "cvs": (has_cvs, "cvs client/server"), | |
245 | "darcs": (has_darcs, "darcs client"), |
|
245 | "darcs": (has_darcs, "darcs client"), | |
246 | "docutils": (has_docutils, "Docutils text processing library"), |
|
246 | "docutils": (has_docutils, "Docutils text processing library"), | |
247 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
|
247 | "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), | |
248 | "execbit": (has_executablebit, "executable bit"), |
|
248 | "execbit": (has_executablebit, "executable bit"), | |
249 | "fifo": (has_fifo, "named pipes"), |
|
249 | "fifo": (has_fifo, "named pipes"), | |
250 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), |
|
250 | "gettext": (has_gettext, "GNU Gettext (msgfmt)"), | |
251 | "git": (has_git, "git command line client"), |
|
251 | "git": (has_git, "git command line client"), | |
252 | "gpg": (has_gpg, "gpg client"), |
|
252 | "gpg": (has_gpg, "gpg client"), | |
253 | "icasefs": (has_icasefs, "case insensitive file system"), |
|
253 | "icasefs": (has_icasefs, "case insensitive file system"), | |
254 | "inotify": (has_inotify, "inotify extension support"), |
|
254 | "inotify": (has_inotify, "inotify extension support"), | |
255 | "lsprof": (has_lsprof, "python lsprof module"), |
|
255 | "lsprof": (has_lsprof, "python lsprof module"), | |
256 | "mtn": (has_mtn, "monotone client (>= 1.0)"), |
|
256 | "mtn": (has_mtn, "monotone client (>= 1.0)"), | |
257 | "outer-repo": (has_outer_repo, "outer repo"), |
|
257 | "outer-repo": (has_outer_repo, "outer repo"), | |
258 | "p4": (has_p4, "Perforce server and client"), |
|
258 | "p4": (has_p4, "Perforce server and client"), | |
259 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), |
|
259 | "pyflakes": (has_pyflakes, "Pyflakes python linter"), | |
260 | "pygments": (has_pygments, "Pygments source highlighting library"), |
|
260 | "pygments": (has_pygments, "Pygments source highlighting library"), | |
261 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), |
|
261 | "serve": (has_serve, "platform and python can manage 'hg serve -d'"), | |
262 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), |
|
262 | "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"), | |
263 | "svn": (has_svn, "subversion client and admin tools"), |
|
263 | "svn": (has_svn, "subversion client and admin tools"), | |
264 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), |
|
264 | "svn13": (has_svn13, "subversion client and admin tools >= 1.3"), | |
265 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), |
|
265 | "svn15": (has_svn15, "subversion client and admin tools >= 1.5"), | |
266 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), |
|
266 | "svn-bindings": (has_svn_bindings, "subversion python bindings"), | |
267 | "symlink": (has_symlink, "symbolic links"), |
|
267 | "symlink": (has_symlink, "symbolic links"), | |
268 | "system-sh": (has_system_sh, "system() uses sh"), |
|
268 | "system-sh": (has_system_sh, "system() uses sh"), | |
269 | "tic": (has_tic, "terminfo compiler"), |
|
269 | "tic": (has_tic, "terminfo compiler"), | |
270 | "tla": (has_tla, "GNU Arch tla client"), |
|
270 | "tla": (has_tla, "GNU Arch tla client"), | |
271 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), |
|
271 | "unix-permissions": (has_unix_permissions, "unix-style permissions"), | |
272 | "windows": (has_windows, "Windows"), |
|
272 | "windows": (has_windows, "Windows"), | |
273 | "msys": (has_msys, "Windows with MSYS"), |
|
273 | "msys": (has_msys, "Windows with MSYS"), | |
274 | } |
|
274 | } |
General Comments 0
You need to be logged in to leave comments.
Login now