Newer
Older
#! /usr/bin/env python
#
'''
$Source: /cvs/G/DRV/misc/App/scripts/bootinfo,v $
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Obtain boot information about IOCs from the ssrm_public Oracle
database and make a pretty printout.
Usage:
-----
%s [--nocc] <pattern> [...]
where
<pattern> is used to match part of the system (i.e. crate name),
bootpc, ipaddr or ethaddr.
Unless "--nocc" is specified, <pattern> will be converted to uppercase
before being used.
Example:
%s x04sa
'''
#--------------------------------------------------------------------
import sys
import os
import urllib
import string
import getopt
import time
#---------------------------------------------------------------------------
def showUsage ():
# =========
base = os.path.basename (sys.argv[0])
print __doc__ % (base, base)
return
#---------------------------------------------------------------------------
# The program starts here!
if __name__ == "__main__":
try:
sys.stderr = sys.stdout
caseConvert = 1
#
# Analyse the options
#
(opts, items) = getopt.getopt (sys.argv[1:], "h?", \
("help", "nocc"))
for opt in opts:
if opt[0] == "-h": raise "Help"
if opt[0] == "-?": raise "Help"
if opt[0] == "--help": raise "Help"
if opt[0] == "--nocc": caseConvert = 0
#endfor
nFnd = 0
#
# Loop over the list of patterns.
hdrNotDone = 1
for item in items:
if caseConvert: item = string.upper (item)
## The following code has been hacked around because of DUO problems.
## DM, 22-Jul-2004
##
## query = "SELECT SYSTEM AS IOC, " + \
## "BOOTDATE, " + \
## "BOOTTIME, " + \
## "BOOTPC, " + \
## "SLSBASE, " + \
## "EPICSVER AS EPICS, " + \
## "VXWORKSVER AS VXWORKS, " + \
## "IPADDR, " + \
## "VXWORKS AS ARCH " + \
## "FROM SSRM.IOC_LASTBOOTED " + \
## "WHERE SYSTEM LIKE '%" + item + "%' OR " + \
## "BOOTPC LIKE '%" + item + "%' OR " + \
## "SLSBASE LIKE '%" + item + "%' OR " + \
## "EPICSVER LIKE '%" + item + "%' OR " + \
## "VXWORKSVER LIKE '%" + item + "%' OR " + \
## "IPADDR LIKE '%" + item + "%' OR " + \
## "ETHADDR LIKE '%" + item + "%' OR " + \
## "IPADDR LIKE '%" + item + "%' OR " + \
## "VXWORKS LIKE '%" + item + "%' " + \
## "ORDER BY IOC"
"BOOTDATE, " + \
"BOOTTIME, " + \
"BOOTPC, " + \
"SLSBASE, " + \
"EPICSVER AS EPICS, " + \
"VXWORKSVER AS VXWORKS, " + \
"IPADDR, " + \
"VXWORKS AS ARCH " + \
"FROM SSRM.IOC_LASTBOOTED"
url = "http://pc4860.psi.ch/testplan/IOC_INFOS/ioc_select.php?SQLQUER=" + \
urllib.quote_plus (query)
try:
ufo = urllib.urlopen (url) # Query the database
lines = ufo.readlines () # Get the result
ufo.close ()
if hdrNotDone:
toks = string.split (lines[0])
print "\n%-16s %-11s %-8s %-8s %-6s %-8s %-8s %-15s %s" % \
(toks[0], toks[1], toks[2], toks[3], toks[4], toks[5], toks[6], toks[7], toks[8])
hdrNotDone = 0
else:
print
#endif
for line in lines[1:]:
toks = string.split (line)
toks[8] = os.path.basename(os.path.dirname (toks[8]))
date = time.strptime ("%s %s" % (toks[1], toks[2]), "%d-%m-%Y %H:%M:%S")
dateStr = time.strftime ("%d-%b-%Y %H:%M:%S", date)
recd = "%-16s %s %-8s %-7s %-8s %-8s %-15s %s" % \
(toks[0], dateStr, toks[3], toks[4], toks[5], toks[6], toks[7], toks[8])
print recd
nFnd = nFnd + 1
#endif
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#endif
#endfor
except:
print "\aError getting data from database!"
raise
#endtry
#endfor
if nFnd == 0: print "No database entries found!"
except getopt.error:
print "Bad option. Specify \"-h\" for help."
sys.exit (1)
except "Help":
showUsage ()
sys.exit (0)
except "NoArgs":
print "\aYou must specify a search pattern!"
sys.exit (1)
#endtry
sys.exit (0)
#endif
#--------------------------------------------------#
# emacs setup - force text mode to prevent emacs #
# from helping with the indentation! #
# Local Variables: #
# mode:text #
# indent-tabs-mode:nil #
# End: #
#--------------------------------------------------#
#
#------------------------------------------------- End of $RCSfile: bootinfo,v $