root/galaxy-central/scripts/manage_db.py @ 2

リビジョン 2, 1.8 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1import sys, os.path, logging
2
3new_path = [ os.path.join( os.getcwd(), "lib" ) ]
4new_path.extend( sys.path[1:] ) # remove scripts/ from the path
5sys.path = new_path
6
7from galaxy import eggs
8
9import pkg_resources
10pkg_resources.require( "sqlalchemy-migrate" )
11
12from migrate.versioning.shell import main
13from ConfigParser import SafeConfigParser
14
15log = logging.getLogger( __name__ )
16
17if 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'
23else:
24    config_file = 'universe_wsgi.ini'
25    repo = 'lib/galaxy/model/migrate'
26
27cp = SafeConfigParser()
28cp.read( config_file )
29
30if cp.has_option( "app:main", "database_connection" ):
31    db_url = cp.get( "app:main", "database_connection" )
32elif cp.has_option( "app:main", "database_file" ):
33    db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % cp.get( "app:main", "database_file" )
34else:
35    db_url = "sqlite:///./database/universe.sqlite?isolation_level=IMMEDIATE"
36
37dialect_to_egg = {
38    "sqlite" : "pysqlite>=2",
39    "postgres" : "psycopg2",
40    "mysql" : "MySQL_python"
41}
42dialect = ( db_url.split( ':', 1 ) )[0]
43try:
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 ) )
51except 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
55main( repository=repo, url=db_url )
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。