Files
galaxy/lib/tool_shed/scripts/bootstrap_tool_shed/bootstrap_util.py
T
Nate Coraor 97ad53f570 Merge remote-tracking branch 'upstream/dev' into smash_eggs
Conflicts:
	eggs.ini
	lib/galaxy/__init__.py
	lib/galaxy/datatypes/binary.py
	lib/galaxy/datatypes/converters/bgzip.py
	lib/galaxy/datatypes/converters/gff_to_interval_index_converter.py
	lib/galaxy/datatypes/converters/interval_to_bed_converter.py
	lib/galaxy/datatypes/converters/interval_to_bedstrict_converter.py
	lib/galaxy/datatypes/converters/interval_to_coverage.py
	lib/galaxy/datatypes/converters/interval_to_fli.py
	lib/galaxy/datatypes/converters/interval_to_tabix_converter.py
	lib/galaxy/datatypes/converters/maf_to_fasta_converter.py
	lib/galaxy/datatypes/converters/maf_to_interval_converter.py
	lib/galaxy/datatypes/converters/pbed_ldreduced_converter.py
	lib/galaxy/datatypes/converters/vcf_to_interval_index_converter.py
	lib/galaxy/datatypes/converters/vcf_to_vcf_bgzip.py
	lib/galaxy/datatypes/converters/wiggle_to_simple_converter.py
	lib/galaxy/datatypes/coverage.py
	lib/galaxy/eggs/__init__.py
	lib/galaxy/eggs/dist.py
	lib/galaxy/eggs/scramble.py
	lib/galaxy/exceptions/__init__.py
	lib/galaxy/jobs/runners/pbs.py
	lib/galaxy/jobs/transfer_manager.py
	lib/galaxy/model/__init__.py
	lib/galaxy/model/migrate/check.py
	lib/galaxy/model/orm/__init__.py
	lib/galaxy/model/tool_shed_install/migrate/check.py
	lib/galaxy/web/framework/__init__.py
	lib/galaxy/web/framework/helpers/__init__.py
	lib/galaxy/web/framework/middleware/sentry.py
	lib/galaxy/web/framework/openid_manager.py
	lib/galaxy/web/framework/webapp.py
	lib/galaxy/webapps/galaxy/controllers/cloudlaunch.py
	lib/galaxy/webapps/galaxy/controllers/dataset.py
	lib/galaxy/webapps/galaxy/controllers/library_common.py
	lib/galaxy/webapps/reports/controllers/workflows.py
	lib/galaxy/webapps/tool_shed/controllers/repository.py
	lib/galaxy/webapps/tool_shed/search/repo_search.py
	lib/galaxy/webapps/tool_shed/search/tool_search.py
	lib/galaxy_ext/metadata/set_metadata.py
	lib/pulsar/client/config_util.py
	lib/tool_shed/galaxy_install/install_manager.py
	lib/tool_shed/galaxy_install/migrate/check.py
	lib/tool_shed/grids/admin_grids.py
	lib/tool_shed/grids/repository_grids.py
	lib/tool_shed/repository_types/repository_suite_definition.py
	lib/tool_shed/repository_types/tool_dependency_definition.py
	lib/tool_shed/scripts/bootstrap_tool_shed/bootstrap_util.py
	lib/tool_shed/scripts/bootstrap_tool_shed/create_user_with_api_key.py
	lib/tool_shed/scripts/check_repositories_for_functional_tests.py
	lib/tool_shed/scripts/check_s3_for_empty_tool_dependency_installation_paths.py
	lib/tool_shed/scripts/check_tool_dependency_definition_repositories.py
	lib/tool_shed/scripts/show_tool_dependency_installation_dir_contents.py
	lib/tool_shed/util/basic_util.py
	lib/tool_shed/util/encoding_util.py
	lib/tool_shed/util/hg_util.py
	scripts/check_eggs.py
	scripts/dist-scramble.py
	scripts/fetch_eggs.py
	scripts/make_egg_packager.py
	scripts/scramble.py
	scripts/scramble/lib/scramble_lib.py
	scripts/scramble/scripts/DRMAA_python-macosx.py
	scripts/scramble/scripts/DRMAA_python-solaris.py
	scripts/scramble/scripts/DRMAA_python.py
	scripts/scramble/scripts/MySQL_python-solaris.py
	scripts/scramble/scripts/MySQL_python.py
	scripts/scramble/scripts/PyRods.py
	scripts/scramble/scripts/bx_python-solaris.py
	scripts/scramble/scripts/generic.py
	scripts/scramble/scripts/pbs_python.py
	scripts/scramble/scripts/psycopg2-linux.py
	scripts/scramble/scripts/psycopg2-macosx.py
	scripts/scramble/scripts/psycopg2-solaris.py
	scripts/scramble/scripts/psycopg2.py
	scripts/scramble/scripts/pysam-solaris.py
	scripts/scramble/scripts/pysqlite.py
	scripts/test_dist_egg.py
