root/trunk/packages/attach/attach

Revision 53, 2.1 kB (checked in by broder, 16 years ago)

Rearranging all of our own packages into their own directory - this will lead to a script to build tarballs for them

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 import sys
4 import os
5 import getopt
6 import hesiod
7
8 usage = """Usage: attach [options] filesystem ... [options] filesystem ...
9        attach -l filesystem
10        attach -H host
11        attach
12 """
13
14 if len(sys.argv) > 1 and sys.argv[1] == '-Padd':
15         os.execv('/usr/local/bin/attach-add.py', sys.argv[2:])
16
17 try:
18         optlist, args = getopt.getopt(sys.argv[1:], 'vqplvngazhrwm:Mxet:o:NSOLH', ['verbose', 'quiet', 'printpath', 'lookup', 'map', 'nomap', 'remap', 'noremap', 'zephyr', 'nozephyr', 'readonly', 'write', 'mountpoint=', 'master', 'noexplicit', 'explicit', 'type', 'mountoptions', 'nosetuid', 'nosuid', 'setuid', 'suid', 'override', 'lock', 'host=']);
19 except getopt.GetoptError:
20         sys.stderr.write(usage)
21         sys.exit(1)
22
23 print_usage = False
24 noise_level = 'verbose'
25 for o, a in optlist:
26         if o == '-l' or o == '--lookup':
27                 noise_level = 'lookup'
28         if o == '-v' or o == '--verbose':
29                 noise_level = 'verbose'
30         if o == '-q' or o == '--quiet':
31                 noise_level = 'quiet'
32         if o == '-p' or o == '--printpath':
33                 noise_level = 'path'
34         if o == '-m' or o == '--mountpoint':
35                 if a[0:5] == '/mit/':
36                         sys.stderr.write('Sorry. The MacAthena attach program does not support alternate mount points within /mit\n')
37                         sys.exit(1)
38                 elif len(args) != 1:
39                         print_usage = True
40                 else:
41                         filsys = hesiod.FilsysLookup(args[0])
42                         if filsys:
43                                 os.symlink(filsys.getFilsys()[0]['location'], a)
44                                 sys.exit(0)
45                         else:
46                                 sys.stderr.write('%s: Locker unknown' % args[0])
47                                 sys.exit(2)
48         if o == '-H' or o == '--host':
49                 sys.stderr.write('Sorry. The MacAthena attach program does not keep an attachtab\n')
50                 sys.exit(1)
51
52 exit_code = 0
53
54 for arg in args:
55         try:
56                 os.stat('/mit/%s' % arg)
57                 os.system('/usr/bin/aklog /mit/%s' % arg)
58         except OSError:
59                 sys.stderr.write('%s: Locker unknown\n' % arg)
60                 exit_code = 2
61         if noise_level == 'verbose':
62                 filsys = hesiod.FilsysLookup(args[0])
63                 print 'attach: %s attached to /mit/%s for filesystem %s' % (filsys.getFilsys()[0]['location'], arg, arg)
64         elif noise_level == 'path':
65                 print '/mit/%s' % arg
66         elif noise_level == 'lookup':
67                 print '%s resolves to:' % arg
68                 os.system('hesinfo %s filsys' % arg)
69
70 sys.exit(exit_code)
Note: See TracBrowser for help on using the browser.