mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-25 00:12:08 +08:00
Models: Refactor some common code between tool shed and Galaxy into galaxy.model.orm.
This commit is contained in:
@@ -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"""
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user