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