##// END OF EJS Templates
hghave: switch from iteritems to items...
timeless -
r29141:ba899954 default
parent child Browse files
Show More
@@ -1,67 +1,67 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
6
7 from __future__ import print_function
7 from __future__ import print_function
8
8
9 import optparse
9 import optparse
10 import os, sys
10 import os, sys
11 import hghave
11 import hghave
12
12
13 checks = hghave.checks
13 checks = hghave.checks
14
14
15 def list_features():
15 def list_features():
16 for name, feature in sorted(checks.iteritems()):
16 for name, feature in sorted(checks.items()):
17 desc = feature[1]
17 desc = feature[1]
18 print(name + ':', desc)
18 print(name + ':', desc)
19
19
20 def test_features():
20 def test_features():
21 failed = 0
21 failed = 0
22 for name, feature in checks.iteritems():
22 for name, feature in checks.items():
23 check, _ = feature
23 check, _ = feature
24 try:
24 try:
25 check()
25 check()
26 except Exception as e:
26 except Exception as e:
27 print("feature %s failed: %s" % (name, e))
27 print("feature %s failed: %s" % (name, e))
28 failed += 1
28 failed += 1
29 return failed
29 return failed
30
30
31 parser = optparse.OptionParser("%prog [options] [features]")
31 parser = optparse.OptionParser("%prog [options] [features]")
32 parser.add_option("--test-features", action="store_true",
32 parser.add_option("--test-features", action="store_true",
33 help="test available features")
33 help="test available features")
34 parser.add_option("--list-features", action="store_true",
34 parser.add_option("--list-features", action="store_true",
35 help="list available features")
35 help="list available features")
36
36
37 def _loadaddon():
37 def _loadaddon():
38 if 'TESTDIR' in os.environ:
38 if 'TESTDIR' in os.environ:
39 # loading from '.' isn't needed, because `hghave` should be
39 # loading from '.' isn't needed, because `hghave` should be
40 # running at TESTTMP in this case
40 # running at TESTTMP in this case
41 path = os.environ['TESTDIR']
41 path = os.environ['TESTDIR']
42 else:
42 else:
43 path = '.'
43 path = '.'
44
44
45 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
45 if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
46 return
46 return
47
47
48 sys.path.insert(0, path)
48 sys.path.insert(0, path)
49 try:
49 try:
50 import hghaveaddon
50 import hghaveaddon
51 except BaseException as inst:
51 except BaseException as inst:
52 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
52 sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n'
53 % (path, inst))
53 % (path, inst))
54 sys.exit(2)
54 sys.exit(2)
55 sys.path.pop(0)
55 sys.path.pop(0)
56
56
57 if __name__ == '__main__':
57 if __name__ == '__main__':
58 options, args = parser.parse_args()
58 options, args = parser.parse_args()
59 _loadaddon()
59 _loadaddon()
60 if options.list_features:
60 if options.list_features:
61 list_features()
61 list_features()
62 sys.exit(0)
62 sys.exit(0)
63
63
64 if options.test_features:
64 if options.test_features:
65 sys.exit(test_features())
65 sys.exit(test_features())
66
66
67 hghave.require(args)
67 hghave.require(args)
General Comments 0
You need to be logged in to leave comments. Login now