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