Skip to content
Snippets Groups Projects
Commit 1f4e5a8c authored by Auke Klazema's avatar Auke Klazema
Browse files

SW-598: Add username, password, port options to create_CDB_objects.py

parent a889ab4f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
import re,sys,pg import re
from database import * import pg
from optparse import OptionParser
import getpass
# get info from database.py
dbName=getDBname()
dbHost=getDBhost()
# #
# findStationInfo(stationName) # findStationInfo(stationName)
# #
def findStationInfo(stationName): def find_station_info(station_name):
""" """
Return all basic station info (eg. nr RSPboards) from a station. Return all basic station info (eg. nr RSPboards) from a station.
""" """
pattern=re.compile("^"+stationName+"[ \t].*", re.IGNORECASE | re.MULTILINE) pattern = re.compile("^"+station_name+"[ \t].*", re.IGNORECASE | re.MULTILINE)
match = pattern.search(open("../StaticMetaData/StationInfo.dat").read()) match = pattern.search(open("../StaticMetaData/StationInfo.dat").read())
if not match: if not match:
raise "\nFatal error: "+stationName+" is not defined in file 'StationInfo.dat'" raise "\nFatal error: "+station_name+" is not defined in file 'StationInfo.dat'"
return match.group().split() return match.group().split()
# #
# getStationList # getStationList
# #
def getStationList(): def get_station_list():
""" """
Returns a list containing all stationnames Returns a list containing all stationnames
""" """
pattern=re.compile("^[A-Z]{2}[0-9]{3}[ \t].*", re.IGNORECASE | re.MULTILINE) pattern = re.compile("^[A-Z]{2}[0-9]{3}[ \t].*", re.IGNORECASE | re.MULTILINE)
return [ station.split()[0] for station in pattern.findall(open("../StaticMetaData/StationInfo.dat").read())] return [station.split()[0] for station in
pattern.findall(open("../StaticMetaData/StationInfo.dat").read())]
# #
# MAIN # MAIN
# #
if __name__ == '__main__': if __name__ == '__main__':
parser = OptionParser("Usage: %prog [options]")
parser.add_option("-D", "--database",
dest="dbName",
type="string",
default="StationCoordinates",
help="Name of StationCoordinates database to use")
parser.add_option("-H", "--host",
dest="dbHost",
type="string",
default="sasdb.control.lofar",
help="Hostname of StationCoordinates database")
parser.add_option("-P", "--port",
dest="dbPort",
type="int",
default="5432",
help="Port of StationCoordinates database")
parser.add_option("-U", "--user",
dest="dbUser",
type="string",
default="postgres",
help="Username of StationCoordinates database")
# parse arguments
(options, args) = parser.parse_args()
dbName = options.dbName
dbHost = options.dbHost
dbPort = options.dbPort
dbUser = options.dbUser
dbPassword = getpass.getpass()
print "Connecting to database ", dbName print "Connecting to database ", dbName
db = pg.connect(user="postgres", host=dbHost, dbname=dbName) db = pg.connect(user=dbUser, host=dbHost, dbname=dbName, port=dbPort, passwd=dbPassword)
pol = 2 # number of polarizations pol = 2 # number of polarizations
for station in getStationList(): for station in get_station_list():
print findStationInfo(station) print find_station_info(station)
if (len(findStationInfo(station)) < 13): if (len(find_station_info(station)) < 13):
continue continue
(name, stationID, stnType, long, lat, height, nrRSP, nrTBB, nrLBA, nrHBA, nrPowecs, HBAsplit, LBAcal, Aartfaac ) = findStationInfo(station) (name, stationID, stnType, long, lat, height, nrRSP, nrTBB,
nrLBA, nrHBA, nrPowecs, HBAsplit, LBAcal, Aartfaac) = find_station_info(station)
if height[0] != '0': if height[0] != '0':
print "updating %s to the coordinate database " % station print "updating %s to the coordinate database " % station
for lba in xrange(0, int(nrLBA)*2): for lba in xrange(0, int(nrLBA)*2):
db.query("select * from add_object('%s', '%s', %d)" % ( name, "LBA", lba )) db.query("select * from add_object('%s', '%s', %d)" % (name, "LBA", lba))
db.query("select * from add_object('%s', '%s', %d)" % ( name, "CLBA", -1 )) db.query("select * from add_object('%s', '%s', %d)" % (name, "CLBA", -1))
if HBAsplit == 'Yes': if HBAsplit == 'Yes':
for hba in xrange(0, int(nrHBA)): for hba in xrange(0, int(nrHBA)):
db.query("select * from add_object('%s', '%s', %d)" % ( name, "HBA0", hba )) db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA0", hba))
db.query("select * from add_object('%s', '%s', %d)" % ( name, "CHBA0", -1 )) db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA0", -1))
for hba in xrange(int(nrHBA), int(nrHBA)*2): for hba in xrange(int(nrHBA), int(nrHBA)*2):
db.query("select * from add_object('%s', '%s', %d)" % ( name, "HBA1", hba )) db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA1", hba))
db.query("select * from add_object('%s', '%s', %d)" % ( name, "CHBA1", -1 )) db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA1", -1))
else: else:
for hba in xrange(0, int(nrHBA)*2): for hba in xrange(0, int(nrHBA)*2):
db.query("select * from add_object('%s', '%s', %d)" % ( name, "HBA", hba )) db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA", hba))
db.query("select * from add_object('%s', '%s', %d)" % ( name, "CHBA", -1 )) db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA", -1))
# ... to be continued # ... to be continued
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment