Models: Refactor some common code between tool shed and Galaxy into galaxy.model.orm.

This commit is contained in:
John Chilton
2013-12-05 00:20:54 -06:00
parent b686182e13
commit e7d8b36513
3 changed files with 29 additions and 43 deletions
+1 -18
View File
@@ -16,7 +16,7 @@ from sqlalchemy.orm import backref, object_session, relation, scoped_session, se
from sqlalchemy.orm.collections import attribute_mapped_collection
from galaxy import model
from galaxy.model.orm import dialect_to_egg
from galaxy.model.orm import load_egg_for_url
from galaxy.model.custom_types import JSONType, MetadataType, TrimmedString, UUIDType
from galaxy.security import GalaxyRBACAgent
from galaxy.util.bunch import Bunch
@@ -1998,23 +1998,6 @@ def db_next_hid( self ):
model.History._next_hid = db_next_hid
def guess_dialect_for_url( url ):
return (url.split(':', 1))[0]
def load_egg_for_url( url ):
# Load the appropriate db module
dialect = guess_dialect_for_url( url )
try:
egg = dialect_to_egg[dialect]
try:
pkg_resources.require( egg )
log.debug( "%s egg successfully loaded for %s dialect" % ( egg, dialect ) )
except:
# If the module's in the path elsewhere (i.e. non-egg), it'll still load.
log.warning( "%s egg not found, but an attempt will be made to use %s anyway" % ( egg, dialect ) )
except KeyError:
# Let this go, it could possibly work with db's we don't support
log.error( "database_connection contains an unknown SQLAlchemy database dialect: %s" % dialect )
def init( file_path, url, engine_options={}, create_tables=False, database_query_profiling_proxy=False, object_store=None, trace_logger=None, use_pbkdf2=True ):
"""Connect mappings to the database"""
+27 -6
View File
@@ -4,13 +4,34 @@ pkg_resources.require( "SQLAlchemy >= 0.4" )
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.interfaces import *
import sqlalchemy.exc
from sqlalchemy.ext.orderinglist import ordering_list
import logging
log = logging.getLogger( __name__ )
dialect_to_egg = {
"sqlite" : "pysqlite>=2",
"postgres" : "psycopg2",
"postgresql" : "psycopg2",
"mysql" : "MySQL_python"
"sqlite": "pysqlite>=2",
"postgres": "psycopg2",
"postgresql": "psycopg2",
"mysql": "MySQL_python"
}
def load_egg_for_url( url ):
# Load the appropriate db module
dialect = __guess_dialect_for_url( url )
try:
egg = dialect_to_egg[dialect]
try:
pkg_resources.require( egg )
log.debug( "%s egg successfully loaded for %s dialect" % ( egg, dialect ) )
except:
# If the module's in the path elsewhere (i.e. non-egg), it'll still load.
log.warning( "%s egg not found, but an attempt will be made to use %s anyway" % ( egg, dialect ) )
except KeyError:
# Let this go, it could possibly work with db's we don't support
log.error( "database_connection contains an unknown SQLAlchemy database dialect: %s" % dialect )
def __guess_dialect_for_url( url ):
return (url.split(':', 1))[0]
+1 -19
View File
@@ -5,14 +5,13 @@ are encapsulated here.
import logging
log = logging.getLogger( __name__ )
import sys
import datetime
from galaxy.webapps.tool_shed.model import *
from galaxy.model.orm import *
from galaxy.model.custom_types import *
from galaxy.util.bunch import Bunch
from galaxy.model.orm import dialect_to_egg
from galaxy.model.orm import load_egg_for_url
import galaxy.webapps.tool_shed.util.shed_statistics as shed_statistics
import galaxy.webapps.tool_shed.util.hgweb_config
from galaxy.webapps.tool_shed.security import CommunityRBACAgent
@@ -307,23 +306,6 @@ mapper( RepositoryCategoryAssociation, RepositoryCategoryAssociation.table,
category=relation( Category ),
repository=relation( Repository ) ) )
def guess_dialect_for_url( url ):
return (url.split(':', 1))[0]
def load_egg_for_url( url ):
# Load the appropriate db module
dialect = guess_dialect_for_url( url )
try:
egg = dialect_to_egg[dialect]
try:
pkg_resources.require( egg )
log.debug( "%s egg successfully loaded for %s dialect" % ( egg, dialect ) )
except:
# If the module's in the path elsewhere (i.e. non-egg), it'll still load.
log.warning( "%s egg not found, but an attempt will be made to use %s anyway" % ( egg, dialect ) )
except KeyError:
# Let this go, it could possibly work with db's we don't support
log.error( "database_connection contains an unknown SQLAlchemy database dialect: %s" % dialect )
def init( file_path, url, engine_options={}, create_tables=False ):
"""Connect mappings to the database"""