##// END OF EJS Templates
hghave: detect git availability
Patrick Mezard -
r5218:4fa0f2df default
parent child Browse files
Show More
@@ -1,108 +1,115 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 sys
8 import sys
9 import tempfile
9 import tempfile
10
10
11 tempprefix = 'hg-hghave-'
11 tempprefix = 'hg-hghave-'
12
12
13 def has_symlink():
13 def has_symlink():
14 return hasattr(os, "symlink")
14 return hasattr(os, "symlink")
15
15
16 def has_fifo():
16 def has_fifo():
17 return hasattr(os, "mkfifo")
17 return hasattr(os, "mkfifo")
18
18
19 def has_executablebit():
19 def has_executablebit():
20 fd, path = tempfile.mkstemp(prefix=tempprefix)
20 fd, path = tempfile.mkstemp(prefix=tempprefix)
21 os.close(fd)
21 os.close(fd)
22 try:
22 try:
23 s = os.lstat(path).st_mode
23 s = os.lstat(path).st_mode
24 os.chmod(path, s | 0100)
24 os.chmod(path, s | 0100)
25 return (os.lstat(path).st_mode & 0100 != 0)
25 return (os.lstat(path).st_mode & 0100 != 0)
26 finally:
26 finally:
27 os.remove(path)
27 os.remove(path)
28
28
29 def has_eol_in_paths():
29 def has_eol_in_paths():
30 try:
30 try:
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
31 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
32 os.close(fd)
32 os.close(fd)
33 os.remove(path)
33 os.remove(path)
34 return True
34 return True
35 except:
35 except:
36 return False
36 return False
37
37
38 def has_hotshot():
38 def has_hotshot():
39 try:
39 try:
40 # hotshot.stats tests hotshot and many problematic dependencies
40 # hotshot.stats tests hotshot and many problematic dependencies
41 # like profile.
41 # like profile.
42 import hotshot.stats
42 import hotshot.stats
43 return True
43 return True
44 except ImportError:
44 except ImportError:
45 return False
45 return False
46
46
47 def has_lsprof():
47 def has_lsprof():
48 try:
48 try:
49 import _lsprof
49 import _lsprof
50 return True
50 return True
51 except ImportError:
51 except ImportError:
52 return False
52 return False
53
53
54 def has_git():
55 fh = os.popen('git --version 2>&1')
56 s = fh.read()
57 ret = fh.close()
58 return ret is None and s.startswith('git version')
59
54 checks = {
60 checks = {
55 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
61 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
56 "execbit": (has_executablebit, "executable bit"),
62 "execbit": (has_executablebit, "executable bit"),
63 "git": (has_git, "git command line client"),
57 "fifo": (has_fifo, "named pipes"),
64 "fifo": (has_fifo, "named pipes"),
58 "hotshot": (has_hotshot, "python hotshot module"),
65 "hotshot": (has_hotshot, "python hotshot module"),
59 "lsprof": (has_lsprof, "python lsprof module"),
66 "lsprof": (has_lsprof, "python lsprof module"),
60 "symlink": (has_symlink, "symbolic links"),
67 "symlink": (has_symlink, "symbolic links"),
61 }
68 }
62
69
63 def list_features():
70 def list_features():
64 for name, feature in checks.iteritems():
71 for name, feature in checks.iteritems():
65 desc = feature[1]
72 desc = feature[1]
66 print name + ':', desc
73 print name + ':', desc
67
74
68 parser = optparse.OptionParser("%prog [options] [features]")
75 parser = optparse.OptionParser("%prog [options] [features]")
69 parser.add_option("--list-features", action="store_true",
76 parser.add_option("--list-features", action="store_true",
70 help="list available features")
77 help="list available features")
71 parser.add_option("-q", "--quiet", action="store_true",
78 parser.add_option("-q", "--quiet", action="store_true",
72 help="check features silently")
79 help="check features silently")
73
80
74 if __name__ == '__main__':
81 if __name__ == '__main__':
75 options, args = parser.parse_args()
82 options, args = parser.parse_args()
76 if options.list_features:
83 if options.list_features:
77 list_features()
84 list_features()
78 sys.exit(0)
85 sys.exit(0)
79
86
80 quiet = options.quiet
87 quiet = options.quiet
81
88
82 failures = 0
89 failures = 0
83
90
84 def error(msg):
91 def error(msg):
85 global failures
92 global failures
86 if not quiet:
93 if not quiet:
87 sys.stderr.write(msg + '\n')
94 sys.stderr.write(msg + '\n')
88 failures += 1
95 failures += 1
89
96
90 for feature in args:
97 for feature in args:
91 negate = feature.startswith('no-')
98 negate = feature.startswith('no-')
92 if negate:
99 if negate:
93 feature = feature[3:]
100 feature = feature[3:]
94
101
95 if feature not in checks:
102 if feature not in checks:
96 error('hghave: unknown feature: ' + feature)
103 error('hghave: unknown feature: ' + feature)
97 continue
104 continue
98
105
99 check, desc = checks[feature]
106 check, desc = checks[feature]
100 if not negate and not check():
107 if not negate and not check():
101 error('hghave: missing feature: ' + desc)
108 error('hghave: missing feature: ' + desc)
102 elif negate and check():
109 elif negate and check():
103 error('hghave: system supports %s' % desc)
110 error('hghave: system supports %s' % desc)
104
111
105 if failures != 0:
112 if failures != 0:
106 sys.exit(1)
113 sys.exit(1)
107
114
108
115
General Comments 0
You need to be logged in to leave comments. Login now