Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
97afb374
Commit
97afb374
authored
6 years ago
by
Auke Klazema
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CEP/LAPS/DBToQDeamon/src/DBToQDeamon.py
+36
-16
36 additions, 16 deletions
CEP/LAPS/DBToQDeamon/src/DBToQDeamon.py
with
36 additions
and
16 deletions
CEP/LAPS/DBToQDeamon/src/DBToQDeamon.py
+
36
−
16
View file @
97afb374
...
...
@@ -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
create
P
arset
F
ile
(
tree
ID
,
node
ID
,
file
N
ame
):
def
create
_p
arset
_f
ile
(
tree
_id
,
node
_id
,
file
n
ame
):
"""
Create a parset file with name fileName from tree treeID starting at nodeID.
"""
parset
=
otdb
.
query
(
"
select * from exportTree(%s, %s, %s)
"
%
(
1
,
tree
ID
,
node
ID
)).
getresult
()
print
"
Creating parset %s
"
%
file
N
ame
file
=
open
(
file
N
ame
,
'
w
'
)
;
parset
=
otdb
.
query
(
"
select * from exportTree(%s, %s, %s)
"
%
(
1
,
tree
_id
,
node
_id
)).
getresult
()
print
"
Creating parset %s
"
%
file
n
ame
file
=
open
(
file
n
ame
,
'
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment