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

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

parent 35dc7c64
No related branches found
No related tags found
No related merge requests found
......@@ -17,26 +17,30 @@
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
#
# $Id$
import os,sys,time,pg
import sys
import time
import pg
from optparse import OptionParser
import LAPS.MsgBus
import getpass
def createParsetFile(treeID, nodeID, fileName):
def create_parset_file(tree_id, node_id, filename):
"""
Create a parset file with name fileName from tree treeID starting at nodeID.
"""
parset = otdb.query("select * from exportTree(%s, %s, %s)" % (1, treeID, nodeID)).getresult()
print " Creating parset %s" % fileName
file = open(fileName, 'w');
parset = otdb.query("select * from exportTree(%s, %s, %s)" % (1, tree_id, node_id)).getresult()
print " Creating parset %s" % filename
file = open(filename, 'w')
file.write(parset[0][0])
file.close()
if __name__ == '__main__':
"""
DBToQDeamon checks the LOFAR database every n seconds for new AutoPipeline trees.
"""
parser = OptionParser("Usage: %prog [options]" )
parser = OptionParser("Usage: %prog [options]")
parser.add_option("-D", "--database",
dest="dbName",
type="string",
......@@ -49,6 +53,18 @@ if __name__ == '__main__':
default="sasdb",
help="Hostname of OTDB database")
parser.add_option("-P", "--port",
dest="dbPort",
type="int",
default="5432",
help="Port of OTDB database")
parser.add_option("-U", "--user",
dest="dbUser",
type="string",
default="postgres",
help="Username of OTDB database")
# parse arguments
(options, args) = parser.parse_args()
......@@ -60,9 +76,13 @@ if __name__ == '__main__':
dbName = options.dbName
dbHost = options.dbHost
dbPort = options.dbPort
dbUser = options.dbUser
dbPassword = getpass.getpass()
# calling stored procedures only works from the pg module for some reason.
otdb = pg.connect(user="postgres", host=dbHost, dbname=dbName)
otdb = pg.connect(user=dbUser, host=dbHost, dbname=dbName, port=dbPort, passwd=dbPassword)
# connect to messaging system
msgbus = LAPS.MsgBus.Bus("LAPS.retrieved.parsets")
......@@ -72,18 +92,18 @@ if __name__ == '__main__':
for t in treeList:
print t['treeid']
topNodeID = otdb.query("select nodeid from getTopNode(%s)" % t['treeid']).getresult()[0][0]
parset = otdb.query("select * from exportTree(%s, %s, %s)" % (1, t['treeid'], topNodeID)).getresult()
###print parset[0][0]
parset = otdb.query("select * from exportTree(%s, %s, %s)" %
(1, t['treeid'], topNodeID)).getresult()
# print parset[0][0]
### send( message , subject )
# send( message , subject )
while True:
# 1000 msg / sec ?
time.sleep(0.01)
msgbus.send(parset[0][0],"Observation%d" %(t['treeid']))
# 1000 msg / sec ?
time.sleep(0.01)
msgbus.send(parset[0][0], "Observation%d" % (t['treeid']))
# set state to 'queued'
# otdb.query("select * from setTreeState(1, %s, 500, false)" % t['treeid'])
### set state to 'queued'
### otdb.query("select * from setTreeState(1, %s, 500, false)" % t['treeid'])
otdb.close()
sys.exit(0)
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