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
import re,sys,pg
from database import *
import re
import pg
from optparse import OptionParser
import getpass
# get info from database.py
dbName=getDBname()
dbHost=getDBhost()
#
# findStationInfo(stationName)
#
def findStationInfo(stationName):
def find_station_info(station_name):
"""
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())
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()
#
# getStationList
#
def getStationList():
def get_station_list():
"""
Returns a list containing all stationnames
"""
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())]
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())]
#
# 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
db = pg.connect(user="postgres", host=dbHost, dbname=dbName)
pol = 2 # number of polarizations
for station in getStationList():
print findStationInfo(station)
if (len(findStationInfo(station)) < 13):
db = pg.connect(user=dbUser, host=dbHost, dbname=dbName, port=dbPort, passwd=dbPassword)
pol = 2 # number of polarizations
for station in get_station_list():
print find_station_info(station)
if (len(find_station_info(station)) < 13):
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':
print "updating %s to the coordinate database " % station
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, "CLBA", -1 ))
db.query("select * from add_object('%s', '%s', %d)" % (name, "LBA", lba))
db.query("select * from add_object('%s', '%s', %d)" % (name, "CLBA", -1))
if HBAsplit == 'Yes':
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, "CHBA0", -1 ))
db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA0", hba))
db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA0", -1))
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, "CHBA1", -1 ))
db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA1", hba))
db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA1", -1))
else:
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, "CHBA", -1 ))
db.query("select * from add_object('%s', '%s', %d)" % (name, "HBA", hba))
db.query("select * from add_object('%s', '%s', %d)" % (name, "CHBA", -1))
# ... 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