Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 6d226793 authored by Jerome Touvier's avatar Jerome Touvier
Browse files

config pg cleanup

parent a973148f
......@@ -6,8 +6,6 @@
```
docker run --rm -p 8000:8000 \
-e PGPASSWORD=________ \
-e PG_DBURI=postgresql://role@host:5432/database \
-e RUNMODE=dev \
-e GUNICORN_CMD_ARGS="--bind 0.0.0.0" \
--name timeseries \
......@@ -18,8 +16,6 @@ docker run --rm -p 8000:8000 \
```
docker run --rm -p 8000:8000 \
-e PGPASSWORD=________ \
-e PG_DBURI=postgresql://role@host:5432/database \
-e RUNMODE=dev \
-e GUNICORN_CMD_ARGS="--bind 0.0.0.0" \
--name timeseries \
......
......@@ -5,7 +5,9 @@ import os
import re
import sys
import traceback
import psycopg2
from flask import current_app
levels = [logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
......@@ -58,32 +60,17 @@ def sql_request(params):
def collect_data(params):
""" Return the result of the sql query in the database"""
""" Get the result of the SQL query. """
conn = None
try:
logging.debug("Try to connect to the RESIF database.")
# connect to the RESIF database using environment variable
conn = psycopg2.connect(os.getenv("PG_DBURI"))
cursor = conn.cursor() # cursor to execute SQL command
with psycopg2.connect(current_app.config["DATABASE_URI"]) as conn:
logging.debug(conn.get_dsn_parameters())
logging.debug(f"Postgres version : {conn.server_version}")
SQL_SELECT = sql_request(params)
logging.debug(f"{SQL_SELECT}")
cursor.execute(SQL_SELECT)
logging.debug(cursor.statusmessage)
data = cursor.fetchall()
cursor.close() # close this communication
return data
except (Exception, psycopg2.DatabaseError) as error:
logging.exception(str(error))
finally:
if conn is not None:
conn.close()
logging.debug("Database connection closed.")
with conn.cursor() as curs:
select = sql_request(params)
logging.debug(select)
curs.execute(select)
logging.debug(curs.statusmessage)
return curs.fetchall()
def extend(args=None, path=None):
......
......@@ -99,7 +99,7 @@ class Error:
DPI = f"dpi {INT_BETWEEN} {DPI_MIN} and {DPI_MAX}." + BAD_VAL
WIDTH = f"width {INT_BETWEEN} {WIDTH_MIN} and {WIDTH_MAX}." + BAD_VAL
HEIGHT = f"height {INT_BETWEEN} {HEIGHT_MIN} and {HEIGHT_MAX}." + BAD_VAL
COLOR = f"Invalid HEX Color Code (must be such as B22222)" + BAD_VAL
COLOR = "Invalid HEX Color Code (must be such as B22222)" + BAD_VAL
WATERLEVEL = f"waterlevel must be between {WL_MIN} and {WL_MAX}." + BAD_VAL
DECI = f"decimate {INT_BETWEEN} {DECI_MIN} and {DECI_MAX}." + BAD_VAL
TAPER = f"Accepted taper window values are: WIDTH,TYPE\n\
......
......@@ -7,7 +7,7 @@ import time
from difflib import SequenceMatcher
from datetime import datetime, timedelta
from flask import make_response, Response, request
from flask import current_app, make_response, Response, request
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, MaxNLocator
......@@ -393,26 +393,20 @@ def is_open_file(paths):
if not paths:
return
conn = None
try:
conn = psycopg2.connect(os.getenv("PG_DBURI"))
cursor = conn.cursor()
values = ", ".join(f"""('{j}', '{k}')""" for j, k in paths)
select = f"""SELECT path, name
FROM rbud, ( SELECT * FROM (VALUES {values}) AS t(path, name) ) AS t1
WHERE source_file=t1.name AND channel_id !=0 UNION SELECT path, name
FROM rall, ( SELECT * FROM (VALUES {values}) AS t(path, name) ) AS t1
WHERE source_file=t1.name AND channel_id !=0;"""
with psycopg2.connect(current_app.config["DATABASE_URI"]) as conn:
logging.debug(conn.get_dsn_parameters())
values = ", ".join(f"""('{j}', '{k}')""" for j, k in paths)
select = f"""SELECT path, name
FROM rbud, ( SELECT * FROM (VALUES {values}) AS t(path, name) ) AS t1
WHERE source_file=t1.name AND channel_id !=0 UNION SELECT path, name
FROM rall, ( SELECT * FROM (VALUES {values}) AS t(path, name) ) AS t1
WHERE source_file=t1.name AND channel_id !=0;"""
cursor.execute(select)
is_open = cursor.fetchall()
cursor.close()
return is_open
except Exception as ex:
logging.exception(str(ex))
finally:
if conn is not None:
conn.close()
logging.debug(f"Postgres version : {conn.server_version}")
with conn.cursor() as curs:
curs.execute(select)
logging.debug(curs.statusmessage)
return curs.fetchall()
def get_signal(params):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment