improve bash completions and related delivery mechanism
[debian/mtx] / contrib / tapeinfo.py
1 # Copyright 2000 Enhanced Software Technologies Inc.
2 # All Rights Reserved
3 # Released under Free Software Foundation's General Public License,
4 # Version 2 or above
5
6 # Routine to call 'tapeinfo' and read status for a node. This is an
7 # example of how to parse the 'tapeinfo' output from a scripting language.
8 #
9
10 import os
11 import string
12 import sys
13
14
15 configdir="/opt/brupro/bin"  # sigh.
16
17 def inquiry(device):
18     retval={}
19
20     # okay, now do the thing:
21
22     command="%s/tapeinfo -f %s" % (configdir,device)
23
24     # Now to read:
25
26     infile=os.popen(command,"r")
27
28     try:
29         s=infile.readline()
30     except:
31         s=""
32         pass
33     if not s:
34         return None # did not get anything.
35     while s:
36         s=string.strip(s)
37         idx,val=string.split(s,':',1)
38         val=string.strip(val)
39         if val[0]=="'":
40             val=val[1:-1] # strip off single quotes, sigh.
41             val=string.strip(val)
42             pass
43         while "\0" in val:
44             # zapo!
45             val=string.replace(val,"\0","")
46             pass
47         retval[idx]=val
48         try:
49             s=infile.readline()
50         except:
51             s=""
52             pass
53         continue # to top of loop!
54     return retval
55