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