diff options
author | Frederick Muriuki Muriithi | 2024-11-22 12:16:28 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-11-22 12:16:28 -0600 |
commit | 8a84c4d6762446e5fdf9f9121f539c89419ae6a0 (patch) | |
tree | 0c4d175767bdfb24d83a7f0c15e0ab677e00ebba | |
parent | 82fb92db448f1985b821193bcfdee72d512e27bb (diff) | |
download | gn-uploader-8a84c4d6762446e5fdf9f9121f539c89419ae6a0.tar.gz |
Use gn-libs code for db connection.
Use the code in gn-libs to connect to the database, rather than a
local module.
-rw-r--r-- | scripts/insert_data.py | 2 | ||||
-rw-r--r-- | scripts/insert_samples.py | 2 | ||||
-rw-r--r-- | scripts/process_rqtl2_bundle.py | 2 | ||||
-rw-r--r-- | scripts/qc.py | 4 | ||||
-rw-r--r-- | scripts/qc_on_rqtl2_bundle.py | 2 | ||||
-rw-r--r-- | scripts/rqtl2/entry.py | 2 | ||||
-rw-r--r-- | scripts/validate_file.py | 2 | ||||
-rw-r--r-- | uploader/check_connections.py | 3 | ||||
-rw-r--r-- | uploader/expression_data/dbinsert.py | 3 | ||||
-rw-r--r-- | uploader/expression_data/views.py | 3 | ||||
-rw-r--r-- | uploader/genotypes/models.py | 7 | ||||
-rw-r--r-- | uploader/genotypes/views.py | 2 | ||||
-rw-r--r-- | uploader/phenotypes/models.py | 9 | ||||
-rw-r--r-- | uploader/phenotypes/views.py | 2 | ||||
-rw-r--r-- | uploader/platforms/views.py | 2 | ||||
-rw-r--r-- | uploader/population/rqtl2.py | 3 | ||||
-rw-r--r-- | uploader/population/views.py | 2 | ||||
-rw-r--r-- | uploader/request_checks.py | 2 | ||||
-rw-r--r-- | uploader/species/views.py | 2 |
19 files changed, 30 insertions, 26 deletions
diff --git a/scripts/insert_data.py b/scripts/insert_data.py index 4b2e5f3..67038f8 100644 --- a/scripts/insert_data.py +++ b/scripts/insert_data.py @@ -10,11 +10,11 @@ from typing import Tuple, Iterator import MySQLdb as mdb from redis import Redis from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from functional_tools import take from quality_control.file_utils import open_file -from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis # Set up logging diff --git a/scripts/insert_samples.py b/scripts/insert_samples.py index e3577b6..1b0a052 100644 --- a/scripts/insert_samples.py +++ b/scripts/insert_samples.py @@ -6,8 +6,8 @@ import argparse import MySQLdb as mdb from redis import Redis +from gn_libs.mysqldb import database_connection -from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis from uploader.species.models import species_by_id from uploader.population.models import population_by_id diff --git a/scripts/process_rqtl2_bundle.py b/scripts/process_rqtl2_bundle.py index ade9862..4efc3e0 100644 --- a/scripts/process_rqtl2_bundle.py +++ b/scripts/process_rqtl2_bundle.py @@ -11,6 +11,7 @@ from logging import Logger, getLogger, StreamHandler import MySQLdb as mdb from redis import Redis +from gn_libs.mysqldb import database_connection from functional_tools import take @@ -19,7 +20,6 @@ import r_qtl.r_qtl2_qc as rqc import r_qtl.exceptions as rqe from uploader import jobs -from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis from scripts.cli_parser import init_cli_parser diff --git a/scripts/qc.py b/scripts/qc.py index 6de051f..b00f4c1 100644 --- a/scripts/qc.py +++ b/scripts/qc.py @@ -5,14 +5,14 @@ import mimetypes from typing import Union, Callable from argparse import ArgumentParser +from gn_libs.mysqldb import database_connection + from functional_tools import take from quality_control.utils import make_progress_calculator from quality_control.errors import InvalidValue, DuplicateHeading from quality_control.parsing import FileType, strain_names, collect_errors -from uploader.db_utils import database_connection - from .cli_parser import init_cli_parser diff --git a/scripts/qc_on_rqtl2_bundle.py b/scripts/qc_on_rqtl2_bundle.py index fc95d13..9f9248c 100644 --- a/scripts/qc_on_rqtl2_bundle.py +++ b/scripts/qc_on_rqtl2_bundle.py @@ -12,12 +12,12 @@ from typing import Union, Sequence, Callable, Iterator import MySQLdb as mdb from redis import Redis +from gn_libs.mysqldb import database_connection from quality_control.errors import InvalidValue from quality_control.checks import decimal_points_error from uploader import jobs -from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis from r_qtl import r_qtl2 as rqtl2 diff --git a/scripts/rqtl2/entry.py b/scripts/rqtl2/entry.py index bc4cd9f..b45e1dc 100644 --- a/scripts/rqtl2/entry.py +++ b/scripts/rqtl2/entry.py @@ -5,9 +5,9 @@ from argparse import Namespace from redis import Redis from MySQLdb import Connection +from gn_libs.mysqldb import database_connection from uploader import jobs -from uploader.db_utils import database_connection from uploader.check_connections import check_db, check_redis from scripts.redis_logger import setup_redis_logger diff --git a/scripts/validate_file.py b/scripts/validate_file.py index a40d7e7..52e55ec 100644 --- a/scripts/validate_file.py +++ b/scripts/validate_file.py @@ -8,12 +8,12 @@ from zipfile import ZipFile, is_zipfile import jsonpickle from redis import Redis from redis.exceptions import ConnectionError # pylint: disable=[redefined-builtin] +from gn_libs.mysqldb import database_connection from quality_control.utils import make_progress_calculator from quality_control.parsing import FileType, strain_names, collect_errors from uploader import jobs -from uploader.db_utils import database_connection from .cli_parser import init_cli_parser from .qc import add_file_validation_arguments diff --git a/uploader/check_connections.py b/uploader/check_connections.py index 2561e55..c9b9aa3 100644 --- a/uploader/check_connections.py +++ b/uploader/check_connections.py @@ -4,8 +4,7 @@ import traceback import redis import MySQLdb - -from uploader.db_utils import database_connection +from gn_libs.mysqldb import database_connection def check_redis(uri: str): "Check the redis connection" diff --git a/uploader/expression_data/dbinsert.py b/uploader/expression_data/dbinsert.py index 32ca359..6d8ce80 100644 --- a/uploader/expression_data/dbinsert.py +++ b/uploader/expression_data/dbinsert.py @@ -7,16 +7,17 @@ from datetime import datetime from redis import Redis from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import ( flash, request, url_for, Blueprint, redirect, render_template, current_app as app) from uploader import jobs from uploader.authorisation import require_login +from uploader.db_utils import with_db_connection from uploader.population.models import populations_by_species from uploader.species.models import all_species, species_by_id from uploader.platforms.models import platform_by_species_and_id -from uploader.db_utils import with_db_connection, database_connection dbinsertbp = Blueprint("dbinsert", __name__) diff --git a/uploader/expression_data/views.py b/uploader/expression_data/views.py index bbe6538..7629f3e 100644 --- a/uploader/expression_data/views.py +++ b/uploader/expression_data/views.py @@ -8,6 +8,7 @@ from zipfile import ZipFile, is_zipfile import jsonpickle from redis import Redis from werkzeug.utils import secure_filename +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -21,8 +22,8 @@ from uploader import jobs from uploader.datautils import order_by_family from uploader.ui import make_template_renderer from uploader.authorisation import require_login +from uploader.db_utils import with_db_connection from uploader.species.models import all_species, species_by_id -from uploader.db_utils import with_db_connection, database_connection from uploader.population.models import (populations_by_species, population_by_species_and_id) diff --git a/uploader/genotypes/models.py b/uploader/genotypes/models.py index 44c98b1..4c3e634 100644 --- a/uploader/genotypes/models.py +++ b/uploader/genotypes/models.py @@ -4,8 +4,9 @@ from datetime import datetime import MySQLdb as mdb from MySQLdb.cursors import Cursor, DictCursor +from flask import current_app as app -from uploader.db_utils import debug_query +from gn_libs.mysqldb import debug_query def genocode_by_population( conn: mdb.Connection, population_id: int) -> tuple[dict, ...]: @@ -38,7 +39,7 @@ def genotype_markers( with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (species_id,)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -64,7 +65,7 @@ def genotype_dataset( with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, _params) - debug_query(cursor) + debug_query(cursor, app.logger) result = cursor.fetchone() if bool(result): return dict(result) diff --git a/uploader/genotypes/views.py b/uploader/genotypes/views.py index 0821eca..e6b1ba7 100644 --- a/uploader/genotypes/views.py +++ b/uploader/genotypes/views.py @@ -1,5 +1,6 @@ """Views for the genotypes.""" from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -11,7 +12,6 @@ from flask import (flash, from uploader.ui import make_template_renderer from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.monadic_requests import make_either_error_handler from uploader.request_checks import with_species, with_population diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py index 9324601..73b1cce 100644 --- a/uploader/phenotypes/models.py +++ b/uploader/phenotypes/models.py @@ -5,8 +5,9 @@ from datetime import datetime import MySQLdb as mdb from MySQLdb.cursors import Cursor, DictCursor +from flask import current_app as app -from uploader.db_utils import debug_query +from gn_libs.mysqldb import debug_query def datasets_by_population( conn: mdb.Connection, @@ -68,7 +69,7 @@ def dataset_phenotypes(conn: mdb.Connection, f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "") with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (population_id, dataset_id)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -201,7 +202,7 @@ def phenotypes_data(conn: mdb.Connection, f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "") with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(_query, (population_id, dataset_id)) - debug_query(cursor) + debug_query(cursor, app.logger) return tuple(dict(row) for row in cursor.fetchall()) @@ -228,5 +229,5 @@ def save_new_dataset(cursor: Cursor, "%(created)s, %(public)s, %(population_id)s, %(confidentiality)s, " "%(users)s)", params) - debug_query(cursor) + debug_query(cursor, app.logger) return {**params, "Id": cursor.lastrowid} diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index 02e8078..79aab81 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -8,6 +8,7 @@ from functools import wraps from redis import Redis from requests.models import Response from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -24,7 +25,6 @@ from uploader import jobs from uploader.files import save_file#, fullpath from uploader.oauth2.client import oauth2_post from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.monadic_requests import make_either_error_handler from uploader.request_checks import with_species, with_population diff --git a/uploader/platforms/views.py b/uploader/platforms/views.py index 2d61b6a..c20ab44 100644 --- a/uploader/platforms/views.py +++ b/uploader/platforms/views.py @@ -1,5 +1,6 @@ """The endpoints for the platforms""" from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import ( flash, request, @@ -10,7 +11,6 @@ from flask import ( from uploader.ui import make_template_renderer from uploader.authorisation import require_login -from uploader.db_utils import database_connection from uploader.species.models import all_species, species_by_id from uploader.datautils import safe_int, order_by_family, enumerate_sequence diff --git a/uploader/population/rqtl2.py b/uploader/population/rqtl2.py index 9968bd6..436eca0 100644 --- a/uploader/population/rqtl2.py +++ b/uploader/population/rqtl2.py @@ -12,6 +12,7 @@ import MySQLdb as mdb from redis import Redis from MySQLdb.cursors import DictCursor from werkzeug.utils import secure_filename +from gn_libs.mysqldb import database_connection from flask import ( flash, escape, @@ -29,7 +30,7 @@ from r_qtl import r_qtl2 from uploader import jobs from uploader.files import save_file, fullpath from uploader.species.models import all_species -from uploader.db_utils import with_db_connection, database_connection +from uploader.db_utils import with_db_connection from uploader.authorisation import require_login from uploader.platforms.models import platform_by_id, platforms_by_species diff --git a/uploader/population/views.py b/uploader/population/views.py index 36201ba..4f985f5 100644 --- a/uploader/population/views.py +++ b/uploader/population/views.py @@ -3,6 +3,7 @@ import json import base64 from MySQLdb.cursors import DictCursor +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -15,7 +16,6 @@ from uploader.oauth2.client import oauth2_post from uploader.ui import make_template_renderer from uploader.authorisation import require_login from uploader.genotypes.views import genotypesbp -from uploader.db_utils import database_connection from uploader.datautils import enumerate_sequence from uploader.phenotypes.views import phenotypesbp from uploader.expression_data.views import exprdatabp diff --git a/uploader/request_checks.py b/uploader/request_checks.py index a24b2f7..f1d8027 100644 --- a/uploader/request_checks.py +++ b/uploader/request_checks.py @@ -4,10 +4,10 @@ These are useful for reusability, and hence maintainability of the code. """ from functools import wraps +from gn_libs.mysqldb import database_connection from flask import flash, url_for, redirect, current_app as app from uploader.species.models import species_by_id -from uploader.db_utils import database_connection from uploader.population.models import population_by_species_and_id def with_species(redirect_uri: str): diff --git a/uploader/species/views.py b/uploader/species/views.py index 10715a5..fee5c75 100644 --- a/uploader/species/views.py +++ b/uploader/species/views.py @@ -1,5 +1,6 @@ """Endpoints handling species.""" from pymonad.either import Left, Right, Either +from gn_libs.mysqldb import database_connection from flask import (flash, request, url_for, @@ -10,7 +11,6 @@ from flask import (flash, from uploader.population import popbp from uploader.platforms import platformsbp from uploader.ui import make_template_renderer -from uploader.db_utils import database_connection from uploader.oauth2.client import oauth2_get, oauth2_post from uploader.authorisation import require_login, require_token from uploader.datautils import order_by_family, enumerate_sequence |