Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OSUG
JMMC
jmmc-obsportal
Commits
cb5692de
Commit
cb5692de
authored
Jun 05, 2020
by
bourgesl
Browse files
Merge branch 'release/2020_06_05'
parents
3cbd3cfe
ae5a1a02
Pipeline
#44792
passed with stage
in 2 minutes and 48 seconds
Changes
40
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
cb5692de
...
...
@@ -91,7 +91,7 @@ Database (Alembic) migrations:
After each modification on DB structure, generate a new Alembic revision.
obsportal-cli database revision
--autogenerate
--settings=client.ini
obsportal-cli database revision --settings=client.ini
Review the SQL code generated by the revision. Add missing non-detected DB structure changes. Add DB content upgrade code.
...
...
@@ -99,6 +99,10 @@ Database (Alembic) migrations:
obsportal-cli database upgrade --settings=client.ini
-
Test downgrade:
obsportal-cli database downgrade 826d0b9dcafa --settings=client.ini
obsportal-cli database upgrade --settings=client.ini
Database feeding from ESO
-------------------------
...
...
client.ini-dist
View file @
cb5692de
...
...
@@ -82,7 +82,7 @@ listen =
##https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
#################################################
[loggers]
keys = root, obsportal, waitress, sqlalchemy, sqlalchemy_pool, urllib
keys = root, obsportal, waitress, sqlalchemy, sqlalchemy_pool,
alembic,
urllib
[handlers]
keys = console, file
...
...
@@ -101,7 +101,7 @@ qualname = obsportal
[logger_sqlalchemy]
level = WARN
handlers =
console
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
...
...
@@ -112,6 +112,11 @@ level = INFO
handlers =
qualname = sqlalchemy.pool
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[logger_waitress]
level = INFO
handlers =
...
...
development.ini-dist
View file @
cb5692de
...
...
@@ -106,7 +106,7 @@ qualname = obsportal
[logger_sqlalchemy]
level = INFO
handlers =
console
handlers =
qualname = sqlalchemy.engine
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
...
...
get-all-routes.sh
View file @
cb5692de
...
...
@@ -4,6 +4,8 @@ export LANG=C
# production
#HOST="http://obs.jmmc.fr"
# pre-production
#HOST="http://obs-preprod.jmmc.fr"
# dev
HOST
=
"http://localhost:6543"
...
...
get-bad_exposures.sh
View file @
cb5692de
...
...
@@ -5,6 +5,8 @@ export LANG=C
# production
#HOST="http://obs.jmmc.fr"
# pre-production
#HOST="http://obs-preprod.jmmc.fr"
# dev
HOST
=
"http://localhost:6543"
...
...
get-votable-queries.sh
View file @
cb5692de
...
...
@@ -5,9 +5,11 @@ TH=$1
export
LANG
=
C
# production
HOST
=
"http://obs-preprod.jmmc.fr"
#HOST="http://obs.jmmc.fr"
# pre-production
#HOST="http://obs-preprod.jmmc.fr"
# dev
#
HOST="http://localhost:6543"
HOST
=
"http://localhost:6543"
echo
"HOST:
$HOST
"
...
...
http_routes.txt
View file @
cb5692de
/
/health
#
dis
able search.votable (huge + slow)
#
/search.votable
#
en
able search.votable (huge + slow)
/search.votable
/search
#/list/{type}
/list/interferometer
...
...
@@ -32,3 +32,9 @@
/detail/observation/1.votable
#/detail/{type}/{id}.raw
/detail/header/GRAVI.2019-12-01T04:30:31.348.raw
# Special votable queries:
/search.votable?ra=170.6319752350479&dec=-53.369848897307776&
/search.votable?ra=170.6319752350479&dec=-53.369848897307776&maxrec=100
/search.votable?ra=170.6319752350479&dec=-53.369848897307776&maxrec=-1
/search.votable?ra=170.6319752350479&dec=-53.369848897307776&all_fields=false
/search.votable?ra=170.6319752350479&dec=-53.369848897307776&date_updated_from=2010-11-30T10:20:26%2B01:00&date_updated_to=2014-05-31T01:26:26%2B02:00&
http_votable_queries.txt
View file @
cb5692de
search.votable?ra=170.6319752350479&dec=-53.369848897307776&
search.votable?ra=237.300425&dec=-35.65142222222222&
search.votable?ra=277.19942485763295&dec=0.1444235118386111&
search.votable?ra=285.77809157917875&dec=-37.21380093975917&
search.votable?ra=207.9077333333333&dec=-61.65208888888889&
search.votable?ra=275.0947905&dec=-10.187118416666667&
search.votable?ra=285.286&dec=-36.955799999999996&
search.votable?ra=239.03823574999998&dec=-37.93503313888889&
search.votable?ra=291.49478941511836&dec=21.20870367244639&
search.votable?ra=180.02119602028793&dec=-78.19293312643083&
search.votable?ra=193.32167848874&dec=-77.11964657277139&
search.votable?ra=237.49061864327584&dec=-3.921206673083889&
search.votable?ra=239.16675955898208&dec=-22.027779124985834&
search.votable?ra=239.17629581170252&dec=-37.820964852544165&
search.votable?ra=250.074678625&dec=-23.89588297222222&
search.votable?ra=241.74147094454665&dec=-27.719377226827223&
search.votable?ra=252.19013481649623&dec=-14.276624984416667&
search.votable?ra=252.31376481159168&dec=-14.369067226606388&
search.votable?ra=257.5338491666667&dec=-27.2552225&
search.votable?ra=269.0887009119171&dec=-21.956075650911668&
search.votable?ra=285.47368759494753&dec=-36.952262644436665&
search.votable?ra=287.7968919648308&dec=15.787675614647222&
search.votable?ra=236.303612566705&dec=-34.29184636696639&
search.votable?ra=246.48402478525253&dec=-24.346733130509723&
search.votable?ra=242.88059583333333&dec=-18.640555555555554&
search.votable?ra=246.59871300696457&dec=-24.720524088134166&
search.votable?ra=246.6003733616908&dec=-24.270404633786665&
search.votable?ra=238.30972791666665&dec=-34.881881&
search.votable?ra=252.68401708333332&dec=-8.732641&
search.votable?ra=276.07116291666665&dec=0.456107&
search.votable?ra=249.16113083333332&dec=-25.330679&
search.votable?ra=243.6514658333333&dec=-23.215068&
search.votable?ra=205.26658583333335&dec=-62.776003&
search.votable?ra=238.29278791666667&dec=-38.352351&
search.votable?ra=171.26787916666666&dec=-53.022053&
search.votable?ra=207.90078&dec=-61.648955&
search.votable?ra=260.341025&dec=-11.947016&
search.votable?ra=289.841195&dec=-11.898609&
search.votable?ra=285.2858&dec=-36.9556&
search.votable?ra=268.86333083333335&dec=-37.803877&
search.votable?ra=296.5065441666667&dec=-40.927519&
search.votable?ra=178.07595583333332&dec=-51.314768&
search.votable?ra=287.897135&dec=-0.070237&
search.votable?ra=226.03183416666667&dec=-62.976367&
search.votable?ra=226.06866&dec=-63.202877&
search.votable?ra=230.93212409784542&dec=-1.022385115025&
search.votable?ra=253.03200791666669&dec=-1.369657&
search.votable?ra=284.93603083333335&dec=-34.471054&
search.votable?ra=299.55565&dec=-36.686926&
search.votable?ra=291.17176708333335&dec=19.786938&
search.votable?ra=288.26346083333334&dec=16.502817&
search.votable?ra=298.33685291666666&dec=22.616982&
search.votable?ra=241.07424500000002&dec=-33.213718&
search.votable?ra=258.50842083333333&dec=-27.796569&
search.votable?ra=249.6193861036075&dec=-18.220475660670832&
search.votable?ra=249.40487583333334&dec=-16.849827&
search.votable?ra=275.0947541666667&dec=-10.18710861111111&
search.votable?ra=275.094825&dec=-10.18682138888889&
search.votable?ra=253.68687406692413&dec=-36.88848911498945&
search.votable?ra=276.91469427398755&dec=-3.831149035247778&
search.votable?ra=277.35704791681206&dec=-6.077024977952222&
search.votable?ra=236.40620083333334&dec=-36.67481&
search.votable?ra=240.40672208333334&dec=-34.069574&
search.votable?ra=238.87084791666666&dec=-33.401242&
search.votable?ra=267.93566500000003&dec=-45.600703&
search.votable?ra=311.30466916666666&dec=-27.24728&
search.votable?ra=189.38566666666665&dec=-66.11136111111111&
search.votable?ra=253.86643708333335&dec=-32.503581&
search.votable?ra=245.39401791666666&dec=-44.944742&
search.votable?ra=291.6330691666667&dec=11.851068&
search.votable?ra=279.15259000000003&dec=12.987611&
search.votable?ra=270.7129108333333&dec=-24.282468&
search.votable?ra=176.77937708333334&dec=-35.906862&
search.votable?
all_fields=false&
ra=170.6319752350479&dec=-53.369848897307776&
search.votable?
all_fields=false&
ra=237.300425&dec=-35.65142222222222&
search.votable?
all_fields=false&
ra=277.19942485763295&dec=0.1444235118386111&
search.votable?
all_fields=false&
ra=285.77809157917875&dec=-37.21380093975917&
search.votable?
all_fields=false&
ra=207.9077333333333&dec=-61.65208888888889&
search.votable?
all_fields=false&
ra=275.0947905&dec=-10.187118416666667&
search.votable?
all_fields=false&
ra=285.286&dec=-36.955799999999996&
search.votable?
all_fields=false&
ra=239.03823574999998&dec=-37.93503313888889&
search.votable?
all_fields=false&
ra=291.49478941511836&dec=21.20870367244639&
search.votable?
all_fields=false&
ra=180.02119602028793&dec=-78.19293312643083&
search.votable?
all_fields=false&
ra=193.32167848874&dec=-77.11964657277139&
search.votable?
all_fields=false&
ra=237.49061864327584&dec=-3.921206673083889&
search.votable?
all_fields=false&
ra=239.16675955898208&dec=-22.027779124985834&
search.votable?
all_fields=false&
ra=239.17629581170252&dec=-37.820964852544165&
search.votable?
all_fields=false&
ra=250.074678625&dec=-23.89588297222222&
search.votable?
all_fields=false&
ra=241.74147094454665&dec=-27.719377226827223&
search.votable?
all_fields=false&
ra=252.19013481649623&dec=-14.276624984416667&
search.votable?
all_fields=false&
ra=252.31376481159168&dec=-14.369067226606388&
search.votable?
all_fields=false&
ra=257.5338491666667&dec=-27.2552225&
search.votable?
all_fields=false&
ra=269.0887009119171&dec=-21.956075650911668&
search.votable?
all_fields=false&
ra=285.47368759494753&dec=-36.952262644436665&
search.votable?
all_fields=false&
ra=287.7968919648308&dec=15.787675614647222&
search.votable?
all_fields=false&
ra=236.303612566705&dec=-34.29184636696639&
search.votable?
all_fields=false&
ra=246.48402478525253&dec=-24.346733130509723&
search.votable?
all_fields=false&
ra=242.88059583333333&dec=-18.640555555555554&
search.votable?
all_fields=false&
ra=246.59871300696457&dec=-24.720524088134166&
search.votable?
all_fields=false&
ra=246.6003733616908&dec=-24.270404633786665&
search.votable?
all_fields=false&
ra=238.30972791666665&dec=-34.881881&
search.votable?
all_fields=false&
ra=252.68401708333332&dec=-8.732641&
search.votable?
all_fields=false&
ra=276.07116291666665&dec=0.456107&
search.votable?
all_fields=false&
ra=249.16113083333332&dec=-25.330679&
search.votable?
all_fields=false&
ra=243.6514658333333&dec=-23.215068&
search.votable?
all_fields=false&
ra=205.26658583333335&dec=-62.776003&
search.votable?
all_fields=false&
ra=238.29278791666667&dec=-38.352351&
search.votable?
all_fields=false&
ra=171.26787916666666&dec=-53.022053&
search.votable?
all_fields=false&
ra=207.90078&dec=-61.648955&
search.votable?
all_fields=false&
ra=260.341025&dec=-11.947016&
search.votable?
all_fields=false&
ra=289.841195&dec=-11.898609&
search.votable?
all_fields=false&
ra=285.2858&dec=-36.9556&
search.votable?
all_fields=false&
ra=268.86333083333335&dec=-37.803877&
search.votable?
all_fields=false&
ra=296.5065441666667&dec=-40.927519&
search.votable?
all_fields=false&
ra=178.07595583333332&dec=-51.314768&
search.votable?
all_fields=false&
ra=287.897135&dec=-0.070237&
search.votable?
all_fields=false&
ra=226.03183416666667&dec=-62.976367&
search.votable?
all_fields=false&
ra=226.06866&dec=-63.202877&
search.votable?
all_fields=false&
ra=230.93212409784542&dec=-1.022385115025&
search.votable?
all_fields=false&
ra=253.03200791666669&dec=-1.369657&
search.votable?
all_fields=false&
ra=284.93603083333335&dec=-34.471054&
search.votable?
all_fields=false&
ra=299.55565&dec=-36.686926&
search.votable?
all_fields=false&
ra=291.17176708333335&dec=19.786938&
search.votable?
all_fields=false&
ra=288.26346083333334&dec=16.502817&
search.votable?
all_fields=false&
ra=298.33685291666666&dec=22.616982&
search.votable?
all_fields=false&
ra=241.07424500000002&dec=-33.213718&
search.votable?
all_fields=false&
ra=258.50842083333333&dec=-27.796569&
search.votable?
all_fields=false&
ra=249.6193861036075&dec=-18.220475660670832&
search.votable?
all_fields=false&
ra=249.40487583333334&dec=-16.849827&
search.votable?
all_fields=false&
ra=275.0947541666667&dec=-10.18710861111111&
search.votable?
all_fields=false&
ra=275.094825&dec=-10.18682138888889&
search.votable?
all_fields=false&
ra=253.68687406692413&dec=-36.88848911498945&
search.votable?
all_fields=false&
ra=276.91469427398755&dec=-3.831149035247778&
search.votable?
all_fields=false&
ra=277.35704791681206&dec=-6.077024977952222&
search.votable?
all_fields=false&
ra=236.40620083333334&dec=-36.67481&
search.votable?
all_fields=false&
ra=240.40672208333334&dec=-34.069574&
search.votable?
all_fields=false&
ra=238.87084791666666&dec=-33.401242&
search.votable?
all_fields=false&
ra=267.93566500000003&dec=-45.600703&
search.votable?
all_fields=false&
ra=311.30466916666666&dec=-27.24728&
search.votable?
all_fields=false&
ra=189.38566666666665&dec=-66.11136111111111&
search.votable?
all_fields=false&
ra=253.86643708333335&dec=-32.503581&
search.votable?
all_fields=false&
ra=245.39401791666666&dec=-44.944742&
search.votable?
all_fields=false&
ra=291.6330691666667&dec=11.851068&
search.votable?
all_fields=false&
ra=279.15259000000003&dec=12.987611&
search.votable?
all_fields=false&
ra=270.7129108333333&dec=-24.282468&
search.votable?
all_fields=false&
ra=176.77937708333334&dec=-35.906862&
obsportal/alembic/versions/20200416_5a7cecf8ad60.py
View file @
cb5692de
This diff is collapsed.
Click to expand it.
obsportal/alembic/versions/20200422_826d0b9dcafa.py
View file @
cb5692de
...
...
@@ -6,12 +6,6 @@ Create Date: 2020-04-22 14:26:12.263211
"""
from
alembic
import
op
import
sqlalchemy
as
sa
from
sqlalchemy_utils
import
UUIDType
,
ChoiceType
from
sqlalchemy_utc
import
UtcDateTime
from
sqlalchemy_jsonfield
import
JSONField
from
obsportal.models.enums.observation
import
EnumObservationCategory
from
obsportal.models.enums.program
import
EnumProgramType
# revision identifiers, used by Alembic.
revision
=
'826d0b9dcafa'
...
...
@@ -21,7 +15,8 @@ depends_on = None
def
upgrade
():
op
.
create_index
(
op
.
f
(
'ix_obsportal_header_date_updated'
),
'header'
,
[
'date_updated'
],
unique
=
False
,
schema
=
'obsportal'
)
op
.
create_index
(
op
.
f
(
'ix_obsportal_header_date_updated'
),
'header'
,
[
'date_updated'
],
unique
=
False
,
schema
=
'obsportal'
)
# ### end Alembic commands ###
...
...
obsportal/alembic/versions/20200604_b27b5a751c73.py
0 → 100644
View file @
cb5692de
"""empty message
Revision ID: b27b5a751c73
Revises: 826d0b9dcafa
Create Date: 2020-06-04 14:53:36.754556
"""
import
sqlalchemy
as
sa
from
alembic
import
op
# revision identifiers, used by Alembic.
from
sqlalchemy_utc
import
UtcDateTime
from
sqlalchemy_utils
import
UUIDType
,
ChoiceType
from
obsportal.models.enums.program
import
EnumProgramType
revision
=
'b27b5a751c73'
down_revision
=
'826d0b9dcafa'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
op
.
create_table
(
'database_tag'
,
sa
.
Column
(
'id'
,
sa
.
Unicode
(),
nullable
=
False
),
sa
.
Column
(
'value'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_database_tag'
)),
schema
=
'obsportal'
)
op
.
create_index
(
op
.
f
(
'ix_obsportal_database_tag_value'
),
'database_tag'
,
[
'value'
],
unique
=
False
,
schema
=
'obsportal'
)
op
.
add_column
(
'exposure'
,
sa
.
Column
(
'date_release'
,
UtcDateTime
(
timezone
=
True
),
nullable
=
True
),
schema
=
'obsportal'
)
op
.
drop_table
(
'program_run'
,
schema
=
'obsportal'
)
op
.
drop_table
(
'program'
,
schema
=
'obsportal'
)
op
.
create_table
(
'program'
,
sa
.
Column
(
'id'
,
sa
.
Unicode
(),
nullable
=
False
),
sa
.
Column
(
'title'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
Column
(
'type'
,
ChoiceType
(
EnumProgramType
,
impl
=
sa
.
Integer
()),
nullable
=
False
),
sa
.
Column
(
'pi_coi'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_program'
)),
schema
=
'obsportal'
)
op
.
execute
(
'INSERT INTO obsportal.program SELECT distinct(o.program_id) as id, null, 0, null FROM obsportal.observation o'
)
op
.
create_foreign_key
(
constraint_name
=
"fk_observation_program_id_program"
,
source_table
=
"observation"
,
referent_table
=
"program"
,
local_cols
=
[
"program_id"
],
remote_cols
=
[
"id"
],
onupdate
=
'CASCADE'
,
ondelete
=
'RESTRICT'
,
source_schema
=
'obsportal'
,
referent_schema
=
'obsportal'
)
# ### end Alembic commands ###
def
downgrade
():
op
.
drop_index
(
op
.
f
(
'ix_obsportal_database_tag_value'
),
table_name
=
'database_tag'
,
schema
=
'obsportal'
)
op
.
drop_table
(
'database_tag'
,
schema
=
'obsportal'
)
op
.
drop_column
(
'exposure'
,
'date_release'
,
schema
=
'obsportal'
)
op
.
drop_constraint
(
"fk_observation_program_id_program"
,
"observation"
,
schema
=
'obsportal'
)
op
.
drop_table
(
'program'
,
schema
=
'obsportal'
)
op
.
create_table
(
'program'
,
sa
.
Column
(
'id'
,
UUIDType
(),
nullable
=
False
),
sa
.
Column
(
'identifier'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
Column
(
'alternative_identifier'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
Column
(
'period'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'name'
,
sa
.
Text
(),
nullable
=
True
),
sa
.
Column
(
'type'
,
ChoiceType
(
EnumProgramType
),
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_program'
)),
schema
=
'obsportal'
)
op
.
create_table
(
'program_run'
,
sa
.
Column
(
'id'
,
UUIDType
(),
nullable
=
False
),
sa
.
Column
(
'program_id'
,
UUIDType
(),
nullable
=
True
),
sa
.
Column
(
'identifier'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
Column
(
'alternative_identifier'
,
sa
.
Unicode
(),
nullable
=
True
),
sa
.
ForeignKeyConstraint
([
'program_id'
],
[
'obsportal.program.id'
],
name
=
op
.
f
(
'fk_program_run_program_id_program'
),
onupdate
=
'CASCADE'
,
ondelete
=
'RESTRICT'
),
sa
.
PrimaryKeyConstraint
(
'id'
,
name
=
op
.
f
(
'pk_program_run'
)),
schema
=
'obsportal'
)
# ### end Alembic commands ###
obsportal/cli/commands/database.py
View file @
cb5692de
...
...
@@ -19,7 +19,6 @@ from lxml import etree
from
obsportal.models.meta
import
Base
,
SCHEMAS
from
obsportal.cli.tools
import
before_command
,
after_command
,
get_config_uri
,
get_root_path
from
obsportal.tools.writers
import
StdoutWriter
from
obsportal.tools.settings
import
load_settings
logger
=
logging
.
getLogger
(
'obsportal.cli.database'
)
...
...
@@ -286,25 +285,20 @@ def upgrade(version, settings, log, debug):
# Configure Alembic
alembic_cfg
=
alembic
.
config
.
Config
(
config_uri
)
# Init output writer
output_writer
=
StdoutWriter
()
# Upgrade DB through Alembic
try
:
alembic
.
command
.
upgrade
(
alembic_cfg
,
version
)
click
.
echo
(
"DONE: Database upgraded."
)
except
Exception
as
e
:
if
debug
:
output_writer
.
write_stack
()
else
:
logger
.
error
(
"database.upgrade() failed"
,
e
)
output_writer
.
write
(
"database.upgrade() failed"
)
logger
.
error
(
"database.upgrade() failed"
,
e
)
click
.
echo
(
"database.upgrade() failed"
)
after_command
()
@
cli
.
command
()
@
click
.
argument
(
'version'
)
@
click
.
option
(
'--settings'
,
default
=
None
,
help
=
'settings file'
,
type
=
click
.
Path
(
exists
=
True
))
@
click
.
option
(
'--log/--no-log'
,
default
=
True
,
help
=
'activate logs'
)
@
click
.
option
(
'--debug'
,
is_flag
=
True
,
help
=
'debug mode'
)
def
downgrade
(
version
,
settings
,
log
,
debug
):
# Get config_uri
...
...
@@ -364,11 +358,12 @@ def history(settings, log, debug):
@
cli
.
command
()
@
click
.
option
(
'--autogenerate'
,
is_flag
=
True
,
help
=
'autogenerate'
)
@
click
.
option
(
'--settings'
,
default
=
None
,
help
=
'settings file'
,
type
=
click
.
Path
(
exists
=
True
))
@
click
.
option
(
'--log/--no-log'
,
default
=
True
,
help
=
'activate logs'
)
@
click
.
option
(
'--debug'
,
is_flag
=
True
,
help
=
'debug mode'
)
def
revision
(
autogenerate
,
settings
,
log
,
debug
):
def
revision
(
settings
,
log
,
debug
):
autogenerate
=
True
# Get config_uri
config_uri
=
get_config_uri
(
settings
)
if
config_uri
is
not
None
:
...
...
@@ -460,15 +455,17 @@ def diagram_uml(output_file, settings, log, debug):
from
sqlalchemy_schemadisplay
import
create_uml_graph
click
.
echo
(
"Rendering diagram from database..."
)
from
obsportal.models.database_tag
import
DatabaseTag
from
obsportal.models.interferometer
import
Interferometer
from
obsportal.models.instrument
import
Instrument
,
InstrumentMode
from
obsportal.models.program
import
Program
,
ProgramRun
from
obsportal.models.program
import
Program
from
obsportal.models.header
import
Header
,
EsoHeader
from
obsportal.models.observation
import
Observation
from
obsportal.models.exposure
import
Exposure
from
obsportal.models.target
import
Target
mappers
=
[]
mappers
.
append
(
class_mapper
(
DatabaseTag
))
mappers
.
append
(
class_mapper
(
Interferometer
))
mappers
.
append
(
class_mapper
(
Instrument
))
mappers
.
append
(
class_mapper
(
InstrumentMode
))
...
...
@@ -478,7 +475,6 @@ def diagram_uml(output_file, settings, log, debug):
mappers
.
append
(
class_mapper
(
Exposure
))
mappers
.
append
(
class_mapper
(
Target
))
mappers
.
append
(
class_mapper
(
Program
))
mappers
.
append
(
class_mapper
(
ProgramRun
))
graph
=
create_uml_graph
(
mappers
,
show_operations
=
False
,
# not necessary in this case
...
...
obsportal/cli/commands/synchronize.py
View file @
cb5692de
...
...
@@ -13,12 +13,11 @@ logger = logging.getLogger('obsportal.cli.synchronize')
@
click
.
command
(
help
=
'ObsPortal content synchronization'
)
@
click
.
option
(
'--limit'
,
default
=
None
)
@
click
.
option
(
'--force_update'
,
is_flag
=
True
,
help
=
'force database update'
)
@
click
.
option
(
'--settings'
,
default
=
None
,
help
=
'settings file'
,
type
=
click
.
Path
(
exists
=
True
))
@
click
.
option
(
'--log/--no-log'
,
default
=
True
,
help
=
'activate logs'
)
@
click
.
option
(
'--debug'
,
is_flag
=
True
,
help
=
'debug mode'
)
@
click
.
option
(
'--check-lockfile'
,
'check_lockfile'
,
is_flag
=
True
,
help
=
'check the lock file'
)
def
cli
(
limit
,
force_update
,
settings
,
log
,
debug
,
check_lockfile
):
def
cli
(
limit
,
settings
,
log
,
debug
,
check_lockfile
):
config_uri
=
get_config_uri
(
settings
)
if
config_uri
is
not
None
:
...
...
@@ -45,10 +44,7 @@ def cli(limit, force_update, settings, log, debug, check_lockfile):
# Run ESO synchronization
service_eso
=
ServiceEso
(
env
[
'request'
],
env
[
'registry'
][
'dbsession_factory'
])
service_eso
.
synchronize
(
limit
=
limit
,
force_update
=
force_update
,
debug
=
debug
)
service_eso
.
synchronize
(
limit
=
limit
,
debug
=
debug
)
# Run CHARA synchronization
# TODO
...
...
obsportal/models/__init__.py
View file @
cb5692de
import
logging
import
zope.sqlalchemy
from
sqlalchemy
import
engine_from_config
from
sqlalchemy.orm
import
configure_mappers
,
sessionmaker
# import or define all models here to ensure they are attached to the
# Base.metadata prior to any initialization routines
from
.interferometer
import
Interferometer
from
.instrument
import
Instrument
,
InstrumentMode
from
.program
import
Program
,
ProgramRun
from
.database_tag
import
DatabaseTag
from
.exposure
import
Exposure
from
.header
import
Header
,
EsoHeader
from
.instrument
import
Instrument
,
InstrumentMode
from
.interferometer
import
Interferometer
from
.observation
import
Observation
from
.
exposure
import
Exposure
from
.
program
import
Program
from
.target
import
Target
logger
=
logging
.
getLogger
(
__name__
)
...
...
obsportal/models/database_tag.py
0 → 100644
View file @
cb5692de
# coding: utf-8
import
logging
from
sqlalchemy
import
(
Column
,
Unicode
,
)
from
.meta
import
Base
logger
=
logging
.
getLogger
(
__name__
)
DatabaseTagVersion
=
'database_version'
CurrentDatabaseTagVersion
=
'obsportal_2020_06_05'
class
DatabaseTag
(
Base
):
__tablename__
=
'database_tag'
__table_args__
=
(
{
'schema'
:
'obsportal'
}
)
# key
id
=
Column
(
Unicode
,
nullable
=
False
,
primary_key
=
True
)
# value
value
=
Column
(
Unicode
,
index
=
True
)
@
classmethod
def
get_db_version
(
cls
,
db_session
):
return
DatabaseTag
.
getValue
(
db_session
,
DatabaseTagVersion
)
@
classmethod
def
set_current_db_version
(
cls
,
db_session
):
DatabaseTag
.
setValue
(
db_session
,
DatabaseTagVersion
,
CurrentDatabaseTagVersion
)
@
classmethod
def
is_current_db_version
(
cls
,
db_session
):
version
=
DatabaseTag
.
get_db_version
(
db_session
)
logger
.
debug
(
f
"is_current_db_version():
{
version
}
"
)
if
not
version
:
return
False
if
version
!=
CurrentDatabaseTagVersion
:
return
False
return
True
# SEARCH ###########################################################################################################
@
classmethod
def
get
(
cls
,
db_session
,
oid
):
try
:
return
db_session
.
query
(
cls
).
autoflush
(
False
).
get
(
oid
)
except
:
return
None
@
classmethod
def
list
(
cls
,
db_session
):
try
:
return
db_session
.
query
(
cls
).
autoflush
(
False
).
all
()
except
:
return
None
@
classmethod
def
getValue
(
cls
,
db_session
,
oid
):
tag
=
DatabaseTag
.
get
(
db_session
,
oid
)
if
tag
:
return
tag
.
value
return
None
@
classmethod
def
setValue
(
cls
,
db_session
,
oid
,
value
):
tag
=
DatabaseTag
.
get
(
db_session
,
oid
)
if
not
tag
:
tag
=
cls
()
tag
.
id
=
oid
if
value
!=
tag
.
value
:
# set value
logger
.
info
(
f
"setValue(): id=
{
oid
}
value=
{
value
}
"
)
tag
.
value
=
value
db_session
.
add
(
tag
)
obsportal/models/enums/program.py
View file @
cb5692de
...
...
@@ -3,11 +3,30 @@ from . import AbstractEnum
class
EnumProgramType
(
AbstractEnum
):
Normal
=
'Normal'
GTO
=
'GTO'
ToO
=
'ToO'
Large
=
'Large'
DDT
=
'DDT'
Short
=
'Short'
Calibration
=
'Calibration'
Monitoring
=
'Monitoring'
Normal
=
0
GTO
=
1
ToO
=
2
Large
=
3
DDT
=
4
Short
=
5
Calibration
=
6
Monitoring
=
7
def
__str__
(
self
):