1 | import sys, os.path, logging |
---|
2 | |
---|
3 | new_path = [ os.path.join( os.getcwd(), "lib" ) ] |
---|
4 | new_path.extend( sys.path[1:] ) # remove scripts/ from the path |
---|
5 | sys.path = new_path |
---|
6 | |
---|
7 | from galaxy import eggs |
---|
8 | |
---|
9 | import pkg_resources |
---|
10 | pkg_resources.require( "sqlalchemy-migrate" ) |
---|
11 | |
---|
12 | from migrate.versioning.shell import main |
---|
13 | from ConfigParser import SafeConfigParser |
---|
14 | |
---|
15 | log = logging.getLogger( __name__ ) |
---|
16 | |
---|
17 | if sys.argv[-1] in [ 'community' ]: |
---|
18 | # Need to pop the last arg so the command line args will be correct |
---|
19 | # for sqlalchemy-migrate |
---|
20 | webapp = sys.argv.pop() |
---|
21 | config_file = 'community_wsgi.ini' |
---|
22 | repo = 'lib/galaxy/webapps/community/model/migrate' |
---|
23 | else: |
---|
24 | config_file = 'universe_wsgi.ini' |
---|
25 | repo = 'lib/galaxy/model/migrate' |
---|
26 | |
---|
27 | cp = SafeConfigParser() |
---|
28 | cp.read( config_file ) |
---|
29 | |
---|
30 | if cp.has_option( "app:main", "database_connection" ): |
---|
31 | db_url = cp.get( "app:main", "database_connection" ) |
---|
32 | elif cp.has_option( "app:main", "database_file" ): |
---|
33 | db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % cp.get( "app:main", "database_file" ) |
---|
34 | else: |
---|
35 | db_url = "sqlite:///./database/universe.sqlite?isolation_level=IMMEDIATE" |
---|
36 | |
---|
37 | dialect_to_egg = { |
---|
38 | "sqlite" : "pysqlite>=2", |
---|
39 | "postgres" : "psycopg2", |
---|
40 | "mysql" : "MySQL_python" |
---|
41 | } |
---|
42 | dialect = ( db_url.split( ':', 1 ) )[0] |
---|
43 | try: |
---|
44 | egg = dialect_to_egg[dialect] |
---|
45 | try: |
---|
46 | pkg_resources.require( egg ) |
---|
47 | log.debug( "%s egg successfully loaded for %s dialect" % ( egg, dialect ) ) |
---|
48 | except: |
---|
49 | # If the module is in the path elsewhere (i.e. non-egg), it'll still load. |
---|
50 | log.warning( "%s egg not found, but an attempt will be made to use %s anyway" % ( egg, dialect ) ) |
---|
51 | except KeyError: |
---|
52 | # Let this go, it could possibly work with db's we don't support |
---|
53 | log.error( "database_connection contains an unknown SQLAlchemy database dialect: %s" % dialect ) |
---|
54 | |
---|
55 | main( repository=repo, url=db_url ) |
---|