1 |
douglas |
600 |
#!/usr/bin/env python |
2 |
|
|
# CCS Computer Science |
3 |
|
|
# Layout |
4 |
|
|
# |
5 |
|
|
# Douglas Thrift |
6 |
|
|
# |
7 |
|
|
# $Id$ |
8 |
|
|
|
9 |
|
|
import admin |
10 |
|
|
import common |
11 |
|
|
import os |
12 |
|
|
|
13 |
|
|
if __name__ == '__main__': |
14 |
douglas |
687 |
parser = admin.parser(description = 'List CCS CS Lab shell layout') |
15 |
douglas |
681 |
|
16 |
douglas |
687 |
parser.add_option('-v', '--verbose', action = 'store_true', help = 'show information about what shell paths were found') |
17 |
douglas |
681 |
|
18 |
douglas |
687 |
verbose = parser.parse_args()[0].verbose |
19 |
douglas |
600 |
path = os.environ['PATH'].split(os.pathsep) |
20 |
douglas |
687 |
_shells = map(lambda shell: shell[0], common.SHELLS[:-1]) |
21 |
douglas |
600 |
shells = [] |
22 |
|
|
|
23 |
douglas |
687 |
if verbose: |
24 |
|
|
format = '%%%us: %%s' % ((len(max(_shells, key = len)) + 1) / 2 * 2) |
25 |
|
|
|
26 |
|
|
for shell in _shells: |
27 |
douglas |
600 |
found = False |
28 |
|
|
|
29 |
|
|
for directory in path: |
30 |
|
|
_shell = os.path.join(directory, shell) |
31 |
|
|
|
32 |
|
|
if os.path.exists(_shell) and os.access(_shell, os.R_OK | os.X_OK): |
33 |
|
|
shells.append(_shell) |
34 |
|
|
|
35 |
|
|
if verbose: |
36 |
douglas |
687 |
print format % (shell, _shell) |
37 |
douglas |
600 |
|
38 |
|
|
found = True |
39 |
|
|
|
40 |
|
|
break |
41 |
|
|
|
42 |
|
|
if not found: |
43 |
|
|
admin.error('Shell not found: %s.' % shell) |
44 |
|
|
|
45 |
|
|
for system in common.SYSTEMS: |
46 |
|
|
if shells == map(lambda shell: shell[1][system], common.SHELLS[:-1]): |
47 |
|
|
print system |
48 |
|
|
|
49 |
douglas |
687 |
parser.exit() |
50 |
douglas |
600 |
|
51 |
|
|
admin.error('Unknown shell layout.') |