equal
deleted
inserted
replaced
|
1 #!/usr/bin/env python |
|
2 """Test the running system for features availability. Exit with zero |
|
3 if all features are there, non-zero otherwise. |
|
4 """ |
|
5 import optparse |
|
6 import os |
|
7 import sys |
|
8 |
|
9 def has_symlink(): |
|
10 return hasattr(os, "symlink") |
|
11 |
|
12 checks = { |
|
13 "symlink": (has_symlink, "symbolic links"), |
|
14 } |
|
15 |
|
16 def list_features(): |
|
17 for name, feature in checks.iteritems(): |
|
18 desc = feature[1] |
|
19 print name + ':', desc |
|
20 |
|
21 parser = optparse.OptionParser("%prog [options] [features]") |
|
22 parser.add_option("--list-features", action="store_true", |
|
23 help="list available features") |
|
24 parser.add_option("-q", "--quiet", action="store_true", |
|
25 help="check features silently") |
|
26 |
|
27 if __name__ == '__main__': |
|
28 options, args = parser.parse_args() |
|
29 if options.list_features: |
|
30 list_features() |
|
31 sys.exit(0) |
|
32 |
|
33 quiet = options.quiet |
|
34 |
|
35 failures = 0 |
|
36 |
|
37 def error(msg): |
|
38 global failures |
|
39 if not quiet: |
|
40 sys.stderr.write(msg + '\n') |
|
41 failures += 1 |
|
42 |
|
43 for feature in args: |
|
44 if feature not in checks: |
|
45 error('hghave: unknown feature: ' + feature) |
|
46 continue |
|
47 |
|
48 check, desc = checks[feature] |
|
49 if not check(): |
|
50 error('hghave: missing feature: ' + desc) |
|
51 |
|
52 if failures != 0: |
|
53 sys.exit(1) |
|
54 |
|
55 |