2015-09-21 15:02:47 -04:00

130 lines
4.6 KiB
Python
Executable File

#!/usr/bin/python
import argparse
import ConfigParser
import os
import sys
sys.path.insert(1, os.path.join( os.path.dirname( __file__ ), os.pardir, os.pardir, os.pardir ) )
from sqlalchemy.exc import OperationalError, ProgrammingError
import galaxy.webapps.tool_shed.model.mapping as tool_shed_model
from tool_shed.util import xml_util
def check_db( config_parser ):
dburi = None
if config_parser.has_option( 'app:main', 'database_connection' ):
dburi = config_parser.get( 'app:main', 'database_connection' )
elif config_parser.has_option( 'app:main', 'database_file' ):
db_file = config_parser.get( 'app:main', 'database_file' )
dburi = "sqlite:///%s?isolation_level=IMMEDIATE" % db_file
else:
sys.exit('The database configuration setting is missing from the tool_shed.ini file. Add this setting before attempting to bootstrap.')
sa_session = None
database_exists_message = 'The database configured for this Tool Shed is not new, so bootstrapping is not allowed. '
database_exists_message += 'Create a new database that has not been migrated before attempting to bootstrap.'
try:
model = tool_shed_model.init( config_parser.get( 'app:main', 'file_path' ), dburi, engine_options={}, create_tables=False )
sa_session = model.context.current
sys.exit(database_exists_message)
except ProgrammingError:
pass
except OperationalError:
pass
try:
if sa_session is not None:
result = sa_session.execute( 'SELECT version FROM migrate_version' ).first()
if result[0] >= 2:
sys.exit(database_exists_message)
else:
pass
except ProgrammingError:
pass
if config_parser.has_option( 'app:main', 'hgweb_config_dir' ):
hgweb_config_parser = ConfigParser.ConfigParser()
hgweb_dir = config_parser.get( 'app:main', 'hgweb_config_dir' )
hgweb_config_file = os.path.join( hgweb_dir, 'hgweb.config' )
if not os.path.exists( hgweb_config_file ):
sys.exit(0)
hgweb_config_parser.read( hgweb_config_file )
configured_repos = hgweb_config_parser.items( 'paths' )
if len( configured_repos ) >= 1:
message = "This Tool Shed's hgweb.config file contains entries, so bootstrapping is not allowed. Delete"
message += " the current hgweb.config file along with all associated repositories in the configured "
message += "location before attempting to boostrap."
sys.exit(message)
else:
sys.exit(0)
else:
sys.exit(0)
sys.exit(0)
def admin_user_info( ):
user_info_config = os.path.abspath( os.path.join( os.getcwd(), 'lib/tool_shed/scripts/bootstrap_tool_shed', 'user_info.xml' ) )
tree, error_message = xml_util.parse_xml( user_info_config )
username = None
email = None
password = None
if tree is None:
print "The XML file ", user_info_config, " seems to be invalid, using defaults."
email = 'admin@test.org'
password = 'testuser'
username = 'admin'
else:
root = tree.getroot()
for elem in root:
if elem.tag == 'email':
email = elem.text
elif elem.tag == 'password':
password = elem.text
elif elem.tag == 'username':
username = elem.text
return (username, email, password)
def get_local_tool_shed_url( config_parser ):
port = '9009'
if config_parser.has_section( 'server:main' ):
if config_parser.has_option( 'server:main', 'port' ):
port = config_parser.get( 'server:main', 'port' )
host = '127.0.0.1'
print 'http://%s:%s' % ( host, port )
return 0
def main( args ):
config_parser = ConfigParser.ConfigParser()
if os.path.exists( args.config ):
config_parser.read( args.config )
else:
return 1
if args.method == 'check_db':
return check_db( config_parser )
elif args.method == 'admin_user_info':
(username, email, password) = admin_user_info()
print '%s__SEP__%s__SEP__%s' % ( username, email, password )
return 0
elif args.method == 'get_url':
return get_local_tool_shed_url( config_parser )
else:
return 1
parser = argparse.ArgumentParser()
parser.add_argument( '-c', '--config_file', dest='config', action='store', default='config/tool_shed.ini.sample' )
parser.add_argument( '-e', '--execute', dest='method', action='store', default='check_db' )
args = parser.parse_args()
if __name__ == '__main__':
sys.exit( main( args ) )