1 |
#!/usr/bin/env python |
---|
2 |
|
---|
3 |
import os |
---|
4 |
import sys |
---|
5 |
import getopt |
---|
6 |
|
---|
7 |
usage = """Usage: add [-vfrpwbq] [-P $athena_path] [-a attachflags] [lockername ...] |
---|
8 |
add [-dfrb] [-P $athena_path] pathname ... |
---|
9 |
""" |
---|
10 |
|
---|
11 |
if '-a' in sys.argv[1:]: |
---|
12 |
(add_options, attach_options) = sys.argv[1:].split('-a') |
---|
13 |
else: |
---|
14 |
add_options = sys.argv[1:] |
---|
15 |
attach_options = [] |
---|
16 |
|
---|
17 |
try: |
---|
18 |
optlist, args = getopt.getopt(add_options, 'frwpP:abqh'); |
---|
19 |
except getopt.GetoptError: |
---|
20 |
sys.stderr.write(usage) |
---|
21 |
sys.exit(1) |
---|
22 |
|
---|
23 |
front = False |
---|
24 |
remove_locker = False |
---|
25 |
shell = 'csh' |
---|
26 |
for o, a in optlist: |
---|
27 |
if o == '-f': front = True |
---|
28 |
if o == '-r': remove_locker = True |
---|
29 |
if o == '-b': shell = 'bash' |
---|
30 |
|
---|
31 |
if os.environ.has_key('PATH'): |
---|
32 |
path = os.environ['PATH'].split(':') |
---|
33 |
else: path = [] |
---|
34 |
|
---|
35 |
if os.environ.has_key('MANPATH'): |
---|
36 |
manpath = os.environ['MANPATH'].split(':') |
---|
37 |
else: manpath = [] |
---|
38 |
|
---|
39 |
if os.environ.has_key('INFOPATH'): |
---|
40 |
infopath = os.environ['INFOPATH'].split(':') |
---|
41 |
else: infopath = [] |
---|
42 |
|
---|
43 |
for arg in args: |
---|
44 |
if '/' == arg[0] or '.' == arg[0]: |
---|
45 |
if remove_locker: path.remove(arg) |
---|
46 |
elif front: path = [arg] + path |
---|
47 |
else: path.append(arg) |
---|
48 |
else: |
---|
49 |
locker = '/mit/%s' % arg |
---|
50 |
|
---|
51 |
bin_pipe = os.popen('/usr/local/bin/athdir %s bin' % locker) |
---|
52 |
new_bin = bin_pipe.read().strip() |
---|
53 |
if bin_pipe.close() != None: |
---|
54 |
if not os.access(locker, os.F_OK): |
---|
55 |
sys.stderr.write("%s: Locker unknown\n" % arg) |
---|
56 |
continue |
---|
57 |
if new_bin in path: |
---|
58 |
path.remove(new_bin) |
---|
59 |
if front: path.insert(0, new_bin) |
---|
60 |
elif not remove_locker: path.append(new_bin) |
---|
61 |
|
---|
62 |
man_pipe = os.popen('/usr/local/bin/athdir %s man' % locker) |
---|
63 |
new_man = man_pipe.read().strip() |
---|
64 |
if man_pipe.close() == None: |
---|
65 |
if new_man in manpath: |
---|
66 |
manpath.remove(new_man) |
---|
67 |
if front: manpath.insert(0, new_man) |
---|
68 |
elif not remove_locker: manpath.append(new_man) |
---|
69 |
|
---|
70 |
info_pipe = os.popen('/usr/local/bin/athdir %s info' % locker) |
---|
71 |
new_info = info_pipe.read().strip() |
---|
72 |
if info_pipe.close() == None: |
---|
73 |
if new_info in infopath: |
---|
74 |
infopath.remove(new_info) |
---|
75 |
if front: infopath.insert(0, new_info) |
---|
76 |
elif not remove_locker: infopath.append(new_info) |
---|
77 |
|
---|
78 |
if shell == 'bash': |
---|
79 |
print 'PATH="%s"; export PATH; MANPATH="%s"; export MANPATH; INFOPATH="%s"; export INFOPATH' % (':'.join(path), ':'.join(manpath), ':'.join(infopath)) |
---|
80 |
elif shell == 'csh': |
---|
81 |
print 'setenv PATH "%s"; setenv MANPATH "%s"; setenv INFOPATH "%s"' % (':'.join(path), ':'.join(manpath), ':'.join(infopath)) |
---|