Esempio n. 1
0
def build_shed_app(simple_kwargs):
    """Build a Galaxy app object from a simple keyword arguments.

    Construct paste style complex dictionary. Also setup "global" reference
    to sqlalchemy database context for tool shed database.
    """
    log.info("Tool shed database connection: %s", simple_kwargs["database_connection"])
    # TODO: Simplify global_conf to match Galaxy above...
    simple_kwargs['__file__'] = 'tool_shed_wsgi.ini.sample'
    simple_kwargs['global_conf'] = get_webapp_global_conf()

    app = ToolshedUniverseApplication( **simple_kwargs )
    database_contexts.tool_shed_context = app.model.context
    log.info( "Embedded Toolshed application started" )
    return app
Esempio n. 2
0
def main():
    # ---- Configuration ------------------------------------------------------
    tool_shed_test_host = os.environ.get('TOOL_SHED_TEST_HOST',
                                         default_tool_shed_test_host)
    tool_shed_test_port = os.environ.get('TOOL_SHED_TEST_PORT', None)
    galaxy_test_host = os.environ.get('GALAXY_TEST_HOST',
                                      default_galaxy_test_host)
    galaxy_test_port = os.environ.get('GALAXY_TEST_PORT', None)
    tool_path = os.environ.get('TOOL_SHED_TEST_TOOL_PATH', 'tools')
    if 'HTTP_ACCEPT_LANGUAGE' not in os.environ:
        os.environ['HTTP_ACCEPT_LANGUAGE'] = default_tool_shed_locales
    tool_shed_test_file_dir = os.environ.get('TOOL_SHED_TEST_FILE_DIR',
                                             default_tool_shed_test_file_dir)
    if not os.path.isabs(tool_shed_test_file_dir):
        tool_shed_test_file_dir = tool_shed_test_file_dir
    ignore_files = ()
    tool_dependency_dir = os.environ.get('TOOL_SHED_TOOL_DEPENDENCY_DIR', None)
    use_distributed_object_store = os.environ.get(
        'TOOL_SHED_USE_DISTRIBUTED_OBJECT_STORE', False)
    if not os.path.isdir(tool_shed_test_tmp_dir):
        os.mkdir(tool_shed_test_tmp_dir)
    tool_shed_test_proxy_port = None
    galaxy_test_proxy_port = None
    if 'TOOL_SHED_TEST_DBPATH' in os.environ:
        shed_db_path = os.environ['TOOL_SHED_TEST_DBPATH']
    else:
        tempdir = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        shed_db_path = os.path.join(tempdir, 'database')
    shed_tool_data_table_conf_file = os.environ.get(
        'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'shed_tool_data_table_conf.xml'))
    galaxy_shed_data_manager_conf_file = os.environ.get(
        'GALAXY_SHED_DATA_MANAGER_CONF',
        os.path.join(tool_shed_test_tmp_dir,
                     'test_shed_data_manager_conf.xml'))
    galaxy_tool_data_table_conf_file = os.environ.get(
        'GALAXY_TEST_TOOL_DATA_TABLE_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'tool_data_table_conf.xml'))
    galaxy_tool_conf_file = os.environ.get(
        'GALAXY_TEST_TOOL_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'test_tool_conf.xml'))
    galaxy_shed_tool_conf_file = os.environ.get(
        'GALAXY_TEST_SHED_TOOL_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'test_shed_tool_conf.xml'))
    galaxy_migrated_tool_conf_file = os.environ.get(
        'GALAXY_TEST_MIGRATED_TOOL_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'test_migrated_tool_conf.xml'))
    galaxy_tool_sheds_conf_file = os.environ.get(
        'GALAXY_TEST_TOOL_SHEDS_CONF',
        os.path.join(tool_shed_test_tmp_dir, 'test_sheds_conf.xml'))
    if 'GALAXY_TEST_TOOL_DATA_PATH' in os.environ:
        tool_data_path = os.environ.get('GALAXY_TEST_TOOL_DATA_PATH')
    else:
        tool_data_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        os.environ['GALAXY_TEST_TOOL_DATA_PATH'] = tool_data_path
    if 'GALAXY_TEST_DBPATH' in os.environ:
        galaxy_db_path = os.environ['GALAXY_TEST_DBPATH']
    else:
        tempdir = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
        galaxy_db_path = os.path.join(tempdir, 'database')
    shed_file_path = os.path.join(shed_db_path, 'files')
    galaxy_file_path = os.path.join(galaxy_db_path, 'files')
    hgweb_config_file_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    new_repos_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    galaxy_tempfiles = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    galaxy_shed_tool_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    galaxy_migrated_tool_path = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    galaxy_tool_dependency_dir = tempfile.mkdtemp(dir=tool_shed_test_tmp_dir)
    os.environ['GALAXY_TEST_TOOL_DEPENDENCY_DIR'] = galaxy_tool_dependency_dir
    hgweb_config_dir = hgweb_config_file_path
    os.environ['TEST_HG_WEB_CONFIG_DIR'] = hgweb_config_dir
    print "Directory location for hgweb.config:", hgweb_config_dir
    if 'TOOL_SHED_TEST_DBURI' in os.environ:
        toolshed_database_connection = os.environ['TOOL_SHED_TEST_DBURI']
    else:
        toolshed_database_connection = 'sqlite:///' + os.path.join(
            shed_db_path, 'community_test.sqlite')
    galaxy_database_auto_migrate = False
    if 'GALAXY_TEST_DBURI' in os.environ:
        galaxy_database_connection = os.environ['GALAXY_TEST_DBURI']
    else:
        db_path = os.path.join(galaxy_db_path, 'universe.sqlite')
        if 'GALAXY_TEST_DB_TEMPLATE' in os.environ:
            # Middle ground between recreating a completely new
            # database and pointing at existing database with
            # GALAXY_TEST_DBURI. The former requires a lot of setup
            # time, the latter results in test failures in certain
            # cases (namely tool shed tests expecting clean database).
            __copy_database_template(os.environ['GALAXY_TEST_DB_TEMPLATE'],
                                     db_path)
            galaxy_database_auto_migrate = True
        if not os.path.exists(galaxy_db_path):
            os.makedirs(galaxy_db_path)
        galaxy_database_connection = 'sqlite:///%s' % db_path
    if 'GALAXY_TEST_INSTALL_DBURI' in os.environ:
        install_galaxy_database_connection = os.environ[
            'GALAXY_TEST_INSTALL_DBURI']
    elif asbool(
            os.environ.get('GALAXY_TEST_INSTALL_DB_MERGED',
                           default_install_db_merged)):
        install_galaxy_database_connection = galaxy_database_connection
    else:
        install_galaxy_db_path = os.path.join(galaxy_db_path, 'install.sqlite')
        install_galaxy_database_connection = 'sqlite:///%s' % install_galaxy_db_path
    tool_shed_global_conf = get_webapp_global_conf()
    tool_shed_global_conf['__file__'] = 'tool_shed_wsgi.ini.sample'
    kwargs = dict(
        admin_users='*****@*****.**',
        allow_user_creation=True,
        allow_user_deletion=True,
        database_connection=toolshed_database_connection,
        datatype_converters_config_file='datatype_converters_conf.xml.sample',
        file_path=shed_file_path,
        global_conf=tool_shed_global_conf,
        hgweb_config_dir=hgweb_config_dir,
        job_queue_workers=5,
        id_secret='changethisinproductiontoo',
        log_destination="stdout",
        new_file_path=new_repos_path,
        running_functional_tests=True,
        shed_tool_data_table_config=shed_tool_data_table_conf_file,
        smtp_server='smtp.dummy.string.tld',
        email_from='functional@localhost',
        template_path='templates',
        tool_path=tool_path,
        tool_parse_help=False,
        tool_data_table_config_path=galaxy_tool_data_table_conf_file,
        use_heartbeat=False)
    for dir in [tool_shed_test_tmp_dir]:
        try:
            os.makedirs(dir)
        except OSError:
            pass

    print "Tool shed database connection:", toolshed_database_connection
    print "Galaxy database connection:", galaxy_database_connection

    # Generate the tool_data_table_conf.xml file.
    file(galaxy_tool_data_table_conf_file,
         'w').write(tool_data_table_conf_xml_template)
    # Generate the shed_tool_data_table_conf.xml file.
    file(shed_tool_data_table_conf_file,
         'w').write(tool_data_table_conf_xml_template)
    os.environ[
        'TOOL_SHED_TEST_TOOL_DATA_TABLE_CONF'] = shed_tool_data_table_conf_file
    # ---- Build Tool Shed Application --------------------------------------------------
    toolshedapp = None
    #    if not toolshed_database_connection.startswith( 'sqlite://' ):
    #        kwargs[ 'database_engine_option_max_overflow' ] = '20'
    if tool_dependency_dir is not None:
        kwargs['tool_dependency_dir'] = tool_dependency_dir
    if use_distributed_object_store:
        kwargs['object_store'] = 'distributed'
        kwargs[
            'distributed_object_store_config_file'] = 'distributed_object_store_conf.xml.sample'

    kwargs['global_conf'] = tool_shed_global_conf

    if not toolshed_database_connection.startswith('sqlite://'):
        kwargs['database_engine_option_pool_size'] = '10'

    toolshedapp = ToolshedUniverseApplication(**kwargs)
    database_contexts.tool_shed_context = toolshedapp.model.context
    log.info("Embedded Toolshed application started")

    # ---- Run tool shed webserver ------------------------------------------------------
    tool_shed_server = None
    tool_shed_global_conf['database_connection'] = toolshed_database_connection
    toolshedwebapp = toolshedbuildapp.app_factory(tool_shed_global_conf,
                                                  use_translogger=False,
                                                  static_enabled=True,
                                                  app=toolshedapp)
    if tool_shed_test_port is not None:
        tool_shed_server = httpserver.serve(toolshedwebapp,
                                            host=tool_shed_test_host,
                                            port=tool_shed_test_port,
                                            start_loop=False)
    else:
        random.seed()
        for i in range(0, 9):
            try:
                tool_shed_test_port = str(
                    random.randint(default_tool_shed_test_port_min,
                                   default_tool_shed_test_port_max))
                log.debug(
                    "Attempting to serve app on randomly chosen port: %s" %
                    tool_shed_test_port)
                tool_shed_server = httpserver.serve(toolshedwebapp,
                                                    host=tool_shed_test_host,
                                                    port=tool_shed_test_port,
                                                    start_loop=False)
                break
            except socket.error, e:
                if e[0] == 98:
                    continue
                raise
        else: