author | Thomas Arendsen Hein <thomas@intevation.de> |
Tue, 07 Aug 2007 09:42:32 +0200 | |
changeset 5138 | 9cda2315c7a9 |
parent 5074 | e86788af599a |
child 5081 | ea7b982b6c08 |
permissions | -rwxr-xr-x |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
2 |
"""Test the running system for features availability. Exit with zero |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
3 |
if all features are there, non-zero otherwise. |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
4 |
""" |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
5 |
import optparse |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
6 |
import os |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
7 |
import sys |
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
8 |
import tempfile |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
9 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
10 |
def has_symlink(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
11 |
return hasattr(os, "symlink") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
12 |
|
5070
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
13 |
def has_fifo(): |
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
14 |
return hasattr(os, "mkfifo") |
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
15 |
|
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
16 |
def has_executablebit(): |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
17 |
fd, path = tempfile.mkstemp() |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
18 |
os.close(fd) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
19 |
try: |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
20 |
s = os.lstat(path).st_mode |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
21 |
os.chmod(path, s | 0100) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
22 |
return (os.lstat(path).st_mode & 0100 != 0) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
23 |
finally: |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
24 |
os.remove(path) |
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
25 |
|
5074
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
26 |
def has_eol_in_paths(): |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
27 |
try: |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
28 |
fd, path = tempfile.mkstemp(suffix='\n\r') |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
29 |
os.close(fd) |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
30 |
os.remove(path) |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
31 |
return True |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
32 |
except: |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
33 |
return False |
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
34 |
|
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
35 |
checks = { |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 |
"symlink": (has_symlink, "symbolic links"), |
5070
4cf6f8dbd1b4
hghave: detect FIFO availability
Patrick Mezard <pmezard@gmail.com>
parents:
4881
diff
changeset
|
37 |
"fifo": (has_fifo, "named pipes"), |
5072
7e2385a31933
hghave: detect executable permission availability.
Patrick Mezard <pmezard@gmail.com>
parents:
5070
diff
changeset
|
38 |
"execbit": (has_executablebit, "executable bit"), |
5074
e86788af599a
hghave: detect support for EOL in paths.
Patrick Mezard <pmezard@gmail.com>
parents:
5072
diff
changeset
|
39 |
"eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"), |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
40 |
} |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
41 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
def list_features(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
43 |
for name, feature in checks.iteritems(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
44 |
desc = feature[1] |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
45 |
print name + ':', desc |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
47 |
parser = optparse.OptionParser("%prog [options] [features]") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 |
parser.add_option("--list-features", action="store_true", |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 |
help="list available features") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
50 |
parser.add_option("-q", "--quiet", action="store_true", |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
51 |
help="check features silently") |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
52 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
53 |
if __name__ == '__main__': |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
54 |
options, args = parser.parse_args() |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
55 |
if options.list_features: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
56 |
list_features() |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
57 |
sys.exit(0) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
58 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
59 |
quiet = options.quiet |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
60 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
61 |
failures = 0 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
62 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
63 |
def error(msg): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
64 |
global failures |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
65 |
if not quiet: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
66 |
sys.stderr.write(msg + '\n') |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
67 |
failures += 1 |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
68 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
69 |
for feature in args: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
70 |
if feature not in checks: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
71 |
error('hghave: unknown feature: ' + feature) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
72 |
continue |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
73 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
74 |
check, desc = checks[feature] |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
75 |
if not check(): |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
76 |
error('hghave: missing feature: ' + desc) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
77 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
78 |
if failures != 0: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
79 |
sys.exit(1) |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
80 |
|
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
81 |