Reuse code between scripts/manage_tools.py and lib/galaxy/model/orm/scripts.py

This commit is contained in:
John Chilton
2013-12-17 11:19:41 -06:00
parent 73cc28ddb4
commit 8f5b10d6d5
2 changed files with 35 additions and 38 deletions
+8 -20
View File
@@ -1,7 +1,9 @@
import sys, os.path, logging
import sys
import os.path
import logging
new_path = [ os.path.join( os.getcwd(), "lib" ) ]
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
sys.path = new_path
from galaxy import eggs
@@ -15,15 +17,12 @@ pkg_resources.require( "sqlalchemy-migrate" )
from migrate.versioning.shell import main
from ConfigParser import SafeConfigParser
from galaxy.model.orm import dialect_to_egg
from galaxy.model.orm.scripts import require_dialect_egg
from galaxy.model.orm.scripts import read_config_file_arg
log = logging.getLogger( __name__ )
config_file = 'universe_wsgi.ini'
if '-c' in sys.argv:
pos = sys.argv.index( '-c' )
sys.argv.pop( pos )
config_file = sys.argv.pop( pos )
config_file = read_config_file_arg( sys.argv, 'universe_wsgi.ini' )
if not os.path.exists( config_file ):
print "Galaxy config file does not exist (hint: use '-c config.ini' for non-standard locations): %s" % config_file
sys.exit( 1 )
@@ -42,17 +41,6 @@ elif cp.has_option( "app:main", "database_file" ):
else:
db_url = "sqlite:///./database/universe.sqlite?isolation_level=IMMEDIATE"
dialect = ( db_url.split( ':', 1 ) )[0]
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 is 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 )
require_dialect_egg( db_url )
main( repository=repo, url=db_url )