From 667f39a697140c95fefa53e9f559cef9e4d2feeb Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Fri, 10 Jan 2014 12:46:00 +0100 Subject: [PATCH] Remove obsolete Db module Now that we ported the database to SQLAlchemy, we remove the obsolete Db module and all references to it. --- mutalyzer/Db.py | 130 --------------------------- mutalyzer/GenRecord.py | 2 - mutalyzer/Retriever.py | 6 -- mutalyzer/config/default_settings.py | 9 -- mutalyzer/mapping.py | 1 - mutalyzer/services/rpc.py | 1 - mutalyzer/website.py | 1 - tests/test_services_soap.py | 1 - 8 files changed, 151 deletions(-) delete mode 100644 mutalyzer/Db.py diff --git a/mutalyzer/Db.py b/mutalyzer/Db.py deleted file mode 100644 index 376221d6..00000000 --- a/mutalyzer/Db.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/python - -""" -Module for database access. -The Db class is a superclass of the rest of the classes and should not be -used as such. The superclass mainly consists of a wrapper for SQL -statements. - -@requires: MySQLdb -@requires: types -@requires: time -@requires: os -""" - -#Public classes: -# - Db ; Log in to a database and keep it open for queries. -# - Mapping ; Mapping of transcripts and genes. -# - Cache ; Cache administration. -# - Batch ; Batch checker. - - -import types -import warnings - -import MySQLdb - -from mutalyzer import util -from mutalyzer.config import settings - - -# -# Note that compound queries are split into single queries because of a bug -# in MySQLdb. The functions load_Update(), merge_cdsUpdates() and -# merge_Update (search for MYSQL_BUG in this file) are affected and may be -# rewritten when this bug is fixed. -# - -class Db(): - """ - Query the database server (and lazily keep a connection open to it). - - This class is subclassed below to create specific interfaces to the - database. - """ - def __init__(self, database, user, host): - """ - Create an interface to the database. - - @arg database: Name of the database to use. - @type database: str - @arg user: User name for the database. - @type user: str - @arg host: Host name for the database. - @type host: str - """ - self._database = database - self._user = user - self._host = host - - # The connection to the database server is created lazily in the query - # method. - self._connection = None - #__init__ - - def _connect(self): - """ - Connect to the database server. - - Note: We would like to automatically reconnect to the database server. - This is especially useful for long-running processes such as the - batch deamon, which would otherwise loose their connection on an - event such as restarting the database server. - The MySQL client libraries provide a reconnect option, but this - is unfortunately not implemented in (most versions of) the Python - MySQLdb module. - Therefore we manually implement automatic reconnects in the query - method. - Also see Trac ticket #91. - """ - self._connection = MySQLdb.connect( - user=self._user, db=self._database, host=self._host) - #_connect - - def query(self, statement): - """ - Query the database. - - @arg statement: The statement that is to be queried - @type statement: tuple (string, (args)) - - @return: The result of the query - @rtype: list - """ - - # Convert the arguments to a tuple. - if type(statement[1]) != types.TupleType : - args = statement[1], - else : - args = statement[1] - - # Escape the input to prevent SQL injections. - escaped_args = [] - if args != (None,) : # Don't escape the empty string. - for i in args : - if i : - if type(i) in [types.StringType, types.UnicodeType]: - escaped_args.append(MySQLdb.escape_string(str(i))) - else : - escaped_args.append(i) - else : - escaped_args.append(None) - #if - - # Do the query, but first connect to the database server if needed. - # This makes sure lost connections are re-created automatically (e.g. - # in case the server was restarted for maintenance). - try: - cursor = self._connection.cursor() - cursor.execute(statement[0], tuple(escaped_args)) - except (AttributeError, MySQLdb.OperationalError): - self._connect() - cursor = self._connection.cursor() - cursor.execute(statement[0], tuple(escaped_args)) - - result = cursor.fetchall() - cursor.close() - - return result - #query -#Db diff --git a/mutalyzer/GenRecord.py b/mutalyzer/GenRecord.py index 917d056c..b30ed800 100644 --- a/mutalyzer/GenRecord.py +++ b/mutalyzer/GenRecord.py @@ -6,7 +6,6 @@ search for them each time. @requires: Crossmap @requires: Bio -@requires: Db """ # Public classes: # - PList ; Store a general location and a list of splice sites. @@ -20,7 +19,6 @@ import Bio from mutalyzer import util from mutalyzer import Crossmap -from mutalyzer import Db SPLICE_ALARM = 2 diff --git a/mutalyzer/Retriever.py b/mutalyzer/Retriever.py index 7c224e48..d2d01c5d 100644 --- a/mutalyzer/Retriever.py +++ b/mutalyzer/Retriever.py @@ -63,13 +63,7 @@ class Retriever(object) : - uploadrecord(raw_data) ; Let someone upload a GenBank file. - loadrecord(identifier) ; Load a record, store it in the cache, manage the cache and return the record. - - Inherited methods from Db.Output: - - WarningMsg(filename, message) ; Print a warning message. - - ErrorMsg(filename, message) ; Print an error message and log it. - - LogMsg(filename, message) ; Log a message. """ - def __init__(self, output) : """ Use variables from the configuration file for some simple diff --git a/mutalyzer/config/default_settings.py b/mutalyzer/config/default_settings.py index 108ad84d..d7cd7457 100644 --- a/mutalyzer/config/default_settings.py +++ b/mutalyzer/config/default_settings.py @@ -33,15 +33,6 @@ REDIS_URI = None # Database connection URI (can be any SQLAlchemy connection URI). DATABASE_URI = 'sqlite://' -# Host name for local MySQL databases. -MYSQL_HOST = 'localhost' - -# User for local MySQL databases. -MYSQL_USER = 'mutalyzer' - -# Local MySQL database name. -MYSQL_DATABASE = 'mutalyzer' - # Default genome assembly (by name or alias). DEFAULT_ASSEMBLY = 'hg19' diff --git a/mutalyzer/mapping.py b/mutalyzer/mapping.py index c10c1545..7bc9813b 100644 --- a/mutalyzer/mapping.py +++ b/mutalyzer/mapping.py @@ -18,7 +18,6 @@ import MySQLdb from mutalyzer.db.models import Chromosome, TranscriptMapping from mutalyzer.grammar import Grammar -from mutalyzer import Db from mutalyzer import Crossmap from mutalyzer import Retriever from mutalyzer.models import SoapMessage, Mapping, Transcript diff --git a/mutalyzer/services/rpc.py b/mutalyzer/services/rpc.py index 86cc0a16..ced3405e 100644 --- a/mutalyzer/services/rpc.py +++ b/mutalyzer/services/rpc.py @@ -30,7 +30,6 @@ from mutalyzer.grammar import Grammar from mutalyzer.sync import CacheSync from mutalyzer import stats from mutalyzer import variantchecker -from mutalyzer import Db from mutalyzer.mapping import Converter from mutalyzer import File from mutalyzer import Retriever diff --git a/mutalyzer/website.py b/mutalyzer/website.py index 63dd3247..266185fd 100644 --- a/mutalyzer/website.py +++ b/mutalyzer/website.py @@ -42,7 +42,6 @@ from mutalyzer.services import soap from mutalyzer import variantchecker from mutalyzer.output import Output from mutalyzer.mapping import Converter -from mutalyzer import Db from mutalyzer import Scheduler from mutalyzer import Retriever from mutalyzer import File diff --git a/tests/test_services_soap.py b/tests/test_services_soap.py index ed5b3e6b..13d0335c 100644 --- a/tests/test_services_soap.py +++ b/tests/test_services_soap.py @@ -15,7 +15,6 @@ from spyne.model.fault import Fault from suds.client import Client import mutalyzer -from mutalyzer import Db from mutalyzer.output import Output from mutalyzer.services.soap import application from mutalyzer.sync import CacheSync -- GitLab