Skip to content
GitLab
Explore
Sign in
Register
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
1f4e5a8c
Commit
1f4e5a8c
authored
6 years ago
by
Auke Klazema
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MAC/Deployment/data/Coordinates/create_CDB_objects.py
+66
-28
66 additions, 28 deletions
MAC/Deployment/data/Coordinates/create_CDB_objects.py
with
66 additions
and
28 deletions
MAC/Deployment/data/Coordinates/create_CDB_objects.py
+
66
−
28
View file @
1f4e5a8c
#!/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
find
S
tation
I
nfo
(
station
N
ame
):
def
find
_s
tation
_i
nfo
(
station
_n
ame
):
"""
"""
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
(
"
^
"
+
station
N
ame
+
"
[
\t
].*
"
,
re
.
IGNORECASE
|
re
.
MULTILINE
)
pattern
=
re
.
compile
(
"
^
"
+
station
_n
ame
+
"
[
\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
"
\n
Fatal error:
"
+
station
N
ame
+
"
is not defined in file
'
StationInfo.dat
'"
raise
"
\n
Fatal error:
"
+
station
_n
ame
+
"
is not defined in file
'
StationInfo.dat
'"
return
match
.
group
().
split
()
return
match
.
group
().
split
()
#
#
# getStationList
# getStationList
#
#
def
get
S
tation
L
ist
():
def
get
_s
tation
_l
ist
():
"""
"""
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
get
S
tation
L
ist
():
for
station
in
get
_s
tation
_l
ist
():
print
find
S
tation
I
nfo
(
station
)
print
find
_s
tation
_i
nfo
(
station
)
if
(
len
(
find
S
tation
I
nfo
(
station
))
<
13
):
if
(
len
(
find
_s
tation
_i
nfo
(
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
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