Ejemplo n.º 1
0
 def upload( self, trans, **kwd ):
     message = kwd.get( 'message', ''  )
     status = kwd.get( 'status', 'done' )
     commit_message = kwd.get( 'commit_message', 'Uploaded'  )
     category_ids = util.listify( kwd.get( 'category_id', '' ) )
     categories = suc.get_categories( trans )
     repository_id = kwd.get( 'repository_id', '' )
     repository = suc.get_repository_in_tool_shed( trans, repository_id )
     repo_dir = repository.repo_path( trans.app )
     repo = hg.repository( suc.get_configured_ui(), repo_dir )
     uncompress_file = util.string_as_bool( kwd.get( 'uncompress_file', 'true' ) )
     remove_repo_files_not_in_tar = util.string_as_bool( kwd.get( 'remove_repo_files_not_in_tar', 'true' ) )
     uploaded_file = None
     upload_point = commit_util.get_upload_point( repository, **kwd )
     tip = repository.tip( trans.app )
     file_data = kwd.get( 'file_data', '' )
     url = kwd.get( 'url', '' )
     # Part of the upload process is sending email notification to those that have registered to
     # receive them.  One scenario occurs when the first change set is produced for the repository.
     # See the suc.handle_email_alerts() method for the definition of the scenarios.
     new_repo_alert = repository.is_new( trans.app )
     uploaded_directory = None
     if kwd.get( 'upload_button', False ):
         if file_data == '' and url == '':
             message = 'No files were entered on the upload form.'
             status = 'error'
             uploaded_file = None
         elif url and url.startswith( 'hg' ):
             # Use mercurial clone to fetch repository, contents will then be copied over.
             uploaded_directory = tempfile.mkdtemp()
             repo_url = 'http%s' % url[ len( 'hg' ): ]
             repo_url = repo_url.encode( 'ascii', 'replace' )
             try:
                 commands.clone( suc.get_configured_ui(), repo_url, uploaded_directory )
             except Exception, e:
                 message = 'Error uploading via mercurial clone: %s' % suc.to_html_string( str( e ) )
                 status = 'error'
                 suc.remove_dir( uploaded_directory )
                 uploaded_directory = None
         elif url:
             valid_url = True
             try:
                 stream = urllib.urlopen( url )
             except Exception, e:
                 valid_url = False
                 message = 'Error uploading file via http: %s' % str( e )
                 status = 'error'
                 uploaded_file = None
             if valid_url:
                 fd, uploaded_file_name = tempfile.mkstemp()
                 uploaded_file = open( uploaded_file_name, 'wb' )
                 while 1:
                     chunk = stream.read( util.CHUNK_SIZE )
                     if not chunk:
                         break
                     uploaded_file.write( chunk )
                 uploaded_file.flush()
                 uploaded_file_filename = url.split( '/' )[ -1 ]
                 isempty = os.path.getsize( os.path.abspath( uploaded_file_name ) ) == 0
Ejemplo n.º 2
0
def build_readme_files_dict( trans, repository, changeset_revision, metadata, tool_path=None ):
    """
    Return a dictionary of valid readme file name <-> readme file content pairs for all readme files defined in the received metadata.  Since the
    received changeset_revision (which is associated with the received metadata) may not be the latest installable changeset revision, the README
    file contents may not be available on disk.  This method is used by both Galaxy and the Tool Shed.
    """
    if trans.webapp.name == 'galaxy':
        can_use_disk_files = True
    else:
        repo = hg.repository( suc.get_configured_ui(), repository.repo_path( trans.app ) )
        latest_downloadable_changeset_revision = suc.get_latest_downloadable_changeset_revision( trans, repository, repo )
        can_use_disk_files = changeset_revision == latest_downloadable_changeset_revision
    readme_files_dict = {}
    if metadata:
        if 'readme_files' in metadata:
            for relative_path_to_readme_file in metadata[ 'readme_files' ]:
                readme_file_name = os.path.split( relative_path_to_readme_file )[ 1 ]
                if can_use_disk_files:
                    if tool_path:
                        full_path_to_readme_file = os.path.abspath( os.path.join( tool_path, relative_path_to_readme_file ) )
                    else:
                        full_path_to_readme_file = os.path.abspath( relative_path_to_readme_file )
                    text = None
                    try:
                        f = open( full_path_to_readme_file, 'r' )
                        text = unicodify( f.read() )
                        f.close()
                    except Exception, e:
                        log.exception( "Error reading README file '%s' from disk: %s" % ( str( relative_path_to_readme_file ), str( e ) ) )
                        text = None
                    if text:
                        text_of_reasonable_length = suc.size_string( text )
                        if text_of_reasonable_length.find( '.. image:: ' ) >= 0:
                            # Handle image display for README files that are contained in repositories in the tool shed or installed into Galaxy.
                            lock = threading.Lock()
                            lock.acquire( True )
                            try:
                                text_of_reasonable_length = suc.set_image_paths( trans.app,
                                                                                 trans.security.encode_id( repository.id ),
                                                                                 text_of_reasonable_length )
                            except Exception, e:
                                log.exception( "Exception in build_readme_files_dict, so images may not be properly displayed:\n%s" % str( e ) )
                            finally:
                                lock.release()
                        if readme_file_name.endswith( '.rst' ):
                            text_of_reasonable_length = Template( rst_to_html( text_of_reasonable_length ),
                                                                  input_encoding='utf-8',
                                                                  output_encoding='utf-8',
                                                                  default_filters=[ 'decode.utf8' ],
                                                                  encoding_errors='replace' )
                            text_of_reasonable_length = text_of_reasonable_length.render( static_path=web.url_for( '/static' ),
                                                                                          host_url=web.url_for( '/', qualified=True ) )
                            text_of_reasonable_length = unicodify( text_of_reasonable_length )
                        else:
                            text_of_reasonable_length = suc.to_html_string( text_of_reasonable_length )
                        readme_files_dict[ readme_file_name ] = text_of_reasonable_length
def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x13c77a50')._populate(_import_ns, [u'render_msg'])
        status = _import_ns.get('status', context.get('status', UNDEFINED))
        migration_stages_dict = _import_ns.get('migration_stages_dict', context.get('migration_stages_dict', UNDEFINED))
        message = _import_ns.get('message', context.get('message', UNDEFINED))
        render_msg = _import_ns.get('render_msg', context.get('render_msg', UNDEFINED))
        __M_writer = context.writer()
        # SOURCE LINE 1
        __M_writer(u'\n')
        # SOURCE LINE 2
        __M_writer(u'\n\n')
        # SOURCE LINE 4
        if message:
            # SOURCE LINE 5
            __M_writer(u'    ')
            __M_writer(unicode(render_msg( message, status )))
            __M_writer(u'\n')
            pass
        # SOURCE LINE 7
        __M_writer(u'\n<div class="toolForm">\n    <div class="toolFormTitle">Tool migrations that can be performed on this Galaxy instance</div>\n    <div class="toolFormBody">\n        <div class="form-row">\n            <p>\n                The list of tool migration stages below, displayed most recent to oldest, provides information about the repositories in the\n                main Galaxy tool shed that will be cloned at each stage if you run the shell command for that stage.  This enables you to execute\n                the migration process for any stage at any time.\n            </p>\n            <p>\n                Keep in mind that tools included in a repository that you want to be displayed in the Galaxy tool panel when the repository is\n                installed must be defined in the <b>tool_conf.xml</b> (or equivalent) config file prior to execution of the migration process for a\n                stage.  Executing a migration process multiple times will have no affect unless the repositories associated with that stage have been\n                uninstalled prior to the execution of the migration process.\n            </p>\n            <p>\n                When you initiate a migration process, the associated repositories will be cloned from the Galaxy tool shed at\n                <a href="http://toolshed.g2.bx.psu.edu" target="_blank">http://toolshed.g2.bx.psu.edu</a>.  The location in which the tool repositories\n                will be installed is the value of the \'tool_path\' attribute in the <tool> tag of the file named ./migrated_tool_conf.xml\n                (i.e., <b>&lt;toolbox tool_path="../shed_tools"&gt;</b>).  The default location setting is <b>\'../shed_tools\'</b>, which may be problematic\n                for some cluster environments, so make sure to change it before you execute the installation process if appropriate.  The configured location\n                must be outside of the Galaxy installation directory or it must be in a sub-directory protected by a properly configured <b>.hgignore</b>\n                file if the directory is within the Galaxy installation directory hierarchy.  This is because tool shed repositories will be installed using\n                mercurial\'s clone feature, which creates .hg directories and associated mercurial repository files.  Not having <b>.hgignore</b> properly\n                configured could result in undesired behavior when modifying or updating your local Galaxy instance or the tool shed repositories if they are\n                in directories that pose conflicts.  See mercurial\'s .hgignore documentation at\n                <a href="http://mercurial.selenic.com/wiki/.hgignore" target="_blank">http://mercurial.selenic.com/wiki/.hgignore</a> for details.\n            </p>\n        </div>\n        <table class="grid">\n            ')
        # SOURCE LINE 38
        from tool_shed.util.shed_util_common import to_html_string 
        
        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in ['to_html_string'] if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n')
        # SOURCE LINE 39
        for stage in migration_stages_dict.keys():
            # SOURCE LINE 40
            __M_writer(u'                ')

            migration_command = 'sh ./scripts/migrate_tools/%04d_tools.sh' % stage
            install_dependencies = '%s install_dependencies' % migration_command
            migration_tup = migration_stages_dict[ stage ]
            migration_info, repo_name_dependency_tups = migration_tup
            repository_names = []
            for repo_name_dependency_tup in repo_name_dependency_tups:
                repository_name, tool_dependencies = repo_name_dependency_tup
                if repository_name not in repository_names:
                    repository_names.append( repository_name )
            if repository_names:
                repository_names.sort()
                repository_names = ', '.join( repository_names )
                            
            
            __M_locals_builtin_stored = __M_locals_builtin()
            __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in ['repository_name','migration_tup','repository_names','migration_command','repo_name_dependency_tup','migration_info','install_dependencies','repo_name_dependency_tups','tool_dependencies'] if __M_key in __M_locals_builtin_stored]))
            # SOURCE LINE 53
            __M_writer(u'\n                <tr><td bgcolor="#D8D8D8"><b>Tool migration stage ')
            # SOURCE LINE 54
            __M_writer(unicode(stage))
            __M_writer(u' - repositories: ')
            __M_writer(unicode(repository_names))
            __M_writer(u'</b></td></tr>\n                <tr>\n                    <td bgcolor="#FFFFCC">\n                        <div class="form-row">\n                            <p>')
            # SOURCE LINE 58
            __M_writer(unicode(to_html_string(migration_info)))
            __M_writer(u' <b>Run commands from the Galaxy installation directory!</b></p>\n                            <p>\n')
            # SOURCE LINE 60
            if tool_dependencies:
                # SOURCE LINE 61
                __M_writer(u'                                    This migration stage includes tools that have tool dependencies that can be automatically installed.  To install them, run:<br/>\n                                    <b>')
                # SOURCE LINE 62
                __M_writer(unicode(install_dependencies))
                __M_writer(u'</b><br/><br/>\n                                    To skip tool dependency installation run:<br/>\n                                    <b>')
                # SOURCE LINE 64
                __M_writer(unicode(migration_command))
                __M_writer(u'</b>\n')
                # SOURCE LINE 65
            else:
                # SOURCE LINE 66
                __M_writer(u'                                    <b>')
                __M_writer(unicode(migration_command))
                __M_writer(u'</b>\n')
                pass
            # SOURCE LINE 68
            __M_writer(u'                            </p>\n                        </div>\n                    </td>\n                </tr>\n')
            # SOURCE LINE 72
            for repo_name_dependency_tup in repo_name_dependency_tups:
                # SOURCE LINE 73
                __M_writer(u'                    ')
                repository_name, tool_dependencies = repo_name_dependency_tup 
                
                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in ['repository_name','tool_dependencies'] if __M_key in __M_locals_builtin_stored]))
                __M_writer(u'\n                    <tr>\n                        <td bgcolor="#DADFEF">\n                            <div class="form-row">\n                                <b>Repository:</b> ')
                # SOURCE LINE 77
                __M_writer(unicode(repository_name))
                __M_writer(u'\n                            </div>\n                        </td>\n                    </tr>\n')
                # SOURCE LINE 81
                if tool_dependencies:
                    # SOURCE LINE 82
                    __M_writer(u'                        <tr>\n                            <td>\n                                <div class="form-row">\n                                    <b>Tool dependencies</b>\n                                </div>\n                            </td>\n                        </tr>\n')
                    # SOURCE LINE 89
                    for tool_dependencies_tup in tool_dependencies:
                        # SOURCE LINE 90
                        __M_writer(u'                            ')

                        tool_dependency_name = tool_dependencies_tup[0]
                        tool_dependency_version = tool_dependencies_tup[1]
                        tool_dependency_type = tool_dependencies_tup[2]
                        installation_requirements = tool_dependencies_tup[3].replace( '\n', '<br/>' )
                                                    
                        
                        __M_locals_builtin_stored = __M_locals_builtin()
                        __M_locals.update(__M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in ['tool_dependency_name','tool_dependency_type','installation_requirements','tool_dependency_version'] if __M_key in __M_locals_builtin_stored]))
                        # SOURCE LINE 95
                        __M_writer(u'\n                            <tr>\n                                <td>\n                                    <div class="form-row">\n                                        <b>Name:</b> ')
                        # SOURCE LINE 99
                        __M_writer(unicode(tool_dependency_name))
                        __M_writer(u' <b>Version:</b> ')
                        __M_writer(unicode(tool_dependency_version))
                        __M_writer(u' <b>Type:</b> ')
                        __M_writer(unicode(tool_dependency_type))
                        __M_writer(u'\n                                    </div>\n                                    <div class="form-row">\n                                        <b>Requirements and installation information:</b><br/>\n                                        ')
                        # SOURCE LINE 103
                        __M_writer(unicode(installation_requirements))
                        __M_writer(u'\n                                    </div>\n                                </td>\n                            </tr>\n')
                        pass
                    # SOURCE LINE 108
                else:
                    # SOURCE LINE 109
                    __M_writer(u'                        <tr>\n                            <td>\n                                <div class="form-row">\n                                    No tool dependencies have been defined for this repository.\n                                </div>\n                            </td>\n                        </tr>\n')
                    pass
                pass
            pass
        # SOURCE LINE 119
        __M_writer(u'        </table>\n    </div>\n</div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()