##// END OF EJS Templates
hghave: detect darcs client
Patrick Mezard -
r5410:2daecf3d default
parent child Browse files
Show More
@@ -1,144 +1,148 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_cvs():
25 25 return matchoutput('cvs --version 2>&1', r'Concurrent Versions System')
26 26
27 27 def has_cvsps():
28 28 return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True)
29 29
30 def has_darcs():
31 return matchoutput('darcs', 'darcs version', True)
32
30 33 def has_eol_in_paths():
31 34 try:
32 35 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
33 36 os.close(fd)
34 37 os.remove(path)
35 38 return True
36 39 except:
37 40 return False
38 41
39 42 def has_executablebit():
40 43 fd, path = tempfile.mkstemp(prefix=tempprefix)
41 44 os.close(fd)
42 45 try:
43 46 s = os.lstat(path).st_mode
44 47 os.chmod(path, s | 0100)
45 48 return (os.lstat(path).st_mode & 0100 != 0)
46 49 finally:
47 50 os.remove(path)
48 51
49 52 def has_fifo():
50 53 return hasattr(os, "mkfifo")
51 54
52 55 def has_hotshot():
53 56 try:
54 57 # hotshot.stats tests hotshot and many problematic dependencies
55 58 # like profile.
56 59 import hotshot.stats
57 60 return True
58 61 except ImportError:
59 62 return False
60 63
61 64 def has_lsprof():
62 65 try:
63 66 import _lsprof
64 67 return True
65 68 except ImportError:
66 69 return False
67 70
68 71 def has_git():
69 72 return matchoutput('git --version 2>&1', r'^git version')
70 73
71 74 def has_svn():
72 75 return matchoutput('svn --version 2>&1', r'^svn, version') and \
73 76 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
74 77
75 78 def has_svn_bindings():
76 79 try:
77 80 import svn.core
78 81 return True
79 82 except ImportError:
80 83 return False
81 84
82 85 def has_symlink():
83 86 return hasattr(os, "symlink")
84 87
85 88 checks = {
86 89 "cvs": (has_cvs, "cvs client"),
87 90 "cvsps": (has_cvsps, "cvsps utility"),
91 "darcs": (has_darcs, "darcs client"),
88 92 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
89 93 "execbit": (has_executablebit, "executable bit"),
90 94 "fifo": (has_fifo, "named pipes"),
91 95 "git": (has_git, "git command line client"),
92 96 "hotshot": (has_hotshot, "python hotshot module"),
93 97 "lsprof": (has_lsprof, "python lsprof module"),
94 98 "svn": (has_svn, "subversion client and admin tools"),
95 99 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
96 100 "symlink": (has_symlink, "symbolic links"),
97 101 }
98 102
99 103 def list_features():
100 104 for name, feature in checks.iteritems():
101 105 desc = feature[1]
102 106 print name + ':', desc
103 107
104 108 parser = optparse.OptionParser("%prog [options] [features]")
105 109 parser.add_option("--list-features", action="store_true",
106 110 help="list available features")
107 111 parser.add_option("-q", "--quiet", action="store_true",
108 112 help="check features silently")
109 113
110 114 if __name__ == '__main__':
111 115 options, args = parser.parse_args()
112 116 if options.list_features:
113 117 list_features()
114 118 sys.exit(0)
115 119
116 120 quiet = options.quiet
117 121
118 122 failures = 0
119 123
120 124 def error(msg):
121 125 global failures
122 126 if not quiet:
123 127 sys.stderr.write(msg + '\n')
124 128 failures += 1
125 129
126 130 for feature in args:
127 131 negate = feature.startswith('no-')
128 132 if negate:
129 133 feature = feature[3:]
130 134
131 135 if feature not in checks:
132 136 error('hghave: unknown feature: ' + feature)
133 137 continue
134 138
135 139 check, desc = checks[feature]
136 140 if not negate and not check():
137 141 error('hghave: missing feature: ' + desc)
138 142 elif negate and check():
139 143 error('hghave: system supports %s' % desc)
140 144
141 145 if failures != 0:
142 146 sys.exit(1)
143 147
144 148
General Comments 0
You need to be logged in to leave comments. Login